Skip to content

Instantly share code, notes, and snippets.

@0x3639
Last active December 2, 2023 11:01
Show Gist options
  • Save 0x3639/4678e255c1f92fbec2cdbd0315e1a127 to your computer and use it in GitHub Desktop.
Save 0x3639/4678e255c1f92fbec2cdbd0315e1a127 to your computer and use it in GitHub Desktop.
Backup Zenon Network Chain State to Digital Ocean
#!/bin/bash
# Make sure to run with root permissions
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Ensure zip is installed
if ! command -v zip &> /dev/null; then
apt-get update
apt-get install -y zip
fi
# Ensure s3cmd is installed
if ! command -v s3cmd &> /dev/null; then
apt-get update
apt-get install -y s3cmd
fi
# Check if s3cmd is configured
if [ ! -f ~/.s3cfg ]; then
echo "Configuring s3cmd for Digital Ocean..."
s3cmd --configure
fi
# Define today's date and file paths
current_date=$(date +%Y-%m-%d)
current_datetime=$(date +"%Y%m%d%H%M%S")
zip_file_name="bootstrap-$current_datetime.zip"
hash_file_name="bootstrap-$current_datetime.hash"
# Stop the service
systemctl stop go-zenon
# Sleep 10 seconds
sleep 10
# Move to the directory
cd /root/.znn
# Make a backup directory if it doesn't exist
mkdir -p /backup
# Copy folders to backup
cp -r nom/ /backup/nom.bak
cp -r network/ /backup/network.bak
cp -r consensus/ /backup/consensus.bak
# Start the service
systemctl start go-zenon
# Create the zip and hash files
zip -r "/backup/$zip_file_name" /backup/nom.bak /backup/network.bak /backup/consensus.bak
echo "$(sha256sum "/backup/$zip_file_name" | awk '{ print $1 }')" > "/backup/$hash_file_name"
# Upload files to Digital Ocean and make them public
s3cmd put "/backup/$zip_file_name" "s3://hypercore/bootstrap/$current_date/$zip_file_name" --acl-public
s3cmd put "/backup/$hash_file_name" "s3://hypercore/bootstrap/$current_date/$hash_file_name" --acl-public
echo "Backup and upload completed!"
# Delete local backup folders, zip, and hash files
rm -r /backup/nom.bak /backup/network.bak /backup/consensus.bak "/backup/$zip_file_name" "/backup/$hash_file_name"
echo "Cleanup completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment