Skip to content

Commit

Permalink
Add snapshot.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Jul 15, 2024
1 parent 6a6bbd6 commit d2a4002
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions run/common/snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /usr/bin/env -S nix shell 'nixpkgs#curl' 'nixpkgs#lz4' 'nixpkgs#gnutar' --command bash
# shellcheck shell=bash

set -euo pipefail

# shellcheck disable=SC1091
source .env

# Define a local db if NODE_DB is not set
if [[ -z "${NODE_DB-}" ]]; then
LOCAL_NODE_DB=./databases/node-db
mkdir -p $LOCAL_NODE_DB
NODE_DB=$LOCAL_NODE_DB
fi

# Clean the db directory
rm -rf "${NODE_DB:?}"/*

echo "Network: $NETWORK"

case "$NETWORK" in
preprod)
SNAPSHOT_NAME=$(curl -s https://downloads.csnapshots.io/testnet/testnet-db-snapshot.json| jq -r .[].file_name )
echo "Snapshot name: $SNAPSHOT_NAME"
SNAPSHOT_URL="https://downloads.csnapshots.io/testnet/$SNAPSHOT_NAME"
;;
*)
echo "Error: Invalid network $NETWORK"
exit 1
;;
esac

echo "Downloading the snapshot..."

curl -SL "$SNAPSHOT_URL" | lz4 -c -d - | tar -x -C "$NODE_DB"

mv -f "$NODE_DB"/db/* "$NODE_DB"/
rm -rf "$NODE_DB"/db

echo "Snapshot downloaded and extracted to $NODE_DB"
1 change: 1 addition & 0 deletions run/preprod/nix/snapshot.sh

0 comments on commit d2a4002

Please sign in to comment.