2

I'm looking for an easy way to backup (and if needed restore) the databases of a Drupal multisite using Drush.

Drush command I use to backup all the databases:

drush @sites sql-dump --result-file --gzip

The backup of the databases seems to work. After executing the above command, databases are automatically stored in /root/drush-backups/DATABASENAME/TIMESTAMP/DATABASENAME_TIMESTAMP.sql.gz

What command can I use to restore the last backup of the databases automatically?

What is the best way to backup and restore the databases of a Drupal 7 multisite using Drush?

PS: I'm using Git, so I only need to backup databases.

Many thanks for your advice!

4

This is how I do the restore on a site-by-site basis:

drush @site1 sql-drop -y && gunzip -c /path/to/backup/file1 | drush @site1 sql-cli

You could maintain a list of site aliases to database name and write a shell script to automate the process.

The database name for an individual site could be extracted as follows:

drush status @site1 --fields=db-name --field-labels=0

Unfortunately, there's no all-in-one solution for restore.

An alternate solution would be to use the Backup and Migrate module, which has drush integration. There are bam-backup and bam-restore commands which might be easier to work with.

As @Duncanmoo mentioned, it's also good to run drush rebuild-registry after the restore.

  • 1
    You may need to first drop the existing tables: drush @site sql-drop -y && drush @site sql-cli < ~/db.sql.(Drush knows what user and DB to work with based on the site you are working on). BTW Good idea to do a drush rebuild-registry after restoring the DB. – Duncanmoo Sep 23 '15 at 11:04
  • Good idea, I'll include the sql-drop. – cleaver Sep 24 '15 at 14:39

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.