Skip to content

Instantly share code, notes, and snippets.

@ArtyomCZ
Created March 10, 2024 03:17
Show Gist options
  • Save ArtyomCZ/9deba601ea872a343c523be04670f0d5 to your computer and use it in GitHub Desktop.
Save ArtyomCZ/9deba601ea872a343c523be04670f0d5 to your computer and use it in GitHub Desktop.
Backup Pterodactyl panel database with FTP remote server

Backup of the Pterodactyl Panel database and upload to the FTP server

The script allows you to set up a cron for regular backups of the Pterodactyl panel database and save the backup to another server using FTP. In case of a failed backup, there is also an webhook to send a notification to Discord.

  1. Create backup folder in /etc/
  2. Paste code in backup.sh:
#!/bin/sh

# Leave empty if you don't want to send a message to Discord, otherwise put the webhook link here
HOOK_LINK=""

# Create folder for backup with current date and time
DATE=$(date +"%Y-%m-%d_%H-%M")
BACKUP_DIR="/archive/$DATE/"
mkdir -p $BACKUP_DIR

# Backup the panel database
mysqldump -u root -p"PASSWORD" --opt panel > $BACKUP_DIR/panel.sql

# compress the backup and remove temporary directory
cd /archive/
tar -zcvf $DATE.tar.gz $BACKUP_DIR

# Delete the backup directory
rm -rf $DATE

# Upload to FTP
curl -T $DATE.tar.gz ftp://server.com --user username:password

# Check if the backup was successful and remove the local copy
if [ $? -eq 0 ]; then
rm -rf $DATE.tar.gz
elif [ -n "$HOOK_LINK" ]; then
# Send a message to Discord if the backup failed
curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"The database backup failed!\"}" $HOOK_LINK
fi
  1. Make script executable chmod +x backup.sh
  2. Create folder for backups mkdir archive (files from the archive folder are deleted after uploading to FTP).
  3. Set up a cron job for scheduled backups: open the crontab editor with crontab -e. Add the following line to the end of the file: 50 23 * * * /etc/backup/backup.sh (This script starts the backup every day at 23:50).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment