Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup strategy for django

I recently deployed a couple of web applications built using django (on webfaction). These would be some of the first projects of this scale that i am working on, so I wanted to know what an effective backup strategy was for maintaining backups both on webfaction and an alternate location.

EDIT:

What i want to backup?

Database and user uploaded media. (my code is managed via git)

like image 769
zsquare Avatar asked Feb 25 '11 17:02

zsquare


1 Answers

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.

like image 123
Arthur Debert Avatar answered Nov 15 '22 05:11

Arthur Debert