From cc49b48b734b0cd04bb37f0e626a6f54932e44af Mon Sep 17 00:00:00 2001 From: Jan Brinkmann Date: Sun, 12 Jun 2022 14:09:34 +0200 Subject: [PATCH 1/2] Allow to backup by means of FTP. --- README.md | 5 +++++ src/backup.sh | 6 ++++++ src/entrypoint.sh | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 1f957dc..96077ae 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,11 @@ Variable | Default | Notes `SCP_DIRECTORY` | | Directory on `SCP_HOST` where backup file is stored. `PRE_SCP_COMMAND` | | Commands that is executed on `SCP_HOST` before the backup is transferred. `POST_SCP_COMMAND` | | Commands that is executed on `SCP_HOST` after the backup has been transferred. +`FTP_HOST` | | When provided, the resulting backup file will be uploaded by means of `ftp` to the host stated. +`FTP_PORT` | 21 | Port, on which the host stated above is listening. +`FTP_USER` | | User name to log into `FTP_HOST`. +`FTP_PASS` | | Password to log into `FTP_HOST`. +`FTP_DIRECTORY` | | Directory on `FTP_HOST` where backup file is stored. `GPG_PASSPHRASE` | | When provided, the backup will be encrypted with gpg using this `passphrase`. `INFLUXDB_URL` | | When provided, backup metrics will be sent to an InfluxDB instance at this URL, e.g. `https://influxdb.example.com`. `INFLUXDB_DB` | | Required when using `INFLUXDB_URL`; e.g. `my_database`. diff --git a/src/backup.sh b/src/backup.sh index a4e91de..7ed64e8 100755 --- a/src/backup.sh +++ b/src/backup.sh @@ -119,6 +119,12 @@ if [ ! -z "$AWS_GLACIER_VAULT_NAME" ]; then TIME_UPLOADED="$(date +%s.%N)" fi +if [ ! -z "$FTP_HOST" ]; then + info "Uploading backup by means of FTP" + echo "Will upload to $FTP_HOST:$FTP_DIRECTORY" + eval ncftpput -u $FTP_USER -p $FTP_PASS -P $FTP_PORT $FTP_HOST $FTP_DIRECTORY $BACKUP_FILENAME +fi + if [ ! -z "$SCP_HOST" ]; then info "Uploading backup by means of SCP" SSH_CONFIG="-o StrictHostKeyChecking=no -i /ssh/id_rsa" diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 47ec835..4332874 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -17,6 +17,11 @@ SCP_USER="${SCP_USER:-}" SCP_DIRECTORY="${SCP_DIRECTORY:-}" PRE_SCP_COMMAND="${PRE_SCP_COMMAND:-}" POST_SCP_COMMAND="${POST_SCP_COMMAND:-}" +FTP_HOST="${FTP_HOST:-}" +FTP_PORT="${FTP_PORT:-21}" +FTP_USER="${FTP_USER:-}" +FTP_PASS="${FTP_PASS:-}" +FTP_DIRECTORY="${FTP_DIRECTORY:-}" BACKUP_FILENAME=${BACKUP_FILENAME:-"backup-%Y-%m-%dT%H-%M-%S.tar.gz"} BACKUP_ARCHIVE="${BACKUP_ARCHIVE:-/archive}" BACKUP_UID=${BACKUP_UID:-0} From fe94ef1117a0a100cb6e9e03ac1f79f730393b53 Mon Sep 17 00:00:00 2001 From: Jan Brinkmann Date: Sun, 12 Jun 2022 14:39:24 +0200 Subject: [PATCH 2/2] Update Dockerfile and documentation. --- Dockerfile | 2 +- README.md | 2 +- src/backup.sh | 3 ++- test/backing-up-via-ftp/docker-compose.yml | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test/backing-up-via-ftp/docker-compose.yml diff --git a/Dockerfile b/Dockerfile index f4c6c39..03f606c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:18.04 RUN apt-get update \ - && apt-get install -y --no-install-recommends curl cron ca-certificates openssh-client iputils-ping unzip \ + && apt-get install -y --no-install-recommends curl cron ca-certificates ncftp openssh-client iputils-ping unzip \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Install awscliv2 https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html diff --git a/README.md b/README.md index 96077ae..37bbda1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Docker image for performing simple backups of Docker volumes. Main features: - Mount volumes into the container, and they'll get backed up - Use full `cron` expressions for scheduling the backups -- Backs up to local disk, to remote host available via `scp`, to [AWS S3](https://aws.amazon.com/s3/), or to all of them +- Backs up to local disk, to remote host available via `scp` or `ftp`, to [AWS S3](https://aws.amazon.com/s3/), or to all of them - Allows triggering a backup manually if needed - Optionally stops containers for the duration of the backup, and starts them again afterward, to ensure consistent backups - Optionally `docker exec`s commands before/after backing up a container, to allow easy integration with database backup tools, for example diff --git a/src/backup.sh b/src/backup.sh index 7ed64e8..441afbc 100755 --- a/src/backup.sh +++ b/src/backup.sh @@ -122,7 +122,8 @@ fi if [ ! -z "$FTP_HOST" ]; then info "Uploading backup by means of FTP" echo "Will upload to $FTP_HOST:$FTP_DIRECTORY" - eval ncftpput -u $FTP_USER -p $FTP_PASS -P $FTP_PORT $FTP_HOST $FTP_DIRECTORY $BACKUP_FILENAME + eval ncftpput -V -u $FTP_USER -p $FTP_PASS -P $FTP_PORT $FTP_HOST $FTP_DIRECTORY $BACKUP_FILENAME + echo "Upload finished" fi if [ ! -z "$SCP_HOST" ]; then diff --git a/test/backing-up-via-ftp/docker-compose.yml b/test/backing-up-via-ftp/docker-compose.yml new file mode 100644 index 0000000..40eb819 --- /dev/null +++ b/test/backing-up-via-ftp/docker-compose.yml @@ -0,0 +1,22 @@ + +version: "3" + +services: + + dashboard: + image: grafana/grafana:7.4.5 + volumes: + - grafana-data:/var/lib/grafana # This is where Grafana keeps its data + + backup: + build: ../.. + environment: + FTP_HOST: 192.168.0.42 # Remote host IP address + FTP_USER: pi # Remote host user to log in + FTP_PASS: supersecret # Remote host password to log in + FTP_DIRECTORY: /home/pi/backups # Remote host directory + volumes: + - grafana-data:/backup/grafana-data:ro # Mount the Grafana data volume (as read-only) + +volumes: + grafana-data: