Skip to main content

No project description provided

Project description

Django PostgreSQL Copy

The package django-pg-copy provides Django management commands for backing up and restoring PostgreSQL databases. These were developed for copying production databases to development, to allow developers to share images with one another, or bring local development databases up to date. It can also be handy for creating different local databases for different branches, and for only creating one migration after tweaking models to get them the way they need to be.

We also use it with Jenkins to automatically back up production, and restore to a staging database environment, so we can test new migrations repeatedly to ensure they'll work when we run them in production.

Installation

pip install django-pg-copy

Then add 'pg_copy', to your INSTALLED_APPS list. It is recommended that it is used in all environments (development, production) so that you can use it against different instances of your database.

Settings

PG_COPY_BACKUP_PATH = 'db_backup'

By default, PostgreSQL backups will be stored in a directory called db_backup where you run the command. This setting will override that location.

It is also recommended to add this path to your .gitignore file, if the path falls under your version control repository.

Parameters

  • --database: The database defined in the DATABASES settings to backup from or restore to.
  • --db-override: A value to override the db argument sent to psql.
  • --host-override: A value to override the host argument sent to psql.
  • --pg-home: The path to the PostgreSQL installation, if it is not on your path.
  • --file, -f: The filename to backup to, or restore from.
  • --ignore-table, -i: Do not include this table in the backup. Can pass multiple tables: -i bigtable1 -i bigtable2
  • --no-confirm: Restores the database without confirmation: be careful! (pg_restore only)

Example Commands

python manage.py pg_backup --settings=config.settings.production --database=default --filename=my_backup.sqlc

This command will create a backup in the same directory as manage.py called my_backup.sqlc using the default settings from DATABASES using the Django settings file located at config/settings/production.py.

python manage.py pg_backup

This command will create a backup in the directory ./db_backup/ (or the directory you specified with PG_COPY_BACKUP_PATH) called [timestamp].sqlc using the default settings from DATABASES using the default Django settings file resolved by manage.py.

python manage.py pg_backup -i bigtable1 -i bigtable2

This will do the same as the previous command, but omit the tables named bigtable1 and bigtable2.

python manage.py pg_restore

This command will provide a list of backup files in PG_COPY_BACKUP_PATH that can be restored. After selecting a backup file, it will confirm that the user wants to overwrite the destination database by showing which server and database will be overwritten from the settings.

python manage.py pg_restore --filename=my_file.sqlc --no-confirm

This command will read the file my_file.sqlc and confirm that the user wants to overwrite the destination database by showing which server and database will be overwritten from the settings.

Known Issues

  • When restoring, PostgreSQL's pg_restore command will output some warnings. I haven't figured out a command line option to make these warnings disappear, but they can be safely ignored if you read them. TODO: include a paste of the output here.

Release Notes

Release notes are available on GitHub

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-pg-copy-0.3.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

django_pg_copy-0.3.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file django-pg-copy-0.3.0.tar.gz.

File metadata

  • Download URL: django-pg-copy-0.3.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.3

File hashes

Hashes for django-pg-copy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b3fc1bfe6e941ce28eedebe246524f15b561d9fa6768938048d25386da10608d
MD5 1f856a4c3edceb6aa46cc8e788fae254
BLAKE2b-256 9e3cbf7e57477cc273985f01524295f0a18b3f5b2bfe66c0995e2daf1caa8e66

See more details on using hashes here.

File details

Details for the file django_pg_copy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: django_pg_copy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.3

File hashes

Hashes for django_pg_copy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc545c585b7fb7fc05a6a3f577b034c3dbc4f0a05b825c64ce0fdd6a4decd231
MD5 d4aae0f324bf95fcfea7c0332809efeb
BLAKE2b-256 7d145484dfbc36f5c2e251ad697ccc873e87decc699673505e853ab50df37efb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page