{"id":19697397,"url":"https://github.com/xetys/open-psql-backup","last_synced_at":"2025-08-05T06:11:55.145Z","repository":{"id":68967783,"uuid":"119566709","full_name":"xetys/open-psql-backup","owner":"xetys","description":"A small bash based tool to manage PostgeSQL backups in a clever way in k8s","archived":false,"fork":false,"pushed_at":"2021-11-23T17:19:18.000Z","size":13,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T11:42:23.915Z","etag":null,"topics":["backup","k8s","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xetys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-01-30T17:00:04.000Z","updated_at":"2021-11-23T17:19:21.000Z","dependencies_parsed_at":"2023-05-21T09:15:42.641Z","dependency_job_id":null,"html_url":"https://github.com/xetys/open-psql-backup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xetys/open-psql-backup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xetys%2Fopen-psql-backup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xetys%2Fopen-psql-backup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xetys%2Fopen-psql-backup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xetys%2Fopen-psql-backup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xetys","download_url":"https://codeload.github.com/xetys/open-psql-backup/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xetys%2Fopen-psql-backup/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268844815,"owners_count":24316055,"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","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","k8s","postgresql"],"created_at":"2024-11-11T19:38:14.793Z","updated_at":"2025-08-05T06:11:55.098Z","avatar_url":"https://github.com/xetys.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Open PSQL Backup for Kubernetes\n\nThis project contains a small tool for automatic backup management of PostgreSQL databases.\n\n## Motivation\n\nOne of the core features is the **regression based deleting**. This means that you will find maximum three hours old backups from today\nwhile just one backup per week from three months ago. That principle is based on the assumption, that normally we need high frequent\nupdates only to restore from crash, which possibly happened today or yesterday. If we are interested in data, from past year,\nit's ok to have just one snapshot for the week. If a database doesn't grow over time, the overall storage needed for the backup \nconverges to a certain size, instead of growing linear. In a real world, you possibly have a linear-like growth of your database size.\nA linear grow of backup storage on top, means you might have a growth of n*2 if you backup all three hours. With regression based deleting\nand a constant growth of database size, the backup storage growth is still linear.\n\n## How to use\n\nThere are three types of get open-psql-working in your Kubernetes cluster:\n\n* As a Deployment with daemon mode enabled\n* One-Time job\n* Cronjob\n\n### Deployment\n\nJust run \n\n``` \n$ kubectl run open-psql-backup --image=xetys/open-psql-backup --env=\"DAEMON_MODE=1\"\n```\n\nTo run open-psql-backup in the current namespace. Deploy it in a different namespace if you wan't to watch postgres containers in a other namespace than default.\nThis deployment method is highly compatible with kuberntes 1.3+, as it only uses deployments.\n\n### Onetime job\n\nRun:\n\n```\n$ kubectl apply -f k8s/job.yaml\n```\n\nto run the tool one time or\n\n## Cronjob\n\n```\n$ kubectl apply -f k8s/cronjob.yaml\n```\n\n## How this tool finds postgres containers\n\nOpen-psql-backup looks for any deployments with the image `postgresql`. \n\nThe recent version of this tool used labels to include marked instances. The current version automatically\nfinds all PostgresSQL instances. Maybe in future, it would be better to allow in- and exclusion of containers.\n\nNote: Currently this tool expects Postgres instances with no password set!\n\n## ./k8s-psql-tool.sh\n\nThe core bash script of this project is the k8s-psql-tool. It allows several operations on PSQL databases, such\nas backup (either with the old timestamp, or with a given name), restore by name, and executing queries on all instances\n\nusage: ./k8s-psql-tool.sh \u003cACTION\u003e [OPTIONS...]\n\nActions: \n\n  backup: creates a backup of all PostgreSQL databases\n  \n  restore: restores PostgreSQL databases\n  \n  exec: executes a query against all PostgreSQL databases\n  \n  \nOptions: \n\n  --name,-n:      do not use a timestamp as backup name, but specify it\n  \n  --filter,-f:    perform action on a filtered set of databases\n  \nExamples: \n```bash\n# just create a backup\n./k8s-psql-tool.sh backup\n# create a backup in the directory 'my-backup'\n./k8s-psql-tool.sh backup -n my-backup\n# restore backup 'my-backup'\n./k8s-psql-tool.sh restore -n my-backup\n# restore backup 'my-backup', but only uaa databases\n./k8s-psql-tool.sh restore -n my-backup -f uaa\n# run some sql on all dbs\n./k8s-psql-tool.sh exec 'select * from table'\n# run some sql on uaa database\n./k8s-psql-tool.sh exec -f uaa 'select * from table'\n```\n\n\n## Where the backups are stored\n\n\nThe default configuration stores backups in the path `/backups` of the volume named 'backup-dir'. You can change that by using a `PersistentVolumeClaim`\nor any other storage strategy you like.\n\n\n### example with CephFS\n\nThe current example shows a binding to a static CephFS using a local secret. With this, you can open the backups \non all nodes by doing a manual ceph mount on that FS to get the backups. This approach works the same in [rook.io](https://rook.io) and its\nshared filesystem.\n\n### example with CIFS (old)\n\nMy initial case was using the [Storage Boxes](https://www.hetzner.de/storage-box) from Hetzner, which allow CIFS connections. On every node, I've `cifs-utils` installed and mounted\na CIFS mount into `/var/backups/database`.\n\nThis could be achieved by adding\n\n```\n//uXXX.your-storagebox.de/backup/db-backup /var/backups/databases cifs user,uid=500,rw,suid,username=uXXX,password=YYY 0 0\n```\n\nto `/etc/fstab` and mounting it using\n\n```\n$ mount -t cifs -o username=uXXX,password=YYY //uXXX.your-storagebox.de/backup/db-backup /var/backups/databases\n```\n\nand then installing open-psql-backup\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxetys%2Fopen-psql-backup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxetys%2Fopen-psql-backup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxetys%2Fopen-psql-backup/lists"}