Add postgres plugin, do some cleanup.

This commit is contained in:
redxef 2023-06-08 17:49:26 +02:00
parent c6163da5e4
commit 9aa896f501
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
6 changed files with 60 additions and 24 deletions

View file

@ -53,14 +53,22 @@ _="${TARBACK_TAR_EXTRACT_USE_ALT_COMMAND:=$TARBACK_TAR_EXTRACT_USE_ALT_COMMAND_D
_="${TARBACK_COMPRESSION:=$TARBACK_COMPRESSION_DEFAULT}"
_="${TARBACK_SPLIT:=$TARBACK_SPLIT_DEFAULT}"
_="${TARBACK_MERGE:=$TARBACK_MERGE_DEFAULT}"
_="${TARBACK_EXTENSION:=tar.$TARBACK_COMPRESSION}"
_transform_split_name() {
case "$1" in
*"$TARBACK_EXTENSION")
n="$1"
;;
*)
n="$1.$TARBACK_EXTENSION"
;;
esac
command_name="$(echo "$TARBACK_SPLIT" | awk '{print $1}')"
if echo "$command_name" | grep -q 'split'; then
echo "$1.part"
else
echo "$1"
n="$n.part"
fi
echo "$n"
}
_transform_remote() {
@ -117,10 +125,10 @@ restore() {
_restore "$@"
}
short_options='p:'
short_options='P:'
while getopts "$short_options" arg; do
case "$arg" in
p)
P)
for p in $(echo "$OPTARG" | tr ',' ' '); do
# source plugin file(s)
sourced=false

32
tarback/postgres.sh Normal file
View file

@ -0,0 +1,32 @@
#!/bin/sh
_tarback_plugin_postgres_host=
_tarback_plugin_postgres_port=
_tarback_plugin_postgres_user=
short_options='h:p:U:'
while getopts "$short_options" arg; do
case "$arg" in
h)
_tarback_plugin_postgres_host="$OPTARG"
;;
p)
_tarback_plugin_postgres_port="$OPTARG"
;;
U)
_tarback_plugin_postgres_user="$OPTARG"
;;
esac
done
_tarback_plugin_postgres_command=
[ -n "$_tarback_plugin_postgres_host" ] && _tarback_plugin_postgres_command="$_tarback_plugin_postgres_command -h '$_tarback_plugin_postgres_host'"
[ -n "$_tarback_plugin_postgres_port" ] && _tarback_plugin_postgres_command="$_tarback_plugin_postgres_command -p '$_tarback_plugin_postgres_port'"
[ -n "$_tarback_plugin_postgres_user" ] && _tarback_plugin_postgres_command="$_tarback_plugin_postgres_command -U '$_tarback_plugin_postgres_user'"
_tarback_plugin_postgres_create_command="pg_dump $_tarback_plugin_postgres_command "'"$1"'
_tarback_plugin_postgres_extract_command="psql $_tarback_plugin_postgres_command"
TARBACK_TAR_CREATE_COMMAND="$_tarback_plugin_postgres_create_command"
TARBACK_TAR_EXTRACT_COMMAND="$_tarback_plugin_postgres_extract_command"
TARBACK_EXTENSION='xz'
TARBACK_TAR_CREATE_USE_ALT_COMMAND=false
TARBACK_TAR_EXTRACT_USE_ALT_COMMAND=false

View file

@ -18,16 +18,12 @@ _tarback_plugin_ssh_transform_ssh_argument() {
fi
}
short_options='p:s:'
short_options='s:'
while getopts "$short_options" arg; do
case "$arg" in
s)
TARBACK_REMOTE="$OPTARG"
;;
*)
echo "unknown option $1" >&2
#exit 1
;;
esac
done

View file

@ -8,24 +8,24 @@ export TARBACK_REMOTE='ssh localhost'
# archive whole directory
workdir="$(create_directories)"
./tarback.sh -p ssh create "$workdir/source" "$workdir/dest/source.tar.xz"
./tarback.sh -p ssh restore "$workdir/dest/source.tar.xz" "$workdir/restore"
./tarback.sh -P ssh create "$workdir/source" "$workdir/dest/source.tar.xz"
./tarback.sh -P ssh 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 ssh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
./tarback.sh -p ssh restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
./tarback.sh -P ssh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
./tarback.sh -P ssh 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 ssh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p ssh restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -P ssh create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -P ssh 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"

View file

@ -8,10 +8,10 @@ set -eu
workdir="$(create_directories 127)"
filename="$(basename "$(find "$workdir/source" -type f)")"
docker_volume="$(create_docker_volume "$workdir" "$filename")"
./tarback.sh -p docker create "$docker_volume" "$workdir/dest/source.tar.xz"
./tarback.sh -P docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
./tarback.sh -P docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
@ -20,10 +20,10 @@ rm -rf "$workdir"
workdir="$(create_directories 127)"
filename="$(basename "$(find "$workdir/source" -type f)")"
docker_volume="$(create_docker_volume "$workdir" "$filename")"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p docker create "$docker_volume" "$workdir/dest/source.tar.xz"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -P docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -P docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2

View file

@ -10,10 +10,10 @@ export TARBACK_REMOTE='ssh localhost'
workdir="$(create_directories 127)"
filename="$(basename "$(find "$workdir/source" -type f)")"
docker_volume="$(create_docker_volume "$workdir" "$filename")"
./tarback.sh -p ssh,docker create "$docker_volume" "$workdir/dest/source.tar.xz"
./tarback.sh -P ssh,docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
./tarback.sh -P ssh,docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
@ -22,10 +22,10 @@ rm -rf "$workdir"
workdir="$(create_directories 127)"
filename="$(basename "$(find "$workdir/source" -type f)")"
docker_volume="$(create_docker_volume "$workdir" "$filename")"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p ssh,docker create "$docker_volume" "$workdir/dest/source.tar.xz"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -P ssh,docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -P ssh,docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2