Created
November 6, 2015 10:47
-
-
Save Patricy/d4d5130bfb1dcade6918 to your computer and use it in GitHub Desktop.
Daily database backup
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/sh | |
| # use on develop servers only | |
| DAYSSTORING=14 | |
| GZIP="$(which gzip)" | |
| BACKUPDIR=/home/patricy/backup/database | |
| BACKUPPREFIX="all-databases" | |
| MYSQLDUMP="$(which mysqldump)" | |
| MYSQLUSER=<backup_powerfull_user> | |
| MYSQLPASS=<backup_powerfull_user_pass> | |
| #GITKEY=/home/patricy/.ssh/bitbucket/common | |
| cd $BACKUPDIR/ | |
| #all databases in separate files | |
| #for DB in `mysql -u$MYSQLUSER -p$MYSQLPASS -e "show databases"|grep -v Database|grep -v information_schema|grep -v mysql`; do $MYSQLDUMP -u$MYSQLUSER -p$MYSQLPASS -f $DB |$GZIP -9 > $BACKUPDIR/dump.`date "+%Y-%m-%d"`.$DB.sql.gz; done; | |
| #all databases in one file | |
| $MYSQLDUMP -u$MYSQLUSER -p$MYSQLPASS --all-databases |$GZIP -9 > $BACKUPDIR/dump.`date "+%Y-%m-%d"`.$BACKUPPREFIX.sql.gz | |
| #without gzip (for git) | |
| #$MYSQLDUMP -u$MYSQLUSER -p$MYSQLPASS --all-databases > $BACKUPDIR/dump.`date "+%Y-%m-%d"`.$BACKUPPREFIX.sql | |
| #find $BACKUPDIR/ -name 'dump.*.$BACKUPPREFIX.sql.gz' -mtime +$DAYSSTORING -type f -exec git rm {} \; | |
| find $BACKUPDIR/ -name 'dump.*.$BACKUPPREFIX.sql.gz' -mtime +$DAYSSTORING -type f -exec rm {} \; | |
| #git add . | |
| #git commit -m 'daily backup databases '`date "+%Y-%m-%d"` | |
| #git push origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment