Skip to main content

Automation of the creation of backups of Postgres databases

Project description

Backup Postgres Database

Downloads Version Python-Version issues PyPI - Status License

Basic Usage

This simple Python package allows you to create easily the database backup of Postgres databases. You can upload them to cloud storage buckets by creating a cron job.

    from postgres_backup import Backup

    # Instantiate the backup object with Postgres database_uri
    backup = Backup(database_uri)

    # Create the file for backup
    backup.create()

Note that the URI has the following structure: db:engine:[//[user[:password]@][host][:port]/][dbname]

Bucket Storage

Have provided also the ability to store those backups in cloud buckets.

Google Cloud Storage

For using this functionality, you need to install the dependencies needed of the package:

    pip3 install postgres-backup[gcs]

And then after we have the backup created, we would keep following with:

    # Create the backup
    backup.create()

    # Upload it to google cloud storage
    backup.upload(
        provider=CloudProviders.gcs.value,
        bucket_name=bucket_name,
        google_cloud_certification
    )

Where the google_cloud_certification is a dictionary, with the key-values of the client api keys:

  • type
  • project_id
  • private_key_id
  • private_key
  • client_email
  • client_id
  • auth_uri
  • token_uri
  • auth_provider_x509_cert_url
  • client_x509_cert_url

An example would be:

    google_cloud_credentials = {
      type: "service_account",
      project_id: "xxx-saas",
      private_key_id: "xxxxxxxx",
      private_key: "-----BEGIN PRIVATE KEY-----\nxxxxxxxxxx\n-----END PRIVATE KEY-----\n",
      client_email: "xxx@xxx-saas.iam.gserviceaccount.com",
      client_id: "xxx",
      auth_uri: "https://accounts.google.com/o/oauth2/auth",
      token_uri: "https://oauth2.googleapis.com/token",
      auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
      client_x509_cert_url: "https://www.googleapis.com/robot/v1/metadata/x509/xxx%xxx-saas.iam.gserviceaccount.com"
    }

In the case that we do not have a bucket already created for storing the backups, we could add additional parameters to create it:

    from postgres_backup.schemas import CloudStorageType, CloudProviders

    backup.upload(
        provider=CloudProviders.gcs.value,
        bucket_name=bucket_name,
        google_cloud_certification,
        create_bucket=True,
        storage_class=CloudStorageType.NEARLINE.value
    )

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

postgres-backup-0.1.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

postgres_backup-0.1.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file postgres-backup-0.1.2.tar.gz.

File metadata

  • Download URL: postgres-backup-0.1.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for postgres-backup-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b9cd78351e4e1304b7c4aeaa4fd67a4919abadff668756724fa23b5dcee3cb7d
MD5 df08e77bdb07db78893a4cf361594941
BLAKE2b-256 c1bbeb79a8a75e079910cc10b6f1cd85f769c159b6eb055fc8781ef8d369b2cc

See more details on using hashes here.

File details

Details for the file postgres_backup-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for postgres_backup-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 368fc8369067395aeb5043e81538e5642aebe8fae6c84b425246ec02dabefdeb
MD5 5296359bf10ef56e8eaad904e1aefd2b
BLAKE2b-256 1a1aec7820ef66b2e0d6db5b958aa538380efd15099b93080cc275acf2eecae7

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