Backup scripts for Pufferpanel 1.0 and MySql



  • Here there are some backup script that i use for my pufferpanel and minecraft server just edit the variables list and add for use it, put it where you want and cronjob it :), be sure backups folders exist in each server folder!

    backup.sh BACKUP SCRIPT FOR PUFFERPANEL

    ##General Settings##
    BackupFolder=/home/backup/
    ServerFolder=/var/lib/pufferd/servers
    SleepInterval=5m
    MaxBackupToKeep=1
    MaxLogToKeep=10
    BackupServerFolder1=servername
    ServerID1=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder2=servername
    ServerID2=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder3=servername
    ServerID3=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder4=servername
    ServerID4=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder5=servername
    ServerID5=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder6=servername
    ServerID6=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder7=servername
    ServerID7=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder8=servername
    ServerID8=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder9=servername
    ServerID9=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder10=servername
    ServerID10=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder11=servername
    ServerID11=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder12=servername
    ServerID12=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder13=servername
    ServerID13=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder14=servername
    ServerID14=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder15=servername
    ServerID15=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder16=servername
    ServerID16=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder17=servername
    ServerID17=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder18=servername
    ServerID18=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder19=servername
    ServerID19=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder20=servername
    ServerID20=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    BackupServerFolder21=servername
    ServerID21=xxxxxx-xxxxxxx-xxxxx-xxx-xxxxxxx
    
    ### Code part here ###
    find $BackupFolder/$BackupServerFolder1/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID1/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$%BackupServerFolder1/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID1
    sleep $SleepInterval
    find $BackupFolder/$%BackupServerFolder2/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID2/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder2/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID2
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder3/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID3/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder3/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID3
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder4/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID4/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder4/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID4
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder5/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID5/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder5/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID5
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder6/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID6/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder6/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID6
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder7/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID7/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder7/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID7
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder8/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID8/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder8/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID8
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder9/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID9/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder9/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID9
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder10/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID10/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder10/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID10
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder11/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID11/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder11/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID11
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder12/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID12/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder12/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID12
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder13/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID13/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder13/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID13
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder14/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID14/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder14/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID14
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder15/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID15/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder15/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID15
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder16/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID16/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder16/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID16
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder17/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID17/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder17/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID17
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder18/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID18/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder18/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID18
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder19/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder//$ServerID19/logs/*.log.gz -mtime +$MaxLogToKeep-exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder19/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID19
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder20/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID20/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder20/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID20
    sleep $SleepInterval
    find $BackupFolder/$BackupServerFolder21/backup.* -mtime +$MaxBackupToKeep -exec rm {} \;
    find $ServerFolder/$ServerID21/logs/*.log.gz -mtime +$MaxLogToKeep -exec rm {} \;
    tar -zcvf $BackupFolder/$BackupServerFolder21/backup.$(date +%m%d%y%H).tar.gz $ServerFolder/$ServerID21
    

    backup-mysql.sh BACKUP SCRIPT FOR MYSQL DATABASE

    ##MysqlSetting##
    data=`date +'%a'`
    dump=`which mysqldump`
    user=root
    pwd="yourpass"
    db=databasename
    path=/home/backup/mysql
    ### Mysql part don't touch ###
    if [ ! -d $path/$data ]
    then
        echo "Making folder y $data";
        mkdir -p $path/$data
    else
       echo "The folder $path/$data exist"
    fi
    
    if [ "$(ls -A $path/$data)" ]
    then
        echo "Deleting content of $data";
        rm -rf $path/$data/*
    else
        echo "The folder $path/$data is empy";
    fi
    
    echo "Starting database export: "
    $dump -u $user --password=$pwd --opt --databases $db > $path/$data/$db.sql
    


  • UPDATED

    • Script work only with Pufferd
    • Removed restart part until is documented
    • Added configurable options easy to read
    • Added minecraft log cleaner (max log to keep)
    • Added Mysql backup schedule
    • Ensure the backup folder of mysql and servers exist!
    • splitted the script in two ones

    To do: learn to use loop for simplify the backup script



  • Nice work :)


Log in to reply
 

Looks like your connection to PufferPanel Community was lost, please wait while we try to reconnect.