Question

Does running drush up run a database backup? From testing, it looks like it doesn't. Should I be doing a separate database backup before I run drush up to update?

Was it helpful?

Solution

No it doesn't. It only makes a backup of the current module directories, before it replaces them.

To create a sql dump, use

drush sql-dump > filename.sql.

But remember to move the file outside of your webroot.

OTHER TIPS

To make gzipped mysql dump with drush:

drush sql-dump --gzip --result-file

Update from the wranvaud's comment: If you don't specify the result file it will be stored on you home folder under: ~/drush-backups/<db_name>/<timestamp>/<database_file>.sql.gz, otherwise you can specify --result-file='~/Documents/'

If you have the Backup and Migrate module module installed, you can call it from Drush with

$ drush bam-backup

This is a bash script solution to Backup and Restore from command line with drush and Acquia-Drupal:

  • Note: You only have to change basepath,sitename and maybe drushpath in both scripts to fit your needs
  • Note 2: The Backup script will create a .tar containing your site files plus a data.sql file describing your database
  • Note3: The restore script will chose the last .tar backup file created by the backup script

INSTRUCTIONS

1) Find the drush path (drush is included in acquia), in my case (drushpath="/Applications/acquia-drupal/drush")

2) Create a backup_mysite file and a restore_mysite file and include them in your bin folder path (for example: /usr/local/bin)

3) Edit backup_mysite

#!/bin/bash
# Text color variables
txtgrn=$(tput setaf 2)    # Green
txtylw=$(tput setaf 3)    # Yellow

basepath="path-to-your-server-root" #4ex "/Users/monojones/www"
backuppath="$basepath/backups"
drushpath="/Applications/acquia-drupal/drush"
sitename="your-sitename"
tempdir="$backuppath/backup_$sitename"

if [ -d $backuppath ]; then
 echo "Backup path finded. [ $backuppath ]"
else
  echo "Creating backup path... [ $backuppath ]"
  mkdir $backuppath
fi

echo "${txtylw}Backing up $sitename ... ${txtgrn}"
if [ -d "$backuppath/$sitename" ]; then
 echo "Backup subdir finded."
else
 echo "Creating $backuppath/$sitename" 
 mkdir $backuppath/$sitename
fi
echo "${txtylw}"
mkdir $tempdir
$drushpath/drush -r $basepath/$sitename  sql-dump --result-file=$tempdir/data.sql
tar -pczf $tempdir/files.tgz $basepath/$sitename $systempaths
tar -pczf $backuppath/$sitename/$sitename.backup_$(date +%Y%m%d%H%M).tar.gz $tempdir
rm -rf $tempdir

4) Edit restore_mysite

#!/bin/bash
# Text color variables
txtred=$(tput setaf 1)    # Red
txtgrn=$(tput setaf 2)    # Green
txtylw=$(tput setaf 3)    # Yellow

basepath="path-to-your-server-root" #4ex "/Users/monojones/www"
backuppath="$basepath/backups"
sitename="your-sitename"
drushpath="/Applications/acquia-drupal/drush"

echo "${txtylw}Restoring ${txtred}$sitename ${txtylw} database: ${txtgrn}"
FILE=`ls -1 $backuppath/$sitename/$sitename.backup_* | tail -n 1`
echo "Last backup file: ${txtpur} $FILE ${txtylw}"
mkdir temp_drupalbackup_$sitename 
tar -C temp_drupalbackup_$sitename -zxvf $FILE ${backuppath:1}/backup_$sitename/data.sql
$drushpath/drush sql-drop
drush sql-cli <  temp_drupalbackup_$sitename/${backuppath:1}/backup_$sitename/data.sql
rm -R temp_drupalbackup_$sitename

You can also use sql-sync for backup.

$ drush sql-sync -v @site1 @site2

It is very easy now with Drush 5

“Note: Drush 5 introduced archive-dump and archive-restore commands which allow you to backup your code, files, and database into a single file."

https://drupal.org/upgrade/backing-your-site-command-line

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top