{"id":26471099,"url":"https://github.com/willandskill/bacman","last_synced_at":"2025-03-19T20:12:19.450Z","repository":{"id":57413726,"uuid":"43603121","full_name":"willandskill/bacman","owner":"willandskill","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-18T21:47:58.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-19T03:34:05.216Z","etag":null,"topics":["backup","database","mysql","postgres","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willandskill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-03T15:12:58.000Z","updated_at":"2020-09-01T15:00:20.000Z","dependencies_parsed_at":"2022-09-05T03:51:25.114Z","dependency_job_id":null,"html_url":"https://github.com/willandskill/bacman","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willandskill%2Fbacman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willandskill%2Fbacman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willandskill%2Fbacman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willandskill%2Fbacman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willandskill","download_url":"https://codeload.github.com/willandskill/bacman/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244498515,"owners_count":20462344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","database","mysql","postgres","python"],"created_at":"2025-03-19T20:12:18.946Z","updated_at":"2025-03-19T20:12:19.444Z","avatar_url":"https://github.com/willandskill.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bacman\n\nA simple library that takes a snapshot of a Postgres or MySQL database and uploads it to AWS S3.\n\n## Installation\n\n**Step 1:** - Install it\n\n```bash\npip install bacman\n```\n\n**Step 2:** Add proper environment variables in your `/etc/environment` or `.pam_environment`\n\n```bash\nDATABASE_URL=\"postgres://dbuser:dbpass@localhost:5432/dbname\"\n\nAWS_SECRET_ACCESS_KEY=\"YOURAWSSECRETACCESSKEYABCDEFGHIJKLMNOPQR\"\nAWS_ACCESS_KEY_ID=\"YOURAWSACCESSKEYIDAB\"\n\nBACMAN_BUCKET=\"bacman-example\"\nBACMAN_DIRECTORY=\"/home/bacman/backups\"\nBACMAN_REGION=\"eu-west-1\"\n```\n\n**Step 3:** Create .py file with the contents below\n\n```python\nfrom bacman.postgres import Postgres\n\nPostgres(cleanup_local_snapshots=True)\n```\n\nor\n\n```python\nfrom bacman.postgres import Postgres\n\nPostgres(cleanup_local_snapshots=True, local_snapshot_timeout=24)\n```\n\n## Settings\n\n### DATABASE\n\n**DATABASE_URL**\n\nPlease add the `DATABASE_URL` variable to your `/etc/environment` or `.pam_environment`\n\nRead more at https://github.com/kennethreitz/dj-database-url\n\n### Amazon Web Services\n\n**AWS_ACCESS_KEY_ID**\n\nPlease add the `AWS_ACCESS_KEY_ID` variable to your `/etc/environment` or `.pam_environment`\n\n**AWS_SECRET_ACCESS_KEY**\n\nPlease add the `AWS_SECRET_ACCESS_KEY` variable to your `/etc/environment` or `.pam_environment`\n\n### BacMan\n\n#### BACMAN_BUCKET\n\nPlease add the `BACMAN_BUCKET` variable to your `/etc/environment` or `.pam_environment`\n\n#### BACMAN_DIRECTORY\n\n- default: `/tmp/bacman`\n\n#### BACMAN_PREFIX\n\n- default (Postgres): `pgdump`\n- default (MySQL): `mysqldump`\n\n### Examples\n\n#### Example 1\n\n```python\n# /home/bacman/runbacman.py\n\nfrom bacman.postgres import Postgres\n\n# Uploads to remote AWS bucket\n# Removes old database snapshots that are older than 30 days (720 hrs)\ndef main():\n  Postgres(to_remote=True, cleanup_local_snapshots=True)\n\nif __name__ == \"__main__\":\n  main()\n```\n\n#### Example 2\n\n```python\n# /home/bacman/runbacman.py\n\nfrom bacman.postgres import Postgres\n\n# Uploads to remote AWS bucket\n# Removes local snapshots that are older than 360 hrs\n# Removes remote snapshots that are older than 180 hours\ndef main():\n  Postgres(to_remote=True, remote_snapshot_timeout=180, cleanup_local_snapshots=True, local_snapshot_timeout=360)\n\nif __name__ == \"__main__\":\n  main()\n```\n\n#### Crontab example\n\nTake a snapshot every 2 hours\n\n```\n0 */2 * * * ~/env/bin/python ~/runbacman.py \u003e\u003e /home/django/logs/crontab.log 2\u003e\u00261\n```\n\nYou can test run the script above by\n\n```\n$ chmod +x runbacman.py\n$ python runbacman.py\n```\n\n```bash\n# Open your crontab editor by typing crontab -e\n\n# m h  dom mon dow   command\n0 */2 * * * ~/env/bin/python ~/runbacman.py \u003e\u003e /home/bacman/logs/crontab.log 2\u003e\u00261\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillandskill%2Fbacman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillandskill%2Fbacman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillandskill%2Fbacman/lists"}