Created
October 30, 2025 21:20
-
-
Save dginhoux/d9026c4ae5d7c8144b888cbe3a6a5783 to your computer and use it in GitHub Desktop.
all run as swarm services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| VM_INSTANCE_NAME="sma-vmetrics" | |
| VM_DUMP_DATE=$( date "+%Y%m%d_%H%M" ) | |
| VM_SNAP_URL="http://vmetrics:8428/snapshot/create" | |
| VM_INSTANCE_DATA_PATH="/mnt/gfs_lv_swarm_prod0/sma/vmetrics-data/" | |
| VM_BACKUP_DATA_PATH="/mnt/db-backup/vmetrics-data" | |
| VM_BACKUP_DST="fs:///backup/${VM_INSTANCE_NAME}/${VM_DUMP_DATE}" | |
| DOCKER_SVC="vmdump_${VM_INSTANCE_NAME}" | |
| # DOCKER_HOST="tcp://socket:2375" | |
| DOCKER_HOST="unix:///var/run/host_docker.sock" | |
| DOCKER_CONSTRAINT="node.role==worker" | |
| DOCKER_NET="sma_internal" | |
| DOCKER_IMAGE="registry.infra.ginhoux.net:5000/victoriametrics/vmbackup:v1.128.0" | |
| # cleanup | |
| /usr/bin/docker --host ${DOCKER_HOST} service rm "${DOCKER_SVC}" || true | |
| # create task | |
| /usr/bin/docker --host ${DOCKER_HOST} service create \ | |
| --name "${DOCKER_SVC}" \ | |
| --detach=true \ | |
| --user root \ | |
| --mode replicated --replicas 1 \ | |
| --restart-condition=none \ | |
| --constraint "${DOCKER_CONSTRAINT}" \ | |
| --network ${DOCKER_NET} \ | |
| --mount type=bind,src=${VM_INSTANCE_DATA_PATH},dst=/storage \ | |
| --mount type=bind,src=${VM_BACKUP_DATA_PATH},dst=/backup \ | |
| ${DOCKER_IMAGE} \ | |
| -storageDataPath=/storage \ | |
| -snapshot.createURL=${VM_SNAP_URL} \ | |
| -dst=${VM_BACKUP_DST} | |
| # wait for the single task to complete and capture exit code swarm sets DesiredState=shutdown when the task exit | |
| task_id="" | |
| while [ -z "$task_id" ]; do | |
| task_id="$(/usr/bin/docker --host ${DOCKER_HOST} service ps --no-trunc --filter desired-state=shutdown -q "${DOCKER_SVC}" || true)" | |
| sleep 1 | |
| done | |
| exitcode="$(/usr/bin/docker --host ${DOCKER_HOST} inspect -f '{{.Status.ContainerStatus.ExitCode}}' "$task_id")" | |
| logs="$(/usr/bin/docker --host ${DOCKER_HOST} service logs --raw "${DOCKER_SVC}" 2>&1 || true)" | |
| # cleanup | |
| /usr/bin/docker --host ${DOCKER_HOST} service rm "${DOCKER_SVC}" || true | |
| echo "$logs" | |
| exit "$exitcode" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment