Backing up content via email to GMail

In the past I had some little scripts that I used to use to back up some items on my personal hosting server. I thought, that since I was retiring them, that I'd share with you.

They are simple scripts that allow you to back up file systems and database dumps to your GMail account. Great if you want a backup and perhaps don't have the funds or time to use a proper backup solution.

Now obviously these really only works for small datasets, and you are limited to whatever email sizes GMail allow you to send. Currently (at the time of this writing) I believe you can send 20Mb emails with GMail.

First up install Mutt, this enables us to attach files from the command line.

sudo apt-get install mutt

MySQL Backup Script

This simple script will take a MySQL database dump gzip it up and email it to you. Ensure you change the settings at the top. Specifically for Password, and Email.

File backup script

This script is a little bit different from the MySQL one. It, will tar up a bzip2 archive and compare it with the archive it last run. Only if the two archives differ will it send the email with the backup file. If the archives are the same (ie they haven't changed) then it exits. Remember to change the GOOGLE Account and the path to archive.

I hope these scripts help people out, please note however that these scripts are a quick little hack to make use of your free GMail space and are great if you manage your own site and need some sort of assurance. I provide them to use at your own risk and recommend if you are hosting sites for clients then have a look into some more professional solutions, ie Amazon S3 or other paid services.