From 4a16029c9a95fa4153ffb39d5b8df135356ca9fe Mon Sep 17 00:00:00 2001 From: Damian Strycharczuk <8152038+Leny1996@users.noreply.github.com> Date: Fri, 26 Jun 2020 20:28:01 +0200 Subject: [PATCH] Added custom label for selecting containers --- src/backup.sh | 11 ++++++++--- src/entrypoint.sh | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backup.sh b/src/backup.sh index e6b4f89..19c1f51 100755 --- a/src/backup.sh +++ b/src/backup.sh @@ -12,9 +12,14 @@ function info { info "Backup starting" TIME_START="$(date +%s.%N)" DOCKER_SOCK="/var/run/docker.sock" + +if [ ! -z "$BACKUP_CUSTOM_LABEL" ]; then + CUSTOM_LABEL="--filter label=$BACKUP_CUSTOM_LABEL" +fi + if [ -S "$DOCKER_SOCK" ]; then TEMPFILE="$(mktemp)" - docker ps --format "{{.ID}}" --filter "label=docker-volume-backup.stop-during-backup=true" > "$TEMPFILE" + docker ps --format "{{.ID}}" --filter "label=docker-volume-backup.stop-during-backup=true" $CUSTOM_LABEL > "$TEMPFILE" CONTAINERS_TO_STOP="$(cat $TEMPFILE | tr '\n' ' ')" CONTAINERS_TO_STOP_TOTAL="$(cat $TEMPFILE | wc -l)" CONTAINERS_TOTAL="$(docker ps --format "{{.ID}}" | wc -l)" @@ -35,7 +40,7 @@ fi if [ -S "$DOCKER_SOCK" ]; then TEMPFILE="$(mktemp)" docker ps \ - --filter "label=docker-volume-backup.exec-pre-backup" \ + --filter "label=docker-volume-backup.exec-pre-backup" $CUSTOM_LABEL \ --format '{{.ID}} {{.Label "docker-volume-backup.exec-pre-backup"}}' \ > "$TEMPFILE" while read line; do @@ -55,7 +60,7 @@ TIME_BACKED_UP="$(date +%s.%N)" if [ -S "$DOCKER_SOCK" ]; then TEMPFILE="$(mktemp)" docker ps \ - --filter "label=docker-volume-backup.exec-post-backup" \ + --filter "label=docker-volume-backup.exec-post-backup" $CUSTOM_LABEL \ --format '{{.ID}} {{.Label "docker-volume-backup.exec-post-backup"}}' \ > "$TEMPFILE" while read line; do diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 89363ef..d23a9d1 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -17,6 +17,7 @@ INFLUXDB_URL="${INFLUXDB_URL:-}" INFLUXDB_DB="${INFLUXDB_DB:-}" INFLUXDB_CREDENTIALS="${INFLUXDB_CREDENTIALS:-}" INFLUXDB_MEASUREMENT="${INFLUXDB_MEASUREMENT:-docker_volume_backup}" +BACKUP_CUSTOM_LABEL="${BACKUP_CUSTOM_LABEL:-}" EOF chmod a+x env.sh source env.sh