Skip to content

Commit

Permalink
add local mode for backup
Browse files Browse the repository at this point in the history
  • Loading branch information
stempler committed Sep 10, 2018
1 parent 5f16e4e commit 6567c44
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ COPY ./scripts /dockup/
RUN chmod 755 /dockup/*.sh
CMD ["/dockup/run.sh"]

ENV S3_BUCKET_NAME docker-backups.example.com
ENV AWS_ACCESS_KEY_ID **DefineMe**
ENV AWS_SECRET_ACCESS_KEY **DefineMe**
ENV AWS_DEFAULT_REGION us-east-1
ENV PATHS_TO_BACKUP auto
ENV BACKUP_NAME backup
ENV RESTORE false
Expand All @@ -29,4 +25,14 @@ ENV BACKUP_TAR_TRIES 5
ENV BACKUP_TAR_RETRY_SLEEP 30
ENV DOCKUP_MODE aws

# aws
ENV S3_BUCKET_NAME docker-backups.example.com
ENV AWS_ACCESS_KEY_ID **DefineMe**
ENV AWS_SECRET_ACCESS_KEY **DefineMe**
ENV AWS_DEFAULT_REGION us-east-1

# local
ENV LOCAL_TARGET /dockup/target
RUN mkdir $LOCAL_TARGET

WORKDIR /dockup
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ It should either be empty or hold a path and end with a slash.

For more complex backup tasks as dumping a database, you can optionally define the environment variables `BEFORE_BACKUP_CMD` and `AFTER_BACKUP_CMD`.

### Backup target

Although dockup was initially designed to specifically support backups so AWS S3, you can also use different kinds of backup targets.

This is possible via the environment variable `DOCKUP_MODE`.
It allows running custom logic to do the actual backup/restoration (see subfolders in `scripts/`).

By default, the following modes are available:

- `aws` - store in AWS S3
- `local` - store in a local folder (e.g. in a volume mounted into the dockup container, defaults to `/dockup/target`)

### Detect volumes

Instead of providing paths manually you can set the `PATHS_TO_BACKUP` to `auto`.
Expand Down
4 changes: 2 additions & 2 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ cleanup
end_time=`date +%Y-%m-%d\\ %H:%M:%S\\ %Z`
backup_duration=`date -u -d @"$SECONDS" +'%-Mm %-Ss'`
if [ $rc -ne 0 ]; then
notifyFailure "Error uploading backup to S3."
notifyFailure "Error backuping up archive."
echo -e "[$end_time] Backup failed\n\n"
exit $rc
else
notifySuccess
echo -e "[$end_time] Archive successfully uploaded to S3\n\n"
echo -e "[$end_time] Archive successfully backed up\n\n"
fi
5 changes: 5 additions & 0 deletions scripts/local/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# Move the tarball to the destination folder
echo "Move the archive to the destination folder..."
mv $tarball ${LOCAL_TARGET}/
10 changes: 10 additions & 0 deletions scripts/local/restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ ! -n "${LAST_BACKUP}" ]; then
# Find last backup file
: ${LAST_BACKUP:=$(ls $LOCAL_TARGET/ -1 | grep ^$BACKUP_NAME | sort -r | head -n1)}
fi

# Retrieve from local storage
echo "Retrieving backup archive $LAST_BACKUP..."
mv "${LOCAL_TARGET}/${LAST_BACKUP}" $LAST_BACKUP
4 changes: 4 additions & 0 deletions scripts/notifications.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

#
# Note: Notification texts assume storage in S3
#

function notifySuccess {
if [ "$NOTIFY_BACKUP_SUCCESS" == "true" ]; then
notify_summary="[${S3_FOLDER}$BACKUP_NAME] Backup succeeded."
Expand Down
2 changes: 2 additions & 0 deletions test-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ docker run --rm \
-e GPG_KEYRING=/$GPG_KEYNAME.pub \
--volumes-from dockup-data-test \
-v $(pwd)/$GPG_KEYNAME.pub:/$GPG_KEYNAME.pub \
-v $(pwd)/target:/dockup/target \
--name dockup-run-test wetransform/dockup:local
rc=$?; if [ $rc -ne 0 ]; then
echo "ERROR: Error running backup"
Expand All @@ -69,6 +70,7 @@ docker run --rm \
--volumes-from dockup-data-test \
-v $(pwd)/$GPG_KEYNAME.pub:/$GPG_KEYNAME.pub \
-v $(pwd)/$GPG_KEYNAME.sec:/$GPG_KEYNAME.sec \
-v $(pwd)/target:/dockup/target \
--name dockup-run-test wetransform/dockup:local
rc=$?; if [ $rc -ne 0 ]; then
echo "ERROR: Error running restore"
Expand Down
3 changes: 2 additions & 1 deletion test-env.txt.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ AWS_DEFAULT_REGION=eu-central-1
S3_BUCKET_NAME=???
S3_FOLDER=dockup-test/
NOTIFY_BACKUP_SUCCESS=false
NOTIFY_BACKUP_FAILURE=false
NOTIFY_BACKUP_FAILURE=false
DOCKUP_MODE=aws

0 comments on commit 6567c44

Please sign in to comment.