Created
May 10, 2019 09:18
-
-
Save waja/c49de7a8d1c196ebd2b28b541cacc11f to your computer and use it in GitHub Desktop.
Dump postgresql databases and roles, keeping last 14 days, the lazy way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE="$(date +%d)" | |
psql_user="postgres" | |
psql_host="/var/run/postgresql/" | |
psql_port="5432" | |
[ -f /opt/gitlab/etc/gitlab-psql-rc ] && . /opt/gitlab/etc/gitlab-psql-rc | |
su - ${psql_user} -c "pg_dumpall -g --host=${psql_host}" > /var/backups/db_dumps/psql_roles.sql-$DATE | |
gzip -f /var/backups/db_dumps/psql_roles.sql-$DATE | |
su - ${psql_user} -c "pg_dumpall --host=${psql_host}" > /var/backups/db_dumps/pgsqldump-$DATE | |
gzip -f /var/backups/db_dumps/pgsqldump-$DATE | |
find /var/backups/db_dumps/*.gz -mtime +14 -exec rm {} + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment