Add ssh-docker test, fix filename escaping when using ssh.
This commit is contained in:
parent
0e6fbcc6f1
commit
f07741a8d5
7 changed files with 77 additions and 15 deletions
22
tarback.sh
22
tarback.sh
|
@ -64,6 +64,24 @@ _transform_remote() {
|
||||||
echo "$r"
|
echo "$r"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_transform_argument_ssh() {
|
||||||
|
command_name="$(echo "$TARBACK_REMOTE" | awk '{print $1}')"
|
||||||
|
if echo "$command_name" | grep -q 'ssh'; then
|
||||||
|
echo "'$(printf '%s' "$1" | sed "s/'/'\\\\''/g")'"
|
||||||
|
else
|
||||||
|
echo "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_transform_argument() {
|
||||||
|
a="$1"
|
||||||
|
for t in _transform_argument_ssh; do
|
||||||
|
[ -z "$t" ] && continue # skip empty transformers
|
||||||
|
a="$("$t" "$a")"
|
||||||
|
done
|
||||||
|
echo "$a"
|
||||||
|
}
|
||||||
|
|
||||||
_create() {
|
_create() {
|
||||||
# $1 ... src
|
# $1 ... src
|
||||||
# $2 ... dst
|
# $2 ... dst
|
||||||
|
@ -75,7 +93,7 @@ _create() {
|
||||||
tarback_tar_create_command="$TARBACK_TAR_CREATE_COMMAND_FILE"
|
tarback_tar_create_command="$TARBACK_TAR_CREATE_COMMAND_FILE"
|
||||||
fi
|
fi
|
||||||
tarback_tar_create_command="$(_transform_remote "$tarback_tar_create_command")"
|
tarback_tar_create_command="$(_transform_remote "$tarback_tar_create_command")"
|
||||||
$TARBACK_REMOTE sh -c "$tarback_tar_create_command" - "$src" \
|
$TARBACK_REMOTE sh -c "$tarback_tar_create_command" - "$(_transform_argument_ssh "$src")" \
|
||||||
| $TARBACK_COMPRESSION \
|
| $TARBACK_COMPRESSION \
|
||||||
| $TARBACK_SPLIT "$dst"
|
| $TARBACK_SPLIT "$dst"
|
||||||
}
|
}
|
||||||
|
@ -95,7 +113,7 @@ _restore() {
|
||||||
tarback_tar_extract_command="$(_transform_remote "$tarback_tar_extract_command")"
|
tarback_tar_extract_command="$(_transform_remote "$tarback_tar_extract_command")"
|
||||||
$TARBACK_MERGE "$src"* \
|
$TARBACK_MERGE "$src"* \
|
||||||
| $TARBACK_COMPRESSION --decompress --stdout \
|
| $TARBACK_COMPRESSION --decompress --stdout \
|
||||||
| $TARBACK_REMOTE sh -c "$tarback_tar_extract_command" - "$dst"
|
| $TARBACK_REMOTE sh -c "$tarback_tar_extract_command" - "$(_transform_argument_ssh "$dst")"
|
||||||
}
|
}
|
||||||
|
|
||||||
restore() {
|
restore() {
|
||||||
|
|
4
test.sh
4
test.sh
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
early_return="${TARBACK_TEST_EARLY_RETURN:-false}"
|
||||||
failed=0
|
failed=0
|
||||||
for f in ./tests/test-*.sh; do
|
for f in ./tests/test-*.sh; do
|
||||||
printf '%s' "Running test $f ... "
|
printf '%s' "Running test $f ... "
|
||||||
|
@ -10,6 +11,9 @@ for f in ./tests/test-*.sh; do
|
||||||
else
|
else
|
||||||
failed=$((failed+1))
|
failed=$((failed+1))
|
||||||
echo "failed"
|
echo "failed"
|
||||||
|
if "$early_return"; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@ create_directories() {
|
||||||
mkdir -p "$workdir/source"
|
mkdir -p "$workdir/source"
|
||||||
mkdir -p "$workdir/dest"
|
mkdir -p "$workdir/dest"
|
||||||
mkdir -p "$workdir/restore"
|
mkdir -p "$workdir/restore"
|
||||||
echo 'Hello World!' > "$workdir/source/hello_world.txt"
|
# 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)
|
||||||
|
echo 'Hello World!' > "$workdir/source/$(for i in $(seq 0 255); do printf '%x' "$i" | xxd -r -p; done | tr -d '/')"
|
||||||
echo "$workdir"
|
echo "$workdir"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,17 @@ rm -rf "$workdir"
|
||||||
|
|
||||||
# archive single file
|
# archive single file
|
||||||
workdir="$(create_directories)"
|
workdir="$(create_directories)"
|
||||||
./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
./tarback.sh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
diff "$workdir/source" "$workdir/restore"
|
diff "$workdir/source" "$workdir/restore"
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
|
|
||||||
# split archive
|
# split archive
|
||||||
workdir="$(create_directories)"
|
workdir="$(create_directories)"
|
||||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
diff "$workdir/source" "$workdir/restore"
|
diff "$workdir/source" "$workdir/restore"
|
||||||
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
|
|
|
@ -15,15 +15,17 @@ rm -rf "$workdir"
|
||||||
|
|
||||||
# archive single file
|
# archive single file
|
||||||
workdir="$(create_directories)"
|
workdir="$(create_directories)"
|
||||||
./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
./tarback.sh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
diff "$workdir/source" "$workdir/restore"
|
diff "$workdir/source" "$workdir/restore"
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
|
|
||||||
# split archive
|
# split archive
|
||||||
workdir="$(create_directories)"
|
workdir="$(create_directories)"
|
||||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
diff "$workdir/source" "$workdir/restore"
|
diff "$workdir/source" "$workdir/restore"
|
||||||
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
|
|
|
@ -13,15 +13,17 @@ rm -rf "$workdir"
|
||||||
|
|
||||||
# archive single file
|
# archive single file
|
||||||
workdir="$(create_directories)"
|
workdir="$(create_directories)"
|
||||||
./tarback.sh -p docker create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
./tarback.sh -p docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
diff "$workdir/source" "$workdir/restore"
|
diff "$workdir/source" "$workdir/restore"
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
|
|
||||||
# split archive
|
# split archive
|
||||||
workdir="$(create_directories)"
|
workdir="$(create_directories)"
|
||||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
diff "$workdir/source" "$workdir/restore"
|
diff "$workdir/source" "$workdir/restore"
|
||||||
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
|
|
31
tests/test-003-ssh-docker.sh
Executable file
31
tests/test-003-ssh-docker.sh
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
. ./tests/common.sh
|
||||||
|
|
||||||
|
export TARBACK_REMOTE='ssh localhost'
|
||||||
|
|
||||||
|
# archive whole directory
|
||||||
|
workdir="$(create_directories)"
|
||||||
|
./tarback.sh -p docker create "$workdir/source" "$workdir/dest/source.tar.xz"
|
||||||
|
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore"
|
||||||
|
diff "$workdir/source" "$workdir/restore"
|
||||||
|
rm -rf "$workdir"
|
||||||
|
|
||||||
|
# archive single file
|
||||||
|
workdir="$(create_directories)"
|
||||||
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
|
./tarback.sh -p docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
|
diff "$workdir/source" "$workdir/restore"
|
||||||
|
rm -rf "$workdir"
|
||||||
|
|
||||||
|
# split archive
|
||||||
|
workdir="$(create_directories)"
|
||||||
|
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||||
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||||
|
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||||
|
diff "$workdir/source" "$workdir/restore"
|
||||||
|
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
||||||
|
rm -rf "$workdir"
|
Loading…
Reference in a new issue