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.
#!/bin/sh # 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 DBSERVER=127.0.0.1 REALMD_DATABASE=realmd CHARACTERSS_ZERO_DATABASE=characters-classic_servername CHARACTERSS_ONE_DATABASE=characters-tbc_servername CHARACTERSS_TWO_DATABASE=characters-wotlk_servername USER=rootuser PASS=rootpassword # FTP transfer on demand connection & login details FTP_USER=ftpuser FTP_PASS=ftppass FTP_HOST=ftphostname # 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 binary delete $OLDARCHIVE.zip put $ARCHIVE.zip quit END_SCRIPT # FTP transfer on demand ends # Tidy up files in the /root folder rm -f /root/*.sql echo "Clearing dumped local .sql files."
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 accountSign in
Already have an account? Sign in here.
Sign In Now