12

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?

7

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.

  • I would like to remind people to do a dump outside of your website root; so hackers will stay away. – chrisjlee May 27 '11 at 17:04
  • This "accepted" answer is not correct. Drush in fact does provide a dump of the database: "drush sql-dump" drushcommands.com/drush-7x/sql/sql-dump – sea26.2 Jan 6 '16 at 18:07
  • Um. Try reading the answer again. All of it, not just the first sentence. Because that's exactly what I wrote. The question was if "drush up" does it, not if drush can do it. – Berdir Jan 6 '16 at 18:27
8

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/'

  • 1
    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/<my_backups_folder>' – wranvaud Mar 22 '17 at 20:48
5

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

$ drush bam-backup

  • drush natively supports a database dump, without the need for an extra module, see above – wiifm Dec 10 '11 at 23:26
2

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
1

You can also use sql-sync for backup.

$ drush sql-sync -v @site1 @site2
  • This is the best way to back up a site. – user4081 Jun 21 '12 at 13:13
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.