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.
- Create
backup
folder in/etc/
- 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
- Make script executable
chmod +x backup.sh
- Create folder for backups
mkdir archive
(files from the archive folder are deleted after uploading to FTP). - 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).