Database Settings¶
The following databases are supported by this application. You can customize the commands used for backup and the resulting filenames with the following settings.
MySQL
DBBACKUP_MYSQL_EXTENSION (optional)
Entension to use for a mysql backup. By default this is 'mysql'.
DBBACKUP_MYSQL_BACKUP_COMMANDS (optional)
List of commands to use execute when creating a backup. Commands are sent to popen and
should be split into shlex tokens. By default, the following command is run:
mysqldump -u{username} -p{password} {databasename} >
DBBACKUP_MYSQL_RESTORE_COMMANDS (optional)
List of commands to use execute when creating a backup. Commands are sent to popen and
should be split into shlex tokens. By default, the following command is run:
mysql -u{username} -p{password} {databasename} <
Postgres
DBBACKUP_POSTGRESQL_EXTENSION (optional)
Entension to use for a postgres backup. By default this is 'psql'.
DBBACKUP_POSTGRESQL_BACKUP_COMMANDS (optional)
List of commands to use execute when creating a backup. Commands are sent to popen and
should be split into shlex tokens. By default, the following command is run:
pg_dump {databasename} >
DBBACKUP_POSTGRESQL_RESTORE_COMMANDS (optional)
List of commands to use execute when restoring a backup. Commands are sent to popen and
should be split into shlex tokens. By default, the following commands are run:
dropdb {databasename}
createdb {databasename} --owner={username}
psql -1 {databasename} <
SQLite
DBBACKUP_SQLITE_EXTENSION (optional)
Entension to use for an sqlite backup. By default this is 'sqlite'.
DBBACKUP_SQLITE_BACKUP_COMMANDS (optional)
List of commands to use execute when creating a backup. Commands are sent to popen and
should be split into shlex tokens. By default, the following command is run:
[READ_FILE, '{databasename}']
DBBACKUP_SQLITE_RESTORE_COMMANDS (optional)
List of commands to use execute when restoring a backup. Commands are sent to popen and
should be split into shlex tokens. By default, the following command is run:
[WRITE_FILE, '{databasename}']
Defining Backup Commands¶
When creating backup or restore commands, there are a few template variables you can use in the commands (listed below). Also note, ending a command with > or < will pipe the file contents from or to the command respectively.
- {databasename}: Name of the database from settings.py
- {servername}: Optional SERVER_NAME setting in settings.py
- {username}: Database username from settings.py
- {password}: Database password from settings.py
- {datetime}: Current datetime string (see DBBACKUP_DATE_FORMAT).
- {extension}: File extension for the current database.
There are also two special commands READ_FILE and WRITE_FILE which take the form of a two-item list, the second item being the file to read or write. Please see the SQLite settings above for reference.
Global Settings
DBBACKUP_STORAGE (required)
String pointing to django-dbbackup location
module to use when performing a backup. You can see the exact definitions to use
in the required settings for the backup location of your choice above.
DBBACKUP_DATE_FORMAT (optional)
The
Python datetime format to use when
generating the backup filename. By default this is '%Y-%m-%d-%H%M%S'.
DBBACKUP_SERVER_NAME (optional)
An optional server name to use when
generating the backup filename. This is useful to help distinguish between development and
production servers. By default this value is not used and the servername is not included in
the generated filename.
DBBACKUP_FILENAME_TEMPLATE (optional)
The template to use when generating
the backup filename. By default this is '{databasename}-{servername}-{datetime}.{extension}'.
About This Project
Django-DBBackup is a project created by me (Michael Shepanski), a web developer located in Boston, MA. I developed this project out of a need to backup this personal site database to an offsite location. Feel free to manipulate, improve upon, and use however you'd like.
Licensed via Creative Commons Attribution.
More Documentation
- Introduction & Management Commands
- Setup Backups to Amazon S3
- Setup Backups to Dropbox
- Setup Backups to Local Disk
- Customize Backup Commands
Database Compatability
My testing resulted the following. If you find different, please let me know and I will adjust.
- SQLite 3.x
- MySQL 5.x
- PostgreSQL 9.x
Support & Contact
- Fork me from the Bitbucket repository.
- Join discussions in the Google Group.
- Report issues and bugs here.
- Follow @PKKid on Twitter for release updates and news.