Backup strategy for django Backup strategy for django django django

Backup strategy for django


I'm not sure there is a one size fits all answer especially since you haven't said what you intend to backup. My usual MO:

  • Source code: use source control such as svn or git. This means that you will usually have: dev, deploy and repository backups for code (specially in a drsc).
  • Database: this also depends on usage, but usually:
    • Have a dump_database.py management command that will introspect settings and for each db will output the correct db dump command (taking into consideration the db type and also the database name).
    • Have a cron job on another server that connects through ssh to the application server, executes the dump db management command, tars the sql file with the db name + timestamp as the file name and uploads it to another server (amazon's s3 in my case).
  • Media file: e.g. user uploads. Keep a cron job on another server that can ssh into the application server and calls rsync to another server.

The thing to keep in mind though, it what is the intended purpose of the backup.If it's accidental (be it disk failure, bug or sql injection) data loss or simply restoring, you can keep those cron jobs on the same server.

If you also want to be safe in case the server is compromised, you cannot keep the remote backup credentials (sshkeys, amazon secret etc) on the application server! Or else an attacker will gain access to the backup server.