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