Skip to content

Backup the prod database

Alex Saunier edited this page May 23, 2017 · 4 revisions

Create a custom backup of some database

ssh compose0.exoscale.infra.camptocamp.org
source /opt/c2corg-docker/server-list.env

# go to the postgresql-backup composition
cd /opt/c2corg-docker/composition/production/postgresql-backup/

# enter the postgresql container
docker-compose exec postgresql bash

# pause the replication, create the dump and resume the replication
psql -U postgres -A0tc 'SELECT pg_xlog_replay_pause()'
pg_dump -U postgres -Fc --create c2corg > /var/backups/pgsql/c2corg_custom_backup.dump
psql -U postgres -A0tc 'SELECT pg_xlog_replay_resume()'

Note that you can also use the nightly backup script to backup all database in one pass, but this will overwrite the last night backup.

/usr/local/bin/pgsql-backup.sh 

Get local copy of some backup file

List existing backups:

ssh compose0.exoscale.infra.camptocamp.org "
cd /opt/c2corg-docker && source server-list.env && \
cd /opt/c2corg-docker/composition/production/postgresql-backup && source .env && \
docker-compose exec postgresql ls -la /var/backups/pgsql
"

Make a local copy:

BACKUP=pgsql_wednesday.tar

ssh compose0.exoscale.infra.camptocamp.org '
cd /opt/c2corg-docker && source server-list.env && \
cd /opt/c2corg-docker/composition/production/postgresql-backup && source .env
export POSTGRESQL_CONTAINER=`docker-compose ps -q postgresql`
docker -H $DOCKER_HOST exec $POSTGRESQL_CONTAINER cat /var/backups/pgsql/$BACKUP
' > ~/data/c2corgv6/backups/$BACKUP

Restart the replication

ssh compose0.exoscale.infra.camptocamp.org
source /opt/c2corg-docker/server-list.env
cd /opt/c2corg-docker/composition/production/postgresql-backup/

# Replication is configured in docker-compose-initreplication.yml
# docker volume rm c2corg_pgsql_replica

docker-compose -f docker-compose-initreplication.yml create && \
docker-compose -f docker-compose-initreplication.yml up && \
docker-compose up -d

This does not remove backup files (hosted out of docker) but only reset postgresql's streaming-replication.