How to backup django db

I have a Django application using Postgres db. I need to be able to backup and restore db - both in order not to lose data, and be able to copy data from the production server to the development server during testing.

There seem to be several ways to do this:

1) Just interact with db directly. So, for Postgres, I can write a script using pg_dumpall and psql.

2) Use the "sqlclear / sqlall" commands that come with Django.

3) Use the "dumpdata / loaddata" commands that come with Django. So, create new fixtures from the db that you want to create, and then load them into the db that you want to restore.

4) Use a Django plugin like django-dbbackup .

I really don't understand the pros and cons of these different methods.

Just at the top of my head, option 1 is set to db, and option 3 is more suitable for setting up the source data. But I'm still not sure what the advantages of option 4 are over option 2.

Thanks.

+27
source share
2 answers

For regular backups, I would choose option 1 using my own native PostgreSQL tool, as it is probably the most efficient.

I would say that option 2 is primarily associated with creating tables and loading source data, therefore it is not suitable for backup.

3 , , , SQL, JSON, Django.

4 , -, db ( 1), Amazon S3 Dropbox

+16

1-3 , (, FileField) . , . , Django , FileField, , .

№4. , django-archive *. :

  • ( ContentType, Permission Session , manage.py migrate) .

  • , FileField ImageField. , , ; , , .

  • , , .

  • , (gz bz2).

, django_archive INSTALLED_APPS settings.py . ( ), :

./manage.py archive

* :

+17

Source: https://habr.com/ru/post/1624534/


All Articles