Skip to content

Commit

Permalink
Merge pull request #14 from Leny1996/master
Browse files Browse the repository at this point in the history
Added custom label for selecting containers
  • Loading branch information
jareware authored Oct 24, 2020
2 parents 0ba7c32 + 4a16029 commit ad367db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad367db

Please sign in to comment.