Cheap Yet Secure Daily Backups For Database And Files

I need to make backups of a webapplication's MySQL database and some files for a client. Backups should be done on a daily basis and the whole system should be as cheap as possible - "ok, backups are important, but I don't want to spend any money on it anyway...". The backup should be fully automated. Furthermore installing an FTP server on one of the client's local machines (to upload the backups there) is not wanted, due to security concerns. Generally nothing of the existing setup should be changed, if possible. Finally security is a major concern - the backups' content is sensitive so making the data publicly available is nearly as bad as losing it.
1 answer

Create Backups With Cron And Send Them To A GMail account

The best free, secure, reliable, and easy solution was the following:

Write a shell script to create backups, call it by cron on a daily, weekly, whatever basis and send the backups to GMail.
Needed items: on the shell gzip and mime-construct (to send emails with attachments), cron jobs, and GMail (or whatever provider with loads of space - GMails current 7GB will be more than enough for the near future).

Shell script


filename1="/tmp/backup_`date +%d%m%Y`.sql";
target="/tmp/backup_foobar_`date +%d%m%Y`.tar"
mysubject="Backup of foobar, `date`";
mydescription="Daily backup of foobar, `date`";

mysqldump -u$myuser -p$mypassword db1 > $filename1;
mysqldump -u$myuser -p$mypassword db2 >> $filename1;
mysqldump -u$myuser -p$mypassword db3 >> $filename1;
mysqldump -u$myuser -p$mypassword db4 >> $filename1;

tar --create --file=$target $filename1 $filename2 $filename3;
gzip $target ;
mime-construct \
--to "$myemail" \
--subject "$mysubject" \
--string "$mydescription" \
--type text/plain \
--file-attach $target.gz;

rm $filename1;
rm $target.gz

If you need additional security, you can of course encrypt the tar file, so your data will be secure, even if someone breaks into your GMail account or you don't trust Google.

If you want you can download a copy via POP3, so you will have backups in your GMail inbox and locally - which should be sufficient for every situation.