diff --git a/Dockerfile b/Dockerfile index d718696..8f3dcdf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ -FROM debian:jessie +FROM alpine:3.4 MAINTAINER Vitalii Vokhmin +RUN apk add --no-cache curl bzip2 +COPY backup.sh /bin/backup.sh +COPY restore.sh /bin/restore.sh +RUN chmod +x /bin/backup.sh /bin/restore.sh + ENV VOLUME_MOUNT_POINT '/data' ENV ARCHIVE_NAME_PREFIX 'volume_container' ENV FTP_PATH '' ENV FTP_USER 'anonymous' ENV FTP_PASSWORD '' -RUN apt-get update && apt-get install -y curl bzip2 && apt-get clean && rm -rf /var/lib/apt/lists - -ADD upload_archive.sh /bin/upload_archive.sh -RUN chmod +x /bin/upload_archive.sh -CMD [ "/bin/upload_archive.sh" ] +CMD [ "/bin/backup.sh" ] diff --git a/README.md b/README.md index 84cc781..5a21435 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # volume-ftp-backup -Docker image for simple volumes backup over FTP. +Docker image for simple volumes backup/restore over FTP. # Description Image with a simple script that archives the data from the Docker volume @@ -9,6 +9,8 @@ Uses user provided archive name prefix + unix timestamp as suffix for the filena I. e. `volume_container-123456789.tar.bz2`. # Usage + +## Backup Image accepts following environment variables: - `VOLUME_MOUNT_POINT` - path where volume is mounted. Default is `/data` - `ARCHIVE_NAME_PREFIX` - prefix for archive file name. Default is `volume_container` @@ -16,7 +18,18 @@ Image accepts following environment variables: - `FTP_USER` - FTP username. Default is `anonymous` - `FTP_PASSWORD` - FTP password for authentication -## Example +### Example ```bash docker run --rm -v my_shiny_volume:/data -e ARCHIVE_NAME_PREFIX='my_shiny_backup' -e FTP_PATH='ftp://example.com/backups/shiny_folder/' -e FTP_USER='user' -e FTP_PASSWORD='secret' vit1/volume-ftp-backup ``` + +## Restore +- `VOLUME_MOUNT_POINT` - path where volume is mounted. Default is `/data` +- `FTP_PATH` - full path to archive. I. e. `ftp://example.com/path/to/storage/volume_container_1234.tar.bz2` +- `FTP_USER` - FTP username. Default is `anonymous` +- `FTP_PASSWORD` - FTP password for authentication + +### Example +```bash +docker run --rm -v my_shiny_volume:/data -e -e FTP_PATH='ftp://example.com/backups/shiny_folder/volume_container_1234.tar.bz2' -e FTP_USER='user' -e FTP_PASSWORD='secret' vit1/volume-ftp-backup restore.sh +``` diff --git a/upload_archive.sh b/backup.sh similarity index 92% rename from upload_archive.sh rename to backup.sh index 11a38dd..364a6b3 100644 --- a/upload_archive.sh +++ b/backup.sh @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh +set -x # Required env vars: # diff --git a/restore.sh b/restore.sh new file mode 100644 index 0000000..0825b2a --- /dev/null +++ b/restore.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh +set -e + +# Required env vars: +# +# $VOLUME_MOUNT_POINT +# $FTP_PATH +# $FTP_USER +# $FTP_PASSWORD + +cmd="curl $FTP_PATH --user '$FTP_USER:$FTP_PASSWORD' -o /tmp/archive.tar.bz2" +eval "$cmd" +tar -jxC / -f /tmp/archive.tar.bz2 +rm /tmp/archive.tar.bz2