initial commit

This commit is contained in:
Yiyang Kang 2022-09-19 04:41:35 +08:00
commit 31d5668e24
4 changed files with 59 additions and 0 deletions

4
Dockerfile Normal file
View File

@ -0,0 +1,4 @@
FROM alpine:latest
RUN apk add --no-cache libarchive-tools zstd

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
image:
docker build --pull -t localhost/archiver .
clean:
docker rmi localhost/archiver
dump:
mkdir -p dumps
cd dumps && bash ../dump.sh
.PHONY: image clean

18
dump.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/bash
set -e -o pipefail
info() {
[ "$#" -gt 0 ] && echo -e "\033[1m>>> $*\033[0m" >&2
}
readarray -t volumes < <(docker volume ls --format "{{ .Name }}")
for v in "${volumes[@]}"; do
info "Dumping \"$v\""
docker run --rm -v "$v":/vol:ro localhost/archiver sh -c \
"bsdtar -C /vol --numeric-owner -c . | zstdmt -15v" \
> "$v".tar.zst
docker volume inspect "$v" > "$v".json
done

26
restore.sh Normal file
View File

@ -0,0 +1,26 @@
#!/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