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,6 +1,12 @@
#! /bin/bash #! /bin/bash
set -e set -e
(
if ! flock -x -w $FLOCK_WAIT 200 ; then
echo 'ERROR: Could not obtain lock. Exiting.'
exit 1
fi
duplicity \ duplicity \
$1 \ $1 \
--asynchronous-upload \ --asynchronous-upload \
@ -16,3 +22,4 @@ if [ -n "$CLEANUP_COMMAND" ]; then
--name $BACKUP_NAME \ --name $BACKUP_NAME \
$BACKUP_DEST $BACKUP_DEST
fi fi
) 200>/var/lock/duplicity/.duplicity.lock

View File

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