2023-06-07 13:21:53 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
create_directories() {
|
|
|
|
workdir="$(mktemp -d)"
|
|
|
|
mkdir -p "$workdir/source"
|
|
|
|
mkdir -p "$workdir/dest"
|
|
|
|
mkdir -p "$workdir/restore"
|
2023-06-07 23:54:52 +02:00
|
|
|
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
filename_len=$1
|
|
|
|
else
|
|
|
|
filename_len=255
|
|
|
|
fi
|
2023-06-07 21:53:14 +02:00
|
|
|
# generate a filename with every possible byte in it to test
|
|
|
|
# escaping, the only character not included is `/` since that is
|
|
|
|
# illegal for filenames (obviously)
|
2023-06-07 23:54:52 +02:00
|
|
|
echo 'Hello World!' > "$workdir/source/$(for i in $(seq 0 $filename_len); do printf '%x' "$i" | xxd -r -p; done | tr -d '/')"
|
2023-06-07 13:21:53 +02:00
|
|
|
echo "$workdir"
|
|
|
|
}
|
2023-06-07 23:54:52 +02:00
|
|
|
|
|
|
|
create_docker_volume() {
|
|
|
|
volumename="tarback-docker-volume-test-$(shuf -i 1000-9999 -n 1)"
|
|
|
|
# use shorter name because alpine runs into a filename length limit
|
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
workdir="$1"
|
|
|
|
filename="$2"
|
|
|
|
docker run --rm -i -v "$volumename:/mnt" alpine tee "/mnt/$filename" < "$workdir/source/$filename" 1>/dev/null
|
|
|
|
fi
|
|
|
|
echo "$volumename"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_docker_volume() {
|
|
|
|
volumename="$1"
|
|
|
|
workdir="$2"
|
|
|
|
filename="$3"
|
|
|
|
#docker run --rm -v "$volumename:/mnt" alpine find /
|
|
|
|
docker run --rm -v "$volumename:/mnt" alpine cat "/mnt/$filename" > "$workdir/restore/$filename"
|
|
|
|
}
|