server-scripts/backup-postgres

13 lines
392 B
Plaintext
Raw Normal View History

2018-09-13 07:43:21 +00:00
#!/usr/bin/env bash
2014-10-19 15:27:33 +00:00
2018-09-13 07:43:21 +00:00
set -eu -o pipefail
2014-10-19 15:27:33 +00:00
# restore:
# psql -f $database.dump postgres
2018-09-13 07:43:21 +00:00
export PATH="/usr/bin/:$PATH"
LIST=$(lxc-attach -n postgres -- psql -h postgres -U postgres -At -c "select datname from pg_database order by datname;")
for d in $LIST; do
[ "$d" == "template0" ] && continue
lxc-attach -n postgres -- pg_dump -h postgres -U postgres "$d" | gzip -c > "$d.dump.gz"
2014-10-19 15:27:33 +00:00
done