Obtain locks before restoring or backing up

This commit is contained in:
ViViDboarder 2018-05-13 10:30:02 -07:00
parent cad7d68644
commit f57ea36f98
5 changed files with 42 additions and 23 deletions

View File

@ -28,13 +28,15 @@ RUN apt-get update \
RUN [ "cross-build-end" ] RUN [ "cross-build-end" ]
VOLUME "/root/.cache/duplicity" VOLUME /root/.cache/duplicity
VOLUME "/backups" VOLUME /backups
VOLUME /var/lock/duplicity
ENV BACKUP_DEST="file:///backups" ENV BACKUP_DEST="file:///backups"
ENV BACKUP_NAME="backup" ENV BACKUP_NAME="backup"
ENV PATH_TO_BACKUP="/data" ENV PATH_TO_BACKUP="/data"
ENV PASSPHRASE="Correct.Horse.Battery.Staple" ENV PASSPHRASE="Correct.Horse.Battery.Staple"
ENV FLOCK_WAIT=60
# Cron schedules # Cron schedules
ENV CRON_SCHEDULE="" ENV CRON_SCHEDULE=""

View File

@ -28,13 +28,15 @@ RUN apt-get update \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/apt/lists/* && rm -rf /var/apt/lists/*
VOLUME "/root/.cache/duplicity" VOLUME /root/.cache/duplicity
VOLUME "/backups" VOLUME /backups
VOLUME /var/lock/duplicity
ENV BACKUP_DEST="file:///backups" ENV BACKUP_DEST="file:///backups"
ENV BACKUP_NAME="backup" ENV BACKUP_NAME="backup"
ENV PATH_TO_BACKUP="/data" ENV PATH_TO_BACKUP="/data"
ENV PASSPHRASE="Correct.Horse.Battery.Staple" ENV PASSPHRASE="Correct.Horse.Battery.Staple"
ENV FLOCK_WAIT=60
# Cron schedules # Cron schedules
ENV CRON_SCHEDULE="" ENV CRON_SCHEDULE=""

View File

@ -15,6 +15,7 @@ Mount any directories you'd like to back up as a volume and run
|BACKUP_NAME|backup|What the name for the backup should be. If using a single store for multiple backups, make sure this is unique| |BACKUP_NAME|backup|What the name for the backup should be. If using a single store for multiple backups, make sure this is unique|
|CLEANUP_COMMAND| |An optional duplicity command to execute after backups to clean older ones out (eg. "remove-all-but-n-full 2")| |CLEANUP_COMMAND| |An optional duplicity command to execute after backups to clean older ones out (eg. "remove-all-but-n-full 2")|
|CRON_SCHEDULE| |If you want to periodic incremental backups on a schedule, provide it here. By default we just backup once and exit| |CRON_SCHEDULE| |If you want to periodic incremental backups on a schedule, provide it here. By default we just backup once and exit|
|FLOCK_WAIT|60|Seconds to wait for a lock before skipping a backup|
|FTP_PASSWORD| |Used to provide passwords for some backends. May not work without an attached TTY| |FTP_PASSWORD| |Used to provide passwords for some backends. May not work without an attached TTY|
|FULL_CRON_SCHEDULE| |If you want to periodic full backups on a schedule, provide it here. This requires an incremental cron schedule too.| |FULL_CRON_SCHEDULE| |If you want to periodic full backups on a schedule, provide it here. This requires an incremental cron schedule too.|
|GPG_KEY_ID| |The ID of the key you wish to use. See [Encryption](#encryption) section below| |GPG_KEY_ID| |The ID of the key you wish to use. See [Encryption](#encryption) section below|

View File

@ -1,18 +1,25 @@
#! /bin/bash #! /bin/bash
set -e set -e
duplicity \ (
$1 \ if ! flock -x -w $FLOCK_WAIT 200 ; then
--asynchronous-upload \ echo 'ERROR: Could not obtain lock. Exiting.'
--log-file /root/duplicity.log \ exit 1
--name $BACKUP_NAME \ fi
$OPT_ARGUMENTS \
$PATH_TO_BACKUP \
$BACKUP_DEST
if [ -n "$CLEANUP_COMMAND" ]; then duplicity \
duplicity $CLEANUP_COMMAND \ $1 \
--asynchronous-upload \
--log-file /root/duplicity.log \ --log-file /root/duplicity.log \
--name $BACKUP_NAME \ --name $BACKUP_NAME \
$OPT_ARGUMENTS \
$PATH_TO_BACKUP \
$BACKUP_DEST $BACKUP_DEST
fi
if [ -n "$CLEANUP_COMMAND" ]; then
duplicity $CLEANUP_COMMAND \
--log-file /root/duplicity.log \
--name $BACKUP_NAME \
$BACKUP_DEST
fi
) 200>/var/lock/duplicity/.duplicity.lock

View File

@ -1,11 +1,18 @@
#! /bin/bash #! /bin/bash
set -e set -e
duplicity restore \ (
--force \ if ! flock -x -w $FLOCK_WAIT 200 ; then
--log-file /root/duplicity.log \ echo 'ERROR: Could not obtain lock. Exiting.'
--name $BACKUP_NAME \ exit 1
$OPT_ARGUMENTS \ fi
$@ \
$BACKUP_DEST \ duplicity restore \
$PATH_TO_BACKUP --force \
--log-file /root/duplicity.log \
--name $BACKUP_NAME \
$OPT_ARGUMENTS \
$@ \
$BACKUP_DEST \
$PATH_TO_BACKUP
) 200>/var/lock/duplicity/.duplicity.lock