Skip to content

Commit

Permalink
derive exported snapshot name
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank committed May 16, 2024
1 parent 6ad54bf commit a1a91ab
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ansible/archival-snapshots/resources/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Enable strict error handling, command tracing, and pipefail
set -euxo pipefail

GENESIS_TIMESTAMP=1598306400
SECONDS_PER_EPOCH=30

FOREST_CLI="/mnt/md0/exported/archival/forest-v0.17.1/forest-cli"
FOREST_TOOL="/mnt/md0/exported/archival/forest-v0.17.1/forest-tool"

Expand All @@ -27,9 +30,17 @@ while ((LATEST_EPOCH - CURRENT_EPOCH > 30000)); do
echo "Next Height: $NEW_EPOCH"

# Export full snapshot to generate lite and diff snapshots
$FOREST_CLI snapshot export --tipset "$NEW_EPOCH" --depth 30000 > export.txt
NEW_SNAPSHOT=$(grep forest export.txt | awk -F'[:]' '{print $1}' | tail -1)
echo "New Snapshot Downloaded: $NEW_SNAPSHOT"
EPOCH_TIMESTAMP=$((GENESIS_TIMESTAMP + NEW_EPOCH*SECONDS_PER_EPOCH))
DATE=$(date --date=@"$EPOCH_TIMESTAMP" -u -I)
NEW_SNAPSHOT="forest_snapshot_mainnet_"$DATE"_height_"$NEW_EPOCH".forest.car.zst"

if [ ! -f "./$NEW_SNAPSHOT" ]; then
echo "Exporting snapshot: $NEW_SNAPSHOT"
$FOREST_CLI snapshot export --tipset "$NEW_EPOCH" --depth 30000 > export.txt
echo "Snapshot exported: $NEW_SNAPSHOT"
else
echo "$NEW_SNAPSHOT already exists."
fi

# Generate and upload lite snapshot
if [ ! -f "$LITE_SNAPSHOT_DIR/$NEW_SNAPSHOT" ]; then
Expand Down

0 comments on commit a1a91ab

Please sign in to comment.