Initial commit
This commit is contained in:
commit
238278565a
4 changed files with 82 additions and 0 deletions
13
Dockerfile
Normal file
13
Dockerfile
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#
|
||||||
|
# Custom resticker docker image with pg_dump support without needing to mount
|
||||||
|
# docker.sock
|
||||||
|
#
|
||||||
|
|
||||||
|
FROM mazzolino/restic:pr-225
|
||||||
|
|
||||||
|
RUN apk update \
|
||||||
|
&& apk add --no-cache postgresql-client tini \
|
||||||
|
&& rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
COPY bin/dump_pg_db.sh /usr/local/bin/dump_pg_db.sh
|
||||||
|
RUN chmod +x /usr/local/bin/dump_pg_db.sh
|
7
LICENSE
Normal file
7
LICENSE
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Copyright (c) 2025 azyrite
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
41
README.md
Normal file
41
README.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# resticker-pg
|
||||||
|
An adapted [resticker](https://github.com/djmaze/resticker) Docker image built
|
||||||
|
with a PostgreSQL client and pg_dump helper script to safely backup PostgreSQL
|
||||||
|
databases without having to mount `docker.sock`.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
Make sure to set the following environment variables:
|
||||||
|
- `DB_HOSTNAME`
|
||||||
|
- `DB_USERNAME`
|
||||||
|
- `DB_PASSWORD`
|
||||||
|
|
||||||
|
`DB_PORT` can be used to set a non-standard database port.
|
||||||
|
|
||||||
|
This image is a drop-in replacement for resticker, and therefore will not
|
||||||
|
attempt to dump a database (even if environment variables are provided) unless
|
||||||
|
the script is explicitly called.
|
||||||
|
|
||||||
|
The database dump script is copied to `/usr/local/bin/dump_pg_db.sh`. To use it,
|
||||||
|
add the following to the container's environment:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
environment:
|
||||||
|
# ...
|
||||||
|
PRE_COMMANDS: |-
|
||||||
|
/usr/local/bin/dump_pg_db.sh
|
||||||
|
# ...
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting dump is written to `/data/db/DATABASE_NAME.sql` within
|
||||||
|
the container.
|
||||||
|
|
||||||
|
# Credits
|
||||||
|
Base Dockerfile from https://github.com/djmaze/resticker [Apache-2.0 License]
|
||||||
|
|
||||||
|
Postgres backup/dump script adapted from https://github.com/ixc/restic-pg-dump-docker
|
||||||
|
[MIT License]
|
||||||
|
|
||||||
|
# License
|
||||||
|
This project is licensed under the MIT license.
|
||||||
|
|
||||||
|
See [LICENSE](LICENSE).
|
21
bin/dump_pg_db.sh
Normal file
21
bin/dump_pg_db.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Dumping all postgres databases at $DB_USERNAME@$DB_HOSTNAME"
|
||||||
|
|
||||||
|
mkdir -p /data/db
|
||||||
|
|
||||||
|
# Set env vars for psql
|
||||||
|
export PGUSER=$DB_USERNAME
|
||||||
|
export PGPASSWORD=$DB_PASSWORD
|
||||||
|
export PGHOST=$DB_HOSTNAME
|
||||||
|
export PGPORT=$DB_PORT
|
||||||
|
|
||||||
|
DBLIST=$(psql -d postgres -q -t -c "SELECT datname FROM pg_database WHERE datname NOT IN ('postgres', 'rdsadmin', 'template0', 'template1')")
|
||||||
|
for db in $DBLIST; do
|
||||||
|
echo "Dumping database $db"
|
||||||
|
pg_dump --file="/data/db/$dbname.sql" --no-owner --no-privileges --dbname="$dbname"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Finished dumping all databases"
|
Loading…
Reference in a new issue