如何备份一个django数据库 [英] how to backup a django db

查看:903
本文介绍了如何备份一个django数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Postgres数据库的Django应用程序。我需要能够备份和还原数据库,以确保数据不会丢失,并且能够在测试期间将数据从生产服务器复制到开发服务器。



似乎有几种不同的方式来做到这一点:



1)直接与数据库数据库进行交互。所以,对于Postgres,我可以使用pg_dumpall和psql编写一个脚本。



2)使用Django附带的sqlclear / sqlall命令。



3)使用Django附带的dumpdata / loaddata命令。所以从你想要备份的数据库创建新的灯具,然后将它们加载到要恢复的数据库中。



4)使用Django插件,如 django-dbbackup



我真的不明白利弊的这些不同的技术。



刚刚在我头上的选项1是db特定的,选项3似乎更适合设置初始数据。但我仍然不确定选项2有哪些优势选项4。



谢谢。

解决方案

对于常规备份,我将使用PostgreSQL自己的本机工具去选择1,因为它可能是最有效的。



认为选项2主要关注创建表并加载初始数据,因此不适合备份。



选项3可用于备份,如果您需要迁移到不同的数据库平台,因为数据被转储成非SQL形式,即Django理解的JSON。



选项4插件似乎正在使用db自己的备份工具(根据选项1),但另外提供帮助,将备份推送到Amazon S3或Dropbox中的云存储


I have a Django application that uses a Postgres db. I need to be able to backup and restore the db - both to ensure no data is lost and to be able to copy data from the production server to the development server during testing.

There seem to be a few different ways to do this:

1) Just interact with the db directly. So, for Postgres I might 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 you want to backup and then load them into the db you want to restore.

4) Use a Django plugin like django-dbbackup.

I really don't understand the pros/cons of these different techniques.

Just off the top of my head option 1 is db-specific, and option 3 seems more suited to setting up initial data. But I'm still not sure what advantages option 4 has over option 2.

Thanks.

解决方案

For regular backups I'd go for option 1, using PostgreSQL's own native tool, as it is probably the most efficient.

I would argue that option 2 is primarily concerned with creating the tables and loading initial data so is not suitable for backups.

Option 3 can be used for backups and would be particularly useful if you needed to migrate to a different database platform since the data is dumped in a non-SQL form, i.e. JSON understood by Django.

Option 4 the plugin appears to be using db's own backup tools (as per option 1) but additionally provides help to push your backups into cloud storage in Amazon S3 or Dropbox

这篇关于如何备份一个django数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆