|
|
@ -7,11 +7,13 @@ |
|
|
|
## - the target of the link is launched first, and get a chance to ``relation-set`` |
|
|
|
## - both side of the scripts get to use ``relation-get``. |
|
|
|
|
|
|
|
. lib/common |
|
|
|
|
|
|
|
set -e |
|
|
|
|
|
|
|
## XXXvlab: should use container name here so that it could support |
|
|
|
## multiple postgres |
|
|
|
label=pg-backup-$SERVICE_NAME |
|
|
|
label=${SERVICE_NAME}-pg-backup |
|
|
|
DST=$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/cron/$label |
|
|
|
schedule=$(relation-get schedule) |
|
|
|
|
|
|
@ -20,10 +22,6 @@ if ! echo "$schedule" | egrep '^\s*(([0-9/,*-]+\s+){4,4}[0-9/,*-]+|@[a-z]+)\s*$' |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
## XXXvlab: how is this meant to works if there's multiples postgres (about PGHOST=?) ? |
|
|
|
## Warning: using '\' in heredoc will be removed in the final cron file, which |
|
|
|
## is totally wanted: cron does not support multilines. |
|
|
|
|
|
|
|
exclude_dbs=$(relation-get exclude-dbs 2>/dev/null) || true |
|
|
|
exclude_dbs=$(echo "$exclude_dbs" | shyaml get-values 2>/dev/null | |
|
|
|
nspc) || true |
|
|
@ -31,20 +29,16 @@ exclude_dbs=$(echo "$exclude_dbs" | shyaml get-values 2>/dev/null | |
|
|
|
## Warning: 'docker -v' will use HOST directory even if launched from |
|
|
|
## 'cron' container. |
|
|
|
file_put "$DST" <<EOF |
|
|
|
COMPOSE_LAUNCHER_OPTS=$COMPOSE_LAUNCHER_OPTS |
|
|
|
|
|
|
|
$schedule root lock $label -D -p 10 -c "\ |
|
|
|
docker run --rm \ |
|
|
|
-e PGHOST=\$POSTGRES_PORT_5432_TCP_ADDR \ |
|
|
|
-e PGHOST=${SERVICE_NAME} \ |
|
|
|
-e exclude_dbs=\"$exclude_dbs\" \ |
|
|
|
-v /root/.pgpass:/root/.pgpass \ |
|
|
|
-v \"$BASE_CHARM_PATH/resources/bin/pg-backup:/usr/sbin/pg-backup\" \ |
|
|
|
-v \"$LOCAL_DB_PASSFILE\":/root/.pgpass \ |
|
|
|
-v \"$HOST_CHARM_STORE/${CHARM_REL_PATH#${CHARM_STORE}/}/resources/bin/pg-backup:/usr/sbin/pg-backup\" \ |
|
|
|
-v \"$SERVICE_DATASTORE/var/backups/pg:/var/backups/pg\" \ |
|
|
|
--entrypoint pg-backup \ |
|
|
|
\"$DOCKER_BASE_IMAGE\"" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/pg-backup_script.log |
|
|
|
EOF |
|
|
|
chmod +x "$DST" |
|
|
|
|
|
|
|
config-add "\ |
|
|
|
$MASTER_TARGET_SERVICE_NAME: |
|
|
|
links: |
|
|
|
- $MASTER_BASE_SERVICE_NAME |
|
|
|
" |