feat: add restic options, add jq pipe processing
parent
a04f0cb2d9
commit
2302bfb5a8
|
@ -43,9 +43,8 @@ root_command() {
|
||||||
hostname=${hostname:-$s_host}
|
hostname=${hostname:-$s_host}
|
||||||
hostname=${hostname:-$HOSTNAME}
|
hostname=${hostname:-$HOSTNAME}
|
||||||
|
|
||||||
local backup_dir=${args[--backup_dir]:-$BACKUP_DIR}
|
local options="${args[--options]:-$BACKUP_OPTIONS}"
|
||||||
backup_dir=${backup_dir:-$s_backup_dir}
|
options="${options:-$s_options}"
|
||||||
backup_dir=${backup_dir:-"/backup"}
|
|
||||||
|
|
||||||
local smount=${args[--source_mount]:-$BACKUP_SOURCE_MOUNT}
|
local smount=${args[--source_mount]:-$BACKUP_SOURCE_MOUNT}
|
||||||
smount=${smount:-$s_source_mount}
|
smount=${smount:-$s_source_mount}
|
||||||
|
@ -85,7 +84,7 @@ root_command() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $smount ]]; then
|
if [[ $smount ]]; then
|
||||||
setpath="--set-path ${source}"
|
setpath="--set-path ${source} --tag mount-point:${smount}"
|
||||||
source=${smount}${source}
|
source=${smount}${source}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -94,34 +93,24 @@ root_command() {
|
||||||
exclude=${exclude:-"$source/exclude.bac"}
|
exclude=${exclude:-"$source/exclude.bac"}
|
||||||
|
|
||||||
|
|
||||||
local shost=$([[ ${args[--shost]} ]] && echo ${args[--shost]}::)
|
# local shost=$([[ ${args[--shost]} ]] && echo ${args[--shost]}::)
|
||||||
local suser=$([[ ${args[--suser]} ]] && echo ${args[--suser]}@)
|
# local suser=$([[ ${args[--suser]} ]] && echo ${args[--suser]}@)
|
||||||
local thost=$([[ ${args[--host]} ]] && echo ${args[--host]}::)
|
# local thost=$([[ ${args[--host]} ]] && echo ${args[--host]}::)
|
||||||
local tuser=$([[ ${args[--user]} ]] && echo ${args[--user]}@)
|
# local tuser=$([[ ${args[--user]} ]] && echo ${args[--user]}@)
|
||||||
|
|
||||||
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
||||||
|
|
||||||
local bin=$(command -v restic)
|
local bin=$(command -v restic)
|
||||||
|
|
||||||
|
|
||||||
local cmd=${args[cmd]:-"backup"}
|
|
||||||
|
|
||||||
|
|
||||||
echo before exists exclude: $exclude
|
|
||||||
|
|
||||||
exclude=$([[ -f $exclude ]] && echo "--iexclude-file $exclude" || echo "")
|
exclude=$([[ -f $exclude ]] && echo "--iexclude-file $exclude" || echo "")
|
||||||
|
|
||||||
echo source: $source
|
echo source: $source
|
||||||
echo target $target
|
echo target $target
|
||||||
echo exclude: $exclude
|
echo exclude: $exclude
|
||||||
|
|
||||||
# local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\""
|
local sudo=$([[ ${args[--sudo]} || $s_sudo || $BACKUP_SUDO ]] && echo "sudo" || echo "")
|
||||||
|
|
||||||
#cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target"
|
local pcmd="${sudo} ${password} ${bin} ${options} -r ${target}"
|
||||||
|
|
||||||
|
|
||||||
local sudo=""
|
|
||||||
local pcmd="${sudo} ${password} ${bin} -r ${target}"
|
|
||||||
|
|
||||||
local cmd="${pcmd} -H ${hostname} ${setpath} backup ${source} ${exclude}"
|
local cmd="${pcmd} -H ${hostname} ${setpath} backup ${source} ${exclude}"
|
||||||
|
|
||||||
|
@ -141,6 +130,11 @@ root_command() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo jq argument ${args[--jq]}
|
||||||
|
if [[ ${args[--jq]} ]];then
|
||||||
|
cmd="${cmd} | jq ${args[--jq]}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo $cmd
|
echo $cmd
|
||||||
confirm run this command? || return 1
|
confirm run this command? || return 1
|
||||||
eval $cmd
|
eval $cmd
|
||||||
|
@ -167,14 +161,14 @@ dbackup_usage() {
|
||||||
|
|
||||||
printf "Usage:\n"
|
printf "Usage:\n"
|
||||||
printf " dbackup [SOURCE] [TARGET] [options]\n"
|
printf " dbackup [SOURCE] [TARGET] [options]\n"
|
||||||
printf " dbackup --help\n"
|
printf " dbackup --help | -h\n"
|
||||||
printf " dbackup --version\n"
|
printf " dbackup --version\n"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if [[ -n $long_usage ]]; then
|
if [[ -n $long_usage ]]; then
|
||||||
printf "Options:\n"
|
printf "Options:\n"
|
||||||
# :command.usage_fixed_flags
|
# :command.usage_fixed_flags
|
||||||
echo " --help"
|
echo " --help, -h"
|
||||||
printf " Show this help\n"
|
printf " Show this help\n"
|
||||||
echo
|
echo
|
||||||
echo " --version"
|
echo " --version"
|
||||||
|
@ -231,34 +225,9 @@ dbackup_usage() {
|
||||||
printf " path to settings file (yaml). Keys are same as long\n"
|
printf " path to settings file (yaml). Keys are same as long\n"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# :flag.usage
|
|
||||||
echo " --host, -h THOST"
|
|
||||||
printf " host on remote to target to receive backup\n"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# :flag.usage
|
|
||||||
echo " --shost SHOST"
|
|
||||||
printf " remote to host of source\n"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# :flag.usage
|
|
||||||
echo " --user, -u TUSER"
|
|
||||||
printf " user on remote host\n"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# :flag.usage
|
|
||||||
echo " --suser SUSER"
|
|
||||||
printf " remote user on source host\n"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# :flag.usage
|
|
||||||
echo " --sshcfg SSHCFG"
|
|
||||||
printf " path to sshcfg file\n"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# :flag.usage
|
# :flag.usage
|
||||||
echo " --options, -o OPTIONS"
|
echo " --options, -o OPTIONS"
|
||||||
printf " additional options (restic or rsync)\n"
|
printf " additional options to pass ot underlying command (restic), \"quote\"\n"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# :flag.usage
|
# :flag.usage
|
||||||
|
@ -272,8 +241,13 @@ dbackup_usage() {
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# :flag.usage
|
# :flag.usage
|
||||||
echo " --dir, -d"
|
echo " --sudo"
|
||||||
printf " append source directory path to target directory\n"
|
printf " run the backup as sudo\n"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# :flag.usage
|
||||||
|
echo " --jq JQ"
|
||||||
|
printf " pipe to jq command\n"
|
||||||
echo
|
echo
|
||||||
# :command.usage_args
|
# :command.usage_args
|
||||||
printf "Arguments:\n"
|
printf "Arguments:\n"
|
||||||
|
@ -365,7 +339,7 @@ parse_requirements() {
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--help )
|
--help | -h )
|
||||||
long_usage=yes
|
long_usage=yes
|
||||||
dbackup_usage
|
dbackup_usage
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -478,66 +452,6 @@ parse_requirements() {
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# :flag.case
|
|
||||||
--host | -h )
|
|
||||||
if [[ $2 ]]; then
|
|
||||||
args[--host]="$2"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
printf "%s\n" "--host requires an argument: --host, -h THOST"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
# :flag.case
|
|
||||||
--shost )
|
|
||||||
if [[ $2 ]]; then
|
|
||||||
args[--shost]="$2"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
printf "%s\n" "--shost requires an argument: --shost SHOST"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
# :flag.case
|
|
||||||
--user | -u )
|
|
||||||
if [[ $2 ]]; then
|
|
||||||
args[--user]="$2"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
printf "%s\n" "--user requires an argument: --user, -u TUSER"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
# :flag.case
|
|
||||||
--suser )
|
|
||||||
if [[ $2 ]]; then
|
|
||||||
args[--suser]="$2"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
printf "%s\n" "--suser requires an argument: --suser SUSER"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
# :flag.case
|
|
||||||
--sshcfg )
|
|
||||||
if [[ $2 ]]; then
|
|
||||||
args[--sshcfg]="$2"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
printf "%s\n" "--sshcfg requires an argument: --sshcfg SSHCFG"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
# :flag.case
|
# :flag.case
|
||||||
--options | -o )
|
--options | -o )
|
||||||
if [[ $2 ]]; then
|
if [[ $2 ]]; then
|
||||||
|
@ -575,11 +489,23 @@ parse_requirements() {
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# :flag.case
|
# :flag.case
|
||||||
--dir | -d )
|
--sudo )
|
||||||
args[--dir]=1
|
args[--sudo]=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
# :flag.case
|
||||||
|
--jq )
|
||||||
|
if [[ $2 ]]; then
|
||||||
|
args[--jq]="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
printf "%s\n" "--jq requires an argument: --jq JQ"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
-* )
|
-* )
|
||||||
printf "invalid option: %s\n" "$key"
|
printf "invalid option: %s\n" "$key"
|
||||||
|
|
|
@ -56,27 +56,10 @@ flags:
|
||||||
short: -s
|
short: -s
|
||||||
arg: syaml
|
arg: syaml
|
||||||
help: path to settings file (yaml). Keys are same as long
|
help: path to settings file (yaml). Keys are same as long
|
||||||
- long: --host
|
|
||||||
short: -h
|
|
||||||
arg: thost
|
|
||||||
help: host on remote to target to receive backup
|
|
||||||
- long: --shost
|
|
||||||
arg: shost
|
|
||||||
help: remote to host of source
|
|
||||||
- long: --user
|
|
||||||
short: -u
|
|
||||||
arg: tuser
|
|
||||||
help: user on remote host
|
|
||||||
- long: --suser
|
|
||||||
arg: suser
|
|
||||||
help: remote user on source host
|
|
||||||
- long: --sshcfg
|
|
||||||
arg: sshcfg
|
|
||||||
help: path to sshcfg file
|
|
||||||
- long: --options
|
- long: --options
|
||||||
short: -o
|
short: -o
|
||||||
arg: options
|
arg: options
|
||||||
help: additional options (restic or rsync)
|
help: additional options to pass ot underlying command (restic), "quote"
|
||||||
- long: --include_file
|
- long: --include_file
|
||||||
short: -i
|
short: -i
|
||||||
arg: include
|
arg: include
|
||||||
|
@ -85,9 +68,29 @@ flags:
|
||||||
short: -e
|
short: -e
|
||||||
arg: exclude
|
arg: exclude
|
||||||
help: exclude file
|
help: exclude file
|
||||||
- long: --dir
|
- long: --sudo
|
||||||
short: -d
|
help: run the backup as sudo
|
||||||
help: append source directory path to target directory
|
- long: --jq
|
||||||
|
arg: jq
|
||||||
|
help: pipe to jq command
|
||||||
|
|
||||||
|
# - long: --host
|
||||||
|
# short: -h
|
||||||
|
# arg: thost
|
||||||
|
# help: host on remote to target to receive backup
|
||||||
|
# - long: --shost
|
||||||
|
# arg: shost
|
||||||
|
# help: remote to host of source
|
||||||
|
# - long: --user
|
||||||
|
# short: -u
|
||||||
|
# arg: tuser
|
||||||
|
# help: user on remote host
|
||||||
|
# - long: --suser
|
||||||
|
# arg: suser
|
||||||
|
# help: remote user on source host
|
||||||
|
# - long: --sshcfg
|
||||||
|
# arg: sshcfg
|
||||||
|
# help: path to sshcfg file
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
- backup -p password . /target/dir
|
- backup -p password . /target/dir
|
||||||
|
|
|
@ -36,9 +36,8 @@ local hostname=${args[--hostname]:-$s_hostname}
|
||||||
hostname=${hostname:-$s_host}
|
hostname=${hostname:-$s_host}
|
||||||
hostname=${hostname:-$HOSTNAME}
|
hostname=${hostname:-$HOSTNAME}
|
||||||
|
|
||||||
local backup_dir=${args[--backup_dir]:-$BACKUP_DIR}
|
local options="${args[--options]:-$BACKUP_OPTIONS}"
|
||||||
backup_dir=${backup_dir:-$s_backup_dir}
|
options="${options:-$s_options}"
|
||||||
backup_dir=${backup_dir:-"/backup"}
|
|
||||||
|
|
||||||
local smount=${args[--source_mount]:-$BACKUP_SOURCE_MOUNT}
|
local smount=${args[--source_mount]:-$BACKUP_SOURCE_MOUNT}
|
||||||
smount=${smount:-$s_source_mount}
|
smount=${smount:-$s_source_mount}
|
||||||
|
@ -78,7 +77,7 @@ if [[ $server ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $smount ]]; then
|
if [[ $smount ]]; then
|
||||||
setpath="--set-path ${source}"
|
setpath="--set-path ${source} --tag mount-point:${smount}"
|
||||||
source=${smount}${source}
|
source=${smount}${source}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -87,33 +86,24 @@ exclude=${exclude:-$s_exclude}
|
||||||
exclude=${exclude:-"$source/exclude.bac"}
|
exclude=${exclude:-"$source/exclude.bac"}
|
||||||
|
|
||||||
|
|
||||||
local shost=$([[ ${args[--shost]} ]] && echo ${args[--shost]}::)
|
# local shost=$([[ ${args[--shost]} ]] && echo ${args[--shost]}::)
|
||||||
local suser=$([[ ${args[--suser]} ]] && echo ${args[--suser]}@)
|
# local suser=$([[ ${args[--suser]} ]] && echo ${args[--suser]}@)
|
||||||
local thost=$([[ ${args[--host]} ]] && echo ${args[--host]}::)
|
# local thost=$([[ ${args[--host]} ]] && echo ${args[--host]}::)
|
||||||
local tuser=$([[ ${args[--user]} ]] && echo ${args[--user]}@)
|
# local tuser=$([[ ${args[--user]} ]] && echo ${args[--user]}@)
|
||||||
|
|
||||||
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
||||||
|
|
||||||
local bin=$(command -v restic)
|
local bin=$(command -v restic)
|
||||||
|
|
||||||
|
|
||||||
local cmd=${args[cmd]:-"backup"}
|
|
||||||
|
|
||||||
|
|
||||||
echo before exists exclude: $exclude
|
|
||||||
|
|
||||||
exclude=$([[ -f $exclude ]] && echo "--iexclude-file $exclude" || echo "")
|
exclude=$([[ -f $exclude ]] && echo "--iexclude-file $exclude" || echo "")
|
||||||
|
|
||||||
echo source: $source
|
echo source: $source
|
||||||
echo target $target
|
echo target $target
|
||||||
echo exclude: $exclude
|
echo exclude: $exclude
|
||||||
|
|
||||||
# local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\""
|
local sudo=$([[ ${args[--sudo]} || $s_sudo || $BACKUP_SUDO ]] && echo "sudo" || echo "")
|
||||||
|
|
||||||
#cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target"
|
local pcmd="${sudo} ${password} ${bin} ${options} -r ${target}"
|
||||||
|
|
||||||
local sudo=""
|
|
||||||
local pcmd="${sudo} ${password} ${bin} -r ${target}"
|
|
||||||
|
|
||||||
local cmd="${pcmd} -H ${hostname} ${setpath} backup ${source} ${exclude}"
|
local cmd="${pcmd} -H ${hostname} ${setpath} backup ${source} ${exclude}"
|
||||||
|
|
||||||
|
@ -133,6 +123,11 @@ if [[ ${args[--view]} || ${args[--view-path]} ]]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo jq argument ${args[--jq]}
|
||||||
|
if [[ ${args[--jq]} ]];then
|
||||||
|
cmd="${cmd} | jq ${args[--jq]}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo $cmd
|
echo $cmd
|
||||||
confirm run this command? || return 1
|
confirm run this command? || return 1
|
||||||
eval $cmd
|
eval $cmd
|
||||||
|
|
Reference in New Issue