0

I am on Mac OS X using MAMP PRO as my local development environment. I want to quickly reset my site to a known state in order to run some tests I have prepared in Selenium.

I have the Backup and Migrate module installed which makes it easy to restore from the command line via drush, but if I restore using Backup and Migrate it appears to only overwrite the existing data and leaves other data in place, which I don't want-- I want to erase all of this other data as well so that I can be sure that the database is in exactly the same state as the backup file.

Currently, I log in to PHPmyadmin, drop all of the tables in the database, and then re-import from the backup. This seems somewhat inefficient to me; is there a way to automate this from the command line?

1

I use /applications/mamp/library/bin/mysqldump -uUSERNAME -pPASSWORD DATABASE >backup.sql to back my database up and then /applications/mamp/library/bin/mysql -uUSERNAME -pPASSWORD DATABASE <backup.sql to restore it.

1

You can also use the Demo module. It's not command line but through the Drupal admin UI. It lets you create 'snapshots' of your database and lets you reset your database to those snapshots.

0

If you're looking to script this process, I would recommend using drush.

If space is a concern than pipe the results to gzip as well. drush sql-dump | gzip > ../backup/FILENAME.sql.gz

Remember it's a good idea to clear out your database prior to running your restore.

drush sql-drop - This drops the tables on your existing database. drush sqlc < path/to/FILENAME.sql - This imports the file into your database.

With a compressed backup:

gunzip < ../backup/FILENAME.sql.gz | drush sqlc

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.