How to Setup A Local Pillar Backup Script

Summary

The script (backup.sh) is designed to back up and restore blockchain data for go-zenon or go-hyperqube. It must be run as root and performs the following backup steps:

  1. Checks Permissions and Dependencies:
  • Ensures the script runs as root.
  • Installs tar if not present.
  1. Backup Process:
  • Creates a backup directory (/backup) with subdirectories (temp, restore).
  • Checks for sufficient disk space (minimum 15GB).
  • Manages disk space by removing old backups if necessary (keeps the 7 most recent per service).
  • Stops the specified service (go-zenon or go-hyperqube).
  • Copies specified folders (nom, network, consensus, cache) to a temporary directory.
  • Restarts the service immediately after copying to minimize downtime.
  • Creates a compressed tarball (.tar.gz) of the copied folders.
  • Generates a SHA256 hash of the backup for integrity verification.
  • Cleans up the temporary directory.
  1. Restore Process (not used in cron job):
  • Verifies the integrity of a specified backup using its hash.
  • Stops the service, backs up existing folders, extracts the backup, and restarts the service.
  1. Key Features:
  • Backs up data to /backup with filenames like _backup_MM-DD-YY_HHMMSS.tar.gz.
  • Supports two services with specific node directories:
    • go-zenon: /root/.znn
    • go-hyperqube: /root/.hqz
  • Ensures service downtime is minimized by restarting services quickly.

Go-Zenon Installation Steps

  1. Download the Script:
sudo wget -O /usr/local/bin/backup.sh https://gist.githubusercontent.com/0x3639/4f3cea99b06b428a326974103cdf0cbe/raw/507f0c84bb9779bff9c8063f93ab323b1a8c0bc1/backup.sh
  1. Set Permissions:
sudo chmod +x /usr/local/bin/backup.sh
  1. Verify the Script:
cat /usr/local/bin/backup.sh
  • Confirm it starts with #!/bin/bash and matches the provided content.
  1. Create Backup Directory:
sudo mkdir -p /backup
sudo chmod 700 /backup
  1. Test the Script (Optional but Recommended):
sudo /usr/local/bin/backup.sh go-zenon --backup
  • Check for a backup file in /backup (e.g., go-zenon_backup_MM-DD-YY_HHMMSS.tar.gz).
  1. Edit the Root Crontab:
sudo crontab -e
  1. Add Cron Job:
  • Add the following line to run the backup weekly on Sunday at a chosen time (e.g., 2:00 AM). Choose a unique time to avoid all pillars backing up simultaneously:
0 2 * * 0 /usr/local/bin/backup.sh go-zenon --backup >> /var/log/backup_go-zenon.log 2>&1
  1. Create Log File:
sudo touch /var/log/backup_go-zenon.log
sudo chmod 600 /var/log/backup_go-zenon.log
  1. Verify Cron Job:
sudo crontab -l
  • Confirm the line is present.
  • Test the command manually to ensure it runs:
sudo /usr/local/bin/backup.sh go-zenon --backup >> /var/log/backup_go-zenon.log 2>&1
  1. Monitor Logs:
sudo cat /var/log/backup_go-zenon.log

Go-Hyperqube Installation Steps

  1. Download the Script:
sudo wget -O /usr/local/bin/backup.sh https://gist.githubusercontent.com/0x3639/4f3cea99b06b428a326974103cdf0cbe/raw/507f0c84bb9779bff9c8063f93ab323b1a8c0bc1/backup.sh
  1. Set Permissions:
sudo chmod +x /usr/local/bin/backup.sh
  1. Verify the Script:
cat /usr/local/bin/backup.sh
  • Confirm it starts with #!/bin/bash and matches the provided content.
  1. Create Backup Directory:
sudo mkdir -p /backup
sudo chmod 700 /backup
  1. Test the Script (Optional but Recommended):
sudo /usr/local/bin/backup.sh go-hyperqube --backup
  • Check for a backup file in /backup (e.g., go-hyperqube_backup_MM-DD-YY_HHMMSS.tar.gz).
  1. Edit the Root Crontab:
sudo crontab -e
  1. Add Cron Job:
  • Add the following line to run the backup weekly on Sunday at a chosen time (e.g., 2:05 AM). Choose a unique time to avoid all pillars backing up simultaneously:
5 2 * * 0 /usr/local/bin/backup.sh go-hyperqube --backup >> /var/log/backup_go-hyperqube.log 2>&1
  1. Create Log File:
sudo touch /var/log/backup_go-hyperqube.log
sudo chmod 600 /var/log/backup_go-hyperqube.log
  1. Verify Cron Job:
sudo crontab -l
  • Confirm the line is present.
  • Test the command manually to ensure it runs:
sudo /usr/local/bin/backup.sh go-hyperqube --backup >> /var/log/backup_go-hyperqube.log 2>&1
  1. Monitor Logs:
sudo cat /var/log/backup_go-hyperqube.log

Notes

  • Sudo Requirement: The script requires root privileges, so cron jobs must be set in the root crontab (sudo crontab -e) to ensure they run as root.
  • Disk Space: Ensure the /backup directory has at least 15GB free, as the script checks this before running.
  • Service Downtime: The script minimizes downtime by restarting services after copying files, but monitor performance during backups.
  • Backup Retention: The script retains only the 7 most recent backups per service to manage disk space.
  • Forum Feedback: Please share feedback on backup success or issues. Check logs (/var/log/backup_go-zenon.log for go-zenon, /var/log/backup_go-hyperqube.log for go-hyperqube) for troubleshooting.
1 Like

We discovered and fixed one small bug related to the path of hqzd. The URL of the script was updated and can be seen in the post history.

1 Like