Skip to content

Instantly share code, notes, and snippets.

@ForestMars
Created October 18, 2012 14:25
Show Gist options
  • Select an option

  • Save ForestMars/3912205 to your computer and use it in GitHub Desktop.

Select an option

Save ForestMars/3912205 to your computer and use it in GitHub Desktop.
Drush database backup and rotate
## 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