It took me a little while to figure out the correct sequence for restoring a Django backup. If you have borked your database, this is how to put it back together.
- Drop the old database.
- Create a new database.
python manage.py dbrestore
. Retrieve the data and insert it into appropriate tables. This will restore the most recent backup.python manage.py migrate
. I only do this if I’m restoring data from my production system into a development environment where there are new migrations.
And you’re back! It seems pretty trivial, but I hit my head against this a number of times and got very frustrated when things just wouldn’t work. Follow this recipes and you’re good.
As a side note, if it’s taking a long, long, long time to restore your backup then you can add the following SQL code to the backup file:
-- Near the top of the file.
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, AUTOCOMMIT = 0;
-- Near the bottom of the file.
SET AUTOCOMMIT = @OLD_AUTOCOMMIT;
COMMIT;