Skip to content

Instantly share code, notes, and snippets.

@brantfaircloth
Created May 6, 2011 07:10
Show Gist options
  • Save brantfaircloth/958546 to your computer and use it in GitHub Desktop.
Save brantfaircloth/958546 to your computer and use it in GitHub Desktop.
Mysql automated backups
#!/bin/bash
#
# mysqlbak - mysql backup for xxx.yyy.zzz.qqq
#
# Created by Brant Faircloth on 2009-04-06.
# Copyright (c) 2009 Brant Faircloth. All rights reserved.
#
# Run by cron w/
# 0 0 * * * /path/to/script/mysqlbak.sh
#
BDATE=`/bin/date +%m-%d-%Y-%H_%M`
BNAME=$BDATE.$HOSTNAME.sql.gz
BLOC=/dir/to/save/backups
USER=backuser
# change to the working directory
cd $BLOC
# run the backup, saving files to $BLOC
/usr/bin/mysqldump --user $USER --password=password --compact --all-databases | /bin/gzip > $BLOC/$BNAME
# remove any files older than 14 days (2 weeks)
/usr/bin/find $BLOC/* -mtime +14 -type f -name "*.sql.gz" -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment