Skip to main content

django-bacman

A simple library that takes a snapshot of a Postgres or MySQL database and uploads it to AWS S3.

Installation

Step 1: - Install it

pip install bacman

Step 2: Add proper environment variables in your /etc/environment or .pam_environment

DATABASE_URL="postgres://dbuser:dbpass@localhost:5432/dbname"

AWS_SECRET_ACCESS_KEY="YOURAWSSECRETACCESSKEYABCDEFGHIJKLMNOPQR"
AWS_ACCESS_KEY_ID="YOURAWSACCESSKEYIDAB"

BACMAN_BUCKET="bacman-example"
BACMAN_DIRECTORY="/home/bacman/backups"
BACMAN_REGION="eu-west-1"

Step 3: Create .py file with the contents below

from bacman.postgres import Postgres

Postgres(cleanup_local_snapshots=True)

or

from bacman.postgres import Postgres

Postgres(cleanup_local_snapshots=True, local_snapshot_timeout=24)

Settings

DATABASE

DATABASE_URL

Please add the DATABASE_URL variable to your /etc/environment or .pam_environment

Read more at https://github.com/kennethreitz/dj-database-url

Amazon Web Services

AWS_ACCESS_KEY_ID

Please add the AWS_ACCESS_KEY_ID variable to your /etc/environment or .pam_environment

AWS_SECRET_ACCESS_KEY

Please add the AWS_SECRET_ACCESS_KEY variable to your /etc/environment or .pam_environment

BacMan

BACMAN_BUCKET

Please add the BACMAN_BUCKET variable to your /etc/environment or .pam_environment

BACMAN_DIRECTORY

  • default: /tmp/bacman

BACMAN_PREFIX

  • default (Postgres): pgdump
  • default (MySQL): mysqldump

Examples

Example 1

# /home/bacman/runbacman.py

from bacman.postgres import Postgres

# Uploads to remote AWS bucket
# Removes old database snapshots that are older than 30 days (720 hrs)
def main():
  Postgres(to_remote=True, cleanup_local_snapshots=True)

if __name__ == "__main__":
  main()

Example 2

# /home/bacman/runbacman.py

from bacman.postgres import Postgres

# Uploads to remote AWS bucket
# Removes local snapshots that are older than 360 hrs
# Removes remote snapshots that are older than 180 hours
def main():
  Postgres(to_remote=True, remote_snapshot_timeout=180, cleanup_local_snapshots=True, local_snapshot_timeout=360)

if __name__ == "__main__":
  main()

Crontab example

Take a snapshot every 2 hours

0 */2 * * * ~/env/bin/python ~/runbacman.py >> /home/django/logs/crontab.log 2>&1

You can test run the script above by

$ chmod +x runbacman.py
$ python runbacman.py
# Open your crontab editor by typing crontab -e

# m h  dom mon dow   command
0 */2 * * * ~/env/bin/python ~/runbacman.py >> /home/bacman/logs/crontab.log 2>&1

Metadata

Release files for bacman 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bacman 0.3
File Size Uploaded Provenance
bacman-0.3.tar.gz 5.8 kB Without provenance Details

Release files / bacman-0.3.tar.gz

Download URL bacman-0.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
33315e5754aa8e40fcf1404af12c9f3a550518dc6ce478f1a502f5925f6c868f
BLAKE2b-256 checksum
How to use checksums
ab828e803ab1a43ccdf19a2ac7c7c8165db70632aa9799e3fcf237f701257760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/3.7.3

Security for bacman 0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page