From 89c8a20db686aa0779d21a792d76ce371a013a4f Mon Sep 17 00:00:00 2001 From: Florian Kick Date: Thu, 16 May 2019 14:58:36 +0200 Subject: [PATCH 1/4] made AWS credentials optional --- src/entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index a711023..e7cea09 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -22,11 +22,13 @@ source env.sh # Configure AWS CLI mkdir -p .aws +if [ ! -z "$AWS_ACCESS_KEY_ID" ]; then cat < .aws/credentials [default] aws_access_key_id = ${AWS_ACCESS_KEY_ID} aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY} EOF +fi if [ ! -z "$AWS_DEFAULT_REGION" ]; then cat < .aws/config [default] From 493a5a8240e97435dfffa23b0b489bd07be7b867 Mon Sep 17 00:00:00 2001 From: Florian Kick Date: Wed, 22 May 2019 16:21:37 +0200 Subject: [PATCH 2/4] updated readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 562ff41..4bb2c86 100644 --- a/README.md +++ b/README.md @@ -149,8 +149,8 @@ Variable | Default | Notes `BACKUP_WAIT_SECONDS` | `0` | The backup script will sleep this many seconds between re-starting stopped containers, and proceeding with archiving/uploading the backup. This can be useful if you don't want the load/network spike of a large upload immediately after the load/network spike of container startup. `BACKUP_HOSTNAME` | `$(hostname)` | Name of the host (i.e. Docker container) in which the backup runs. Mostly useful if you want a specific hostname to be associated with backup metrics (see InfluxDB support). `AWS_S3_BUCKET_NAME` | | When provided, the resulting backup file will be uploaded to this S3 bucket after the backup has ran. -`AWS_ACCESS_KEY_ID` | | Required when using `AWS_S3_BUCKET_NAME`. -`AWS_SECRET_ACCESS_KEY` | | Required when using `AWS_S3_BUCKET_NAME`. +`AWS_ACCESS_KEY_ID` | | Optional when using `AWS_S3_BUCKET_NAME`. Allows you to provide credentials for AWS authentication. +`AWS_SECRET_ACCESS_KEY` | | Optional when using `AWS_S3_BUCKET_NAME`. Allows you to provide credentials for AWS authentication. `AWS_DEFAULT_REGION` | | Optional when using `AWS_S3_BUCKET_NAME`. Allows you to override the AWS CLI default region. Usually not needed. `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`. From c6323c5bf09a1fa13a0a36cb6b935f8c5f389562 Mon Sep 17 00:00:00 2001 From: Florian Kick Date: Wed, 22 May 2019 16:23:09 +0200 Subject: [PATCH 3/4] fixed cron issue due to pam config on Amazon Linux --- Dockerfile | 2 +- src/entrypoint.sh | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 00a12b4..0d01f6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:18.04 -RUN apt-get update && apt-get install -y --no-install-recommends curl cron awscli +RUN apt-get update && apt-get install -y --no-install-recommends curl cron awscli less vim RUN rm -rf /var/lib/apt/lists/* # https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#install-using-the-convenience-script diff --git a/src/entrypoint.sh b/src/entrypoint.sh index e7cea09..eb9c340 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -39,6 +39,11 @@ fi # Add our cron entry, and direct stdout & stderr to Docker commands stdout echo "Installing cron.d entry: docker-volume-backup" echo "$BACKUP_CRON_EXPRESSION root /root/backup.sh > /proc/1/fd/1 2>&1" > /etc/cron.d/docker-volume-backup +echo -e "\n" >> /etc/cron.d/docker-volume-backup + +# Remove line from PAM config because cron won't run otherwise on AWS EC2 Linux +echo "Editing /etc/pam.d/cron" +sed -i '/session required pam_loginuid.so/c\#session required pam_loginuid.so' /etc/pam.d/cron # Let cron take the wheel echo "Starting cron in foreground with expression: $BACKUP_CRON_EXPRESSION" From b36c6e5f40a81a9b79e19f39b9f08350d130603a Mon Sep 17 00:00:00 2001 From: Florian Kick Date: Wed, 21 Aug 2019 14:49:13 +0200 Subject: [PATCH 4/4] delay date replacement in backup filename to avoid overwriting same backup file on every cronjob run --- src/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index eb9c340..7ce65d4 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -8,7 +8,7 @@ cat < env.sh BACKUP_SOURCES="${BACKUP_SOURCES:-/backup}" BACKUP_CRON_EXPRESSION="${BACKUP_CRON_EXPRESSION:-@daily}" AWS_S3_BUCKET_NAME="${AWS_S3_BUCKET_NAME:-}" -BACKUP_FILENAME="$(date +"${BACKUP_FILENAME:-backup-%Y-%m-%dT%H-%M-%S.tar.gz}")" +BACKUP_FILENAME="\$(date +"${BACKUP_FILENAME:-backup-%Y-%m-%dT%H-%M-%S.tar.gz}")" BACKUP_ARCHIVE="${BACKUP_ARCHIVE:-/archive}" BACKUP_WAIT_SECONDS="${BACKUP_WAIT_SECONDS:-0}" BACKUP_HOSTNAME="${BACKUP_HOSTNAME:-$(hostname)}"