docker-volume-dump/restore.sh

27 lines
704 B
Bash

#!/bin/bash
set -e -o pipefail
info() {
[ "$#" -gt 0 ] && echo -e "\033[1m>>> $*\033[0m" >&2
}
for i in *.json; do
[ -f "$i" ] || continue
vol_name=${i%.json}
archive=$vol_name.tar.zst
info "Recovering \"$vol_name\" from \"$archive\""
label_args=()
readarray -t labels < <(jq -r '.[0].Labels | to_entries | .[] | .key + "=" + .value' "$i")
for label in "${labels[@]}"; do
label_args+=(--label "$label")
done
set -x
docker volume create "${label_args[@]}" "$vol_name"
docker run --rm -v "$vol_name":/vol -v "$(readlink -f "$archive")":/vol.tar.zst:ro \
localhost/archiver bsdtar -C /vol --numeric-owner -xf /vol.tar.zst
set +x
done