https://github.com/efrecon/pgbackup Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} efrecon / pgbackup Public * Notifications * Fork 0 * Star 44 Dockerized local and offline backing up of PostgresQL with rotation and compression. License BSD-3-Clause license 44 stars 0 forks Activity Star Notifications * Code * Issues 1 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights efrecon/pgbackup This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 2 branches 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/e] Use Git or checkout with SVN using the web URL. [gh repo clone efreco] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @efrecon efrecon Merge pull request #2 from efrecon/feature/wait-pg ... b41d3be Sep 23, 2020 Merge pull request #2 from efrecon/feature/wait-pg Active wait for connection b41d3be Git stats * 26 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time wait-for @ 1c5c811 Fix for file listing September 23, 2020 11:52 .gitmodules Fix for file listing September 23, 2020 11:52 Dockerfile Add wait for September 23, 2020 11:53 LICENSE Initial commit February 19, 2018 10:41 README.md Add wait for September 23, 2020 11:53 backup.sh Support docker postgress standard vars also September 23, 2020 10:10 docker-compose.yml Add wait for September 23, 2020 11:53 multi.sh Modernise shell impl. and follow 12-factors September 21, 2020 17:50 offsite.sh Fix for file listing September 23, 2020 11:52 View code Simple Automated Backup Solution for PostgreSQL Example Usage and Command-Line Options backup.sh offsite.sh Docker README.md Simple Automated Backup Solution for PostgreSQL This project covers two intertwined use cases: 1. Continuous and regular dumps of one or all PostgreSQL databases at a given host in a format that permits recovery in case of disasters. This is backup.sh. 2. Continuous and regular copying of these dumps in a compressed form to a (supposedly) remote directory in order to facilitate offsite backup and recovery in case of disasters. This is offsite.sh. The project is tuned for usage within a Dockerised environment and each tool described below performs only one backup or compression. Typical scenarios will periodically restart containers based on this image using a host-wide cron-like daemon such as dockron. Example An example compose file is provided as a plausible real-life scenario. The file docker-compose.yml starts up the following containers: 1. db, an instance of the PostgreSQL database. 2. pgbackup, which runs backup.sh once and will perform a backup of all databases when it starts. 3. davbackup, which runs offsite.sh once and will copy the latest backup to another volume in compressed form. This could be a WebDAV mounted volume, even though it isn't since this is just an example. 4. pulse, runs an instance of efrecon/dockron and will restart the two previous containers from time to time so they can regularly perform their operations. Usage and Command-Line Options backup.sh This shell (not bash) script has the following options: Description: backup.sh will backup one or all PostgreSQL databases at a given (remote) host, and rotate dumps to keep disk usage under control. Usage: backup.sh [-option arg]... where all dash-led single options are as follows: -v Be more verbose -h host Specify host to connect to, defaults to localhost -p port Specify port of daemon, defaults to 5432 -u user User to authenticate with at database, defaults to postgres. -w password Password for user, defaults to empty -W path Same as -w, but read content of password from file instead -d destination Directory where to place (and rotate) backups. -n basename Basename for file to create, date-tags allowed, defaults to: %Y%m%d-%H%M%S.sql -k keep Number of backups to keep, defaults to empty, meaning keep all backups -b database Name of database to backup, defaults to empty, meaning all databases -t command Command to execute once done, path to backup will be passed as an argument. -o output Output type: sql or csv (only tables content). When the output type is sql, an entire dump of the database(s) will be generated using pg_dump or pg_dumpall. When the output type is csv, a sub-directory of the destination directory will be created using the basename. Under this directory, there will be as many directories created as there are databases to dump, with the same name as the database. In these, one file for each table will be created, with the same name as the table and the extension .csv. CSV output do not capture anything else than the data itself, meaning that no functions, triggers, etc. can be backed up using this mechanism. offsite.sh This shell (not bash) script has the following options: Description: offline.sh will compress the latest file matching a pattern, compress it, move it to a destination directory and rotate files in this directory to keep disk space under control. Compression via zip is preferred, otherwise gzip. Usage: offline.sh [-option arg] pattern where all dash-led single options are as follows: -v Be more verbose -d destination Directory where to place (and rotate) compressed copies, default to current dir -k keep Number of compressed copies to keep, defaults to empty, meaning all -c level Compression level, defaults to 0, meaning no compression -w password Password for compressed archive, only when zip available -W path Same as -w, but read content of password from file instead -t command Command to execute once done, path to copy will be passed as an argument Docker multi.sh is specified as the default entrypoint for the image; it relays both scripts. The following command would for example request backup.sh for help: docker run -it --rm efrecon/pgbackup backup -? By default, the Docker image encapsulates multi.sh behind tini so that it will be able to properly terminate sub-processes when stopping the container. In a typical Docker environment, database initialisation takes time. This means that depending on the database container will not be enough. The Docker image for this project provides a script aiming at waiting for the connection to the postgres database to be responsive. How to perform this and chain it behind tini is exemplified in the docker-compose.yml file. About Dockerized local and offline backing up of PostgresQL with rotation and compression. Resources Readme License BSD-3-Clause license Activity Stars 44 stars Watchers 2 watching Forks 0 forks Report repository Releases No releases published Packages 0 No packages published Contributors 2 * @efrecon efrecon Emmanuel Frecon * @yanzibot yanzibot Languages * Shell 98.6% * Dockerfile 1.4% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.