Skip to content

Instantly share code, notes, and snippets.

@blu3Alien
Created January 25, 2013 12:01
Show Gist options
  • Save blu3Alien/4633911 to your computer and use it in GitHub Desktop.
Save blu3Alien/4633911 to your computer and use it in GitHub Desktop.
Shell script to store a compressed backup of all mySQL databases in the users home directory. Note: modify mySQL username and password before using.
#!/bin/sh
date=`date -I`
log_date=`date -u`
# Dump and compress all mySQL databases to remote external drive
mysqldump --user=[username] --password=[password] --all-databases | gzip > ~/backup/sql_backup-$date.sql.gz
echo "[$log_date]: Backing up all MySQL databases. (sql_backup-$date.sql.gz)" >> ~/backup/logs/_backup.txt
# Only keep mySQL backups for 14 days
find ~/backup/ -name "*gz" -mtime +14 -exec rm{} \;
echo "[$log_date]: Removing old MySQL backups." >> ~/backup/logs/_backup.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment