Jump to content
  • We are looking for staff for the Wiki area!
    If interested please
    click here and select "Documentation Team"

  • A simple offsite backup script running via cronjob


    Original credit @H0zen rewritten in part by myself.


    Our covenant servers hold lots of user and character data, we need to make sure that is safe and one of the tasks we do is multiple daily backups to an offsite FTP server.

    This script is ran via cronjob and can be ran as many times a day as you like. You will need to run things like "yum install ftp" for the ftp part and have zip installed.

    Make sure you change the parts suck as yourbackupfilename, servername, MySQL/FTP details, the password on the zip file and the folder path "remotefolder" in the FTP transfer section.

    # Archive & file variables
    ARCHIVE=yourbackupfilename`date +"%F"`
    OLDARCHIVE=yourbackupfilename-`date --date '-5 days' +"%F"`
    FILE=servername-Realmd_`date +"%F"`
    FILE0=servername-ZERO-Chars_`date +"%F"`
    FILE1=servername-ONE-Chars_`date +"%F"`
    FILE2=servername-TWO-Chars_`date +"%F"`
    # MySQL variables
    # FTP transfer on demand connection & login details
    # Remove previous .zip files if multiple daily backups are being ran
    echo "Checking and removing as needed old .zip files locally."
    rm -f $ARCHIVE.zip
    rm -f $OLDARCHIVE.zip
    # Dump MySQL database in .sql files into /root
    echo "Dumping .sql files to /root"
    mysqldump --opt --user=${USER} --password=${PASS} ${REALMD_DATABASE} > ${FILE}.sql
    mysqldump --opt --user=${USER} --password=${PASS} ${CHARACTERSS_ZERO_DATABASE} > ${FILE0}.sql
    mysqldump --opt --user=${USER} --password=${PASS} ${CHARACTERSS_ONE_DATABASE} > ${FILE1}.sql
    mysqldump --opt --user=${USER} --password=${PASS} ${CHARACTERSS_TWO_DATABASE} > ${FILE2}.sql
    echo ".sql files have been dumped to /root."
    # Zip dumped MySQL .sql files and password the zip file
    echo "Zipping dumped .sql files."
    zip -e -P backupfilepassword $ARCHIVE.zip $FILE.sql $FILE0.sql ${FILE1}.sql ${FILE2}.sql
    # Show the user the result
    echo "${ARCHIVE}.zip was created!"
    # Move the file via ftp to remote NAS
    echo "Initiating FTP transfer on demand."
    ftp -n $FTP_HOST <<END_SCRIPT
    quote USER $FTP_USER
    quote PASS $FTP_PASS
    cd remotefolder/remotefolder
    delete $OLDARCHIVE.zip
    put $ARCHIVE.zip
    # FTP transfer on demand ends
    # Tidy up files in the /root folder
    rm -f /root/*.sql
    echo "Clearing dumped local .sql files."


    Mangos Backup Cron Script.txt

    User Feedback

    Recommended Comments

    There are no comments to display.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use