
So recently we needed rapid backups of one of our MySQL servers. As everyone know server admin tasks are not my favorite thing to do, but it is obviously a need in our development environment so I got to thinking what was a quick reliable way to accomplish this task. The backup is easy:
Write a small script to dump the db:
#!/bin/sh timestamp=$(date '+%d-%m-%Y@%H:%M') mysqldump -u dbuser -pPassword --all-databases | gzip > /tmp/path/for/backup/database_$timestamp.sql.gz
This is a bash script that stores the current timestamp to a variable then goes about dumping the databases to text and piping that to gzip which outputs a gzipped version of the DB. Compression is good since we're going to email it to a Gmail account for storage and we wanna maximize our 7 GB of backup space.
$timestamp in our filepath is replaced by the timestamp we generate above.
Next we actually need to mail this file to our backups account, after a short research session i came across mutt. Which seems to fufill the requirement of sending a email with an attached file easily from the command line:
mutt -s "Hourly backup from c4.kohsrv.net |...