Compare commits
No commits in common. "f07741a8d5a820c39b8d3349b6e84c8fd3b67b59" and "482da4b8338daeb1e209fa7a0a12fe73502f5cd9" have entirely different histories.
f07741a8d5
...
482da4b833
8 changed files with 9 additions and 128 deletions
22
tarback.sh
22
tarback.sh
|
@ -64,24 +64,6 @@ _transform_remote() {
|
|||
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() {
|
||||
# $1 ... src
|
||||
# $2 ... dst
|
||||
|
@ -93,7 +75,7 @@ _create() {
|
|||
tarback_tar_create_command="$TARBACK_TAR_CREATE_COMMAND_FILE"
|
||||
fi
|
||||
tarback_tar_create_command="$(_transform_remote "$tarback_tar_create_command")"
|
||||
$TARBACK_REMOTE sh -c "$tarback_tar_create_command" - "$(_transform_argument_ssh "$src")" \
|
||||
$TARBACK_REMOTE sh -c "$tarback_tar_create_command" - "$src" \
|
||||
| $TARBACK_COMPRESSION \
|
||||
| $TARBACK_SPLIT "$dst"
|
||||
}
|
||||
|
@ -113,7 +95,7 @@ _restore() {
|
|||
tarback_tar_extract_command="$(_transform_remote "$tarback_tar_extract_command")"
|
||||
$TARBACK_MERGE "$src"* \
|
||||
| $TARBACK_COMPRESSION --decompress --stdout \
|
||||
| $TARBACK_REMOTE sh -c "$tarback_tar_extract_command" - "$(_transform_argument_ssh "$dst")"
|
||||
| $TARBACK_REMOTE sh -c "$tarback_tar_extract_command" - "$dst"
|
||||
}
|
||||
|
||||
restore() {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
_tarback_plugin_docker_cmd='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine '
|
||||
TARBACK_TAR_CREATE_COMMAND="$_tarback_plugin_docker_cmd "'tar c -C "/mnt/$1" .'
|
||||
TARBACK_TAR_EXTRACT_COMMAND="$_tarback_plugin_docker_cmd "'tar x -C "/mnt/$1"'
|
||||
TARBACK_TAR_CREATE_COMMAND='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine '"$TARBACK_TAR_CREATE_COMMAND"
|
||||
TARBACK_TAR_EXTRACT_COMMAND='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine '"$TARBACK_TAR_EXTRACT_COMMAND"
|
||||
|
|
4
test.sh
4
test.sh
|
@ -2,7 +2,6 @@
|
|||
|
||||
set -eu
|
||||
|
||||
early_return="${TARBACK_TEST_EARLY_RETURN:-false}"
|
||||
failed=0
|
||||
for f in ./tests/test-*.sh; do
|
||||
printf '%s' "Running test $f ... "
|
||||
|
@ -11,9 +10,6 @@ for f in ./tests/test-*.sh; do
|
|||
else
|
||||
failed=$((failed+1))
|
||||
echo "failed"
|
||||
if "$early_return"; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
|
@ -5,9 +5,6 @@ create_directories() {
|
|||
mkdir -p "$workdir/source"
|
||||
mkdir -p "$workdir/dest"
|
||||
mkdir -p "$workdir/restore"
|
||||
# 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 'Hello World!' > "$workdir/source/hello_world.txt"
|
||||
echo "$workdir"
|
||||
}
|
||||
|
|
|
@ -13,17 +13,15 @@ rm -rf "$workdir"
|
|||
|
||||
# archive single file
|
||||
workdir="$(create_directories)"
|
||||
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||
./tarback.sh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||
./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||
./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
||||
./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
||||
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 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"
|
||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz"
|
||||
TARBACK_SPLIT="split -b 10 -" ./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt"
|
||||
diff "$workdir/source" "$workdir/restore"
|
||||
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
||||
rm -rf "$workdir"
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
. ./tests/common.sh
|
||||
|
||||
export TARBACK_REMOTE='ssh localhost'
|
||||
|
||||
# archive whole directory
|
||||
workdir="$(create_directories)"
|
||||
./tarback.sh create "$workdir/source" "$workdir/dest/source.tar.xz"
|
||||
./tarback.sh 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 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"
|
||||
rm -rf "$workdir"
|
||||
|
||||
# split archive
|
||||
workdir="$(create_directories)"
|
||||
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||
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"
|
||||
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
|
||||
rm -rf "$workdir"
|
|
@ -1,29 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
. ./tests/common.sh
|
||||
|
||||
# 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"
|
|
@ -1,31 +0,0 @@
|
|||
#!/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