Backup mySQL with BASH

10 Oct 2011

Simple BASH script to backup mySQL database and save it encrypted

#!/bin/bash
DATE=$(date +%s)
BACKUPFILEZ=/backup/dump${DATE}.sql
mysqldump -u root --all-databases --hex-blob --complete-insert -p > backup.sql > $BACKUPFILEZ
gpg --encrypt $BACKUPFILEZ
rm $BACKUPFILEZ

Note: This script stil needs you to manually enter database password and what public key to use for encryption (this can easily be added to the script). Also I recommend that you save the backups externally (and not in “/backup”), and for this I would recommend “scp”.

blog comments powered by Disqus