Created
October 18, 2012 14:25
-
-
Save ForestMars/3912205 to your computer and use it in GitHub Desktop.
Drush database backup and rotate
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
| ## This will create a file called my_db.sql with your most recent dump and keep a history of archived (& tagged) backups. | |
| ## NB: needs some error handling when sql connect fails (currently it returns the error, but continues script execution.) | |
| #!/bin/sh | |
| #declare siteroot=/home/engineer/archetypes | |
| declare siteroot=/Applications/MAMP/htdocs/archetypes | |
| declare budir=~/dbbackups | |
| echo "tag?" | |
| read tag | |
| cd $siteroot | |
| echo "clearing caches before making backup!" | |
| drush cc all | |
| echo "dumping database" | |
| drush sql-dump > ~/dbbackups/arche_db.sql | |
| cd ~/dbbackups/ | |
| echo "rotating backup" | |
| # uncomment for daily backups | |
| #filename="db_backup_"`eval date +%Y%m%d`".tgz" | |
| # uncomment for ad hoc backups | |
| # NB: this will overwrite backups made within past minute depending on your permissions settings | |
| filename="db_backup_"`eval date +%Y%m%d%-%H%M`"."$tag".tgz" | |
| tar -zcvf $filename arche_db.sql | |
| echo "done" | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment