Backups using cronjobs
From LeonWiki!
Purpose
- Make a backup on a remote machine and email it to me.
- Make a backup on a remote machine and ssh the backup to me.
Implementation
- First get the current date
- mydate = `date +%m%d%y%H%M`
- /usr/bin/mysqldump --add-drop-table -ce --user=<username> --password=<password> <database name> | /bin/gzip | /usr/bin/uuencode -m backup.gz | /bin/mail -s "Website Backup" <email address> ... isn't that slick! pipes | pipes | and more pipes...
- On the receiving end
- Copy the email message text (which is Base64 encoded) and load it into an editor compatible with your operating system.
- Run uudecode on the result of the last step.
- This should have produced a backup.gz file in the directory where you ran uudecode.
- Running gzip -d on backup.gz, gives you a directory named backup that has the contents.
- I couldn't get a dynamic date to work with uuencode, so I gave the backup file a static name. When I uudecode it, I can give it an output file name, thereby differentiating it from any other file/directory
- /usr/bin/mysqldump --add-drop-table -ce --user=<username> --password=<password> <database name> | /bin/gzip | /usr/bin/ssh -i $HOME/.ssh/id_rsa <username>@<domain> "cat > ~/backup_$mydate.gz"
- On the receiving end
- You have a gzip file (encoded with date timestamp) on the local machine, so decompress it and you're done.