<Previous | Next>

Automated MySQL to FTP Backup on Shared Hosting

Posted by Tom on the 20th of February, 2011, at 9:59 am.

At first, I was trying to do all one-line commands. I don't have SSH access on my hosting server, and I can't do crontab -e. So, the only way I have to set up cron jobs is a web form. I was putting the whole of each command in there with && inbetween "lines" before a teacher of mine told me I could just do sh /home/HOSTINGUSER/bin/backup.sh, even without that file being chmod'd to executability.

So, here's my script. Modify to suit.

#/bin/sh
#get all MySQL data into a date-named file, and zip it to *.sql.bz2
#note that there is no space between the -p and the MYSQLPASS
mysqldump -u MYSQLUSER -pMYSQLPASS --all-databases > /home/HOSTINGUSER/backup/backup-$(date +%Y%m%d_%H%M%S).sql
gzip /home/edgarswo/backup/backup-*.sql

#zip all regular www content to a *.www.tar.bz2 file
tar -cjf /home/USER/backup/backup-$(date +%Y%m%d_%H%M%S).www.tar.bz2 /home/USER/public_html

#ftp it all to to your backup location
ftp -inv ftp.FTPSERVER.edu<

Tom's Picasa Web Albums

Bookmark and Share