|  | 
|  | 1 | +# postgresql-backup-restore-fs | 
|  | 2 | +Service to backup and/or restore a PostgreSQL database to/from a local filesystem directory | 
|  | 3 | + | 
|  | 4 | +## How to use it | 
|  | 5 | +1. Create a directory on the filesystem to hold your backups | 
|  | 6 | +2. Supply all appropriate environment variables | 
|  | 7 | +3. Run a backup and check your directory for that backup | 
|  | 8 | + | 
|  | 9 | +### Environment variables | 
|  | 10 | +`MODE` Valid values: `backup`, `restore` | 
|  | 11 | + | 
|  | 12 | +`DB_HOST` hostname of the database server | 
|  | 13 | + | 
|  | 14 | +`DB_NAME` name of the database | 
|  | 15 | + | 
|  | 16 | +`DB_OPTIONS` optional arguments to supply to the backup or restore commands | 
|  | 17 | + | 
|  | 18 | +`DB_ROOTPASSWORD` password for the `DB_ROOTUSER` | 
|  | 19 | + | 
|  | 20 | +`DB_ROOTUSER` database administrative user, typically "postgres" for PostgreSQL databases | 
|  | 21 | + | 
|  | 22 | +`DB_USERPASSWORD` password for the `DB_USER` | 
|  | 23 | + | 
|  | 24 | +`DB_USER` user that accesses the database (PostgreSQL "role") | 
|  | 25 | + | 
|  | 26 | +`BACKUP_DIR` e.g., _/path/to/database-backups_ **NOTE: no trailing slash** | 
|  | 27 | + | 
|  | 28 | +>**Versioning of the backup file is left as an exercise for the user.  This script will overwrite an existing backup file.** | 
|  | 29 | +
 | 
|  | 30 | +## Docker Hub | 
|  | 31 | +This image is built automatically on Docker Hub as [silintl/postgresql-backup-restore-fs](https://hub.docker.com/r/silintl/postgresql-backup-restore-fs/) | 
|  | 32 | + | 
|  | 33 | +## Playing with it locally | 
|  | 34 | +You'll need [Docker](https://www.docker.com/get-docker), [Docker Compose](https://docs.docker.com/compose/install/), and [Make](https://www.gnu.org/software/make/). | 
|  | 35 | + | 
|  | 36 | +1. cd .../postgres-backup-restore-fs | 
|  | 37 | +2. mkdir ./mybackups | 
|  | 38 | +3. cp -p test/world.sql.gz ./mybackups | 
|  | 39 | +4. `make db`  # creates the Postgres DB server | 
|  | 40 | +5. `make restore`  # restores the DB dump file | 
|  | 41 | +6. `docker ps -a`  # get the Container ID of the exited restore container | 
|  | 42 | +7. `docker logs <containerID>`  # review the restoration log messages | 
|  | 43 | +8. `make backup`  # create a new DB dump file | 
|  | 44 | +9. `docker ps -a`  # get the Container ID of the exited backup container | 
|  | 45 | +10. `docker logs <containerID>`  # review the backup log messages | 
|  | 46 | +11. `make restore`  # restore the DB dump file from the new backup | 
|  | 47 | +12. `docker ps -a`  # get the Container ID of the exited restore container | 
|  | 48 | +13. `docker logs <containerID>`  # review the restoration log messages | 
|  | 49 | +14. `make clean`  # remove containers and network | 
|  | 50 | +15. `docker volume ls`  # find the volume ID of the Postgres data container | 
|  | 51 | +16. `docker volume rm <volumeID>`  # remove the data volume | 
|  | 52 | +17. `docker images`  # list existing images | 
|  | 53 | +18. `docker image rm <imageID ...>`  # remove images no longer needed | 
0 commit comments