Created
May 6, 2011 07:10
-
-
Save brantfaircloth/958546 to your computer and use it in GitHub Desktop.
Mysql automated backups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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