From: Michael Brown Date: Fri, 15 Nov 2013 08:12:37 +0000 (+0000) Subject: Add postgres backups every few hours X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c266ef4b28929d1333ffafd280c330ab03e319a4;p=discourse_docker.git Add postgres backups every few hours * add cron to runit * add take-database-backup script * add cron for postgres * modify postgres startup params to allow replication --- diff --git a/standalone.template.yml b/standalone.template.yml index 02a6b2d..fb4f96e 100644 --- a/standalone.template.yml +++ b/standalone.template.yml @@ -34,6 +34,33 @@ params: - YOUR_HOSTNAME_HERE run: + - file: + path: /etc/service/cron/run + chmod: "+x" + contents: | + #!/bin/bash + exec 2>&1 + cd / + exec cron + + - file: + path: /var/lib/postgresql/take-database-backup + chown: postgres:postgres + chmod: "+x" + contents: | + #!/bin/bash + ID=db-$(date +%F_%T) + FILENAME=/shared/postgres_backup/$ID.tar.gz + pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME + echo $FILENAME + + - file: + path: /var/spool/cron/crontabs/postgres + contents: | + # m h dom mon dow command + #MAILTO=? + 0 */4 * * * /var/lib/postgresql/take-database-backup + - file: path: /etc/service/unicorn/run chmod: "+x" @@ -150,9 +177,7 @@ run: - exec: cmd: - - mkdir -p /shared/redis_data - - chown -R redis /shared/redis_data - - chgrp -R redis /shared/redis_data + - install -d -m 0755 -o redis -g redis /shared/redis_data - replace: filename: "/etc/redis/redis.conf" @@ -175,14 +200,33 @@ run: cmd: - chown -R root /var/lib/postgresql/9.2/main - "[ ! -e /shared/postgres_data ] && cp -r /var/lib/postgresql/9.2/main /shared/postgres_data || exit 0" - - chown -R postgres /shared/postgres_data - - chgrp -R postgres /shared/postgres_data + - chown -R postgres:postgres /shared/postgres_data - replace: filename: "/etc/postgresql/9.2/main/postgresql.conf" from: "data_directory = '/var/lib/postgresql/9.2/main'" to: "data_directory = '/shared/postgres_data'" + # Necessary to enable backups + - exec: + cmd: + - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup + + - replace: + filename: "/etc/postgresql/9.2/main/postgresql.conf" + from: /#?max_wal_senders *=.*/ + to: "max_wal_senders = 4" + + - replace: + filename: "/etc/postgresql/9.2/main/postgresql.conf" + from: /#?wal_level *=.*/ + to: "wal_level = hot_standby" + + - replace: + filename: "/etc/postgresql/9.2/main/pg_hba.conf" + from: /^#local +replication +postgres +peer$/ + to: "local replication postgres peer" + - exec: background: true cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main"