#!/bin/bash echo "running root command" inspect_args # module_load ssh module_load confirm module_load path local settings=${args[--settings]} if [[ -f $settings ]]; then echo loading settings file $settings module_load yaml eval $(parse_yaml $settings "s_") echo $s_source echo $s_target echo $s_host fi if [[ $s_server_host ]]; then s_server="http$([[ $s_server_secure ]] && echo "s")://${s_server_host}$([[ $s_server_port ]] && echo :${s_server_port} || echo "")" fi local password=${args[--password]:-$BACKUP_PASSWORD} password=${password:-$s_password} [[ ! $password ]] && echo restic requires a backup repository password, exiting && return 2 password="RESTIC_PASSWORD=${password}" local server=${args[--server]:-$BACKUP_SERVER} server=${server:-$s_server} echo server $s_server echo server $server local backup_dir=${args[--backup_dir]:-$BACKUP_DIR} backup_dir=${backup_dir:-$s_backup_dir} backup_dir=${backup_dir:-"/backup"} local source="${args[source]:-$s_source}" source=$(echo "${source:-$PWD}" | tr -s /) local target=${args[target]:-$s_target} target="$(echo $target | tr -s /)" if [[ ${args[--dir]:-$s_dir} ]]; then target="${target}$(echo $source | tr -s / | sed -e "s#^[.]##")" fi if [[ $(isAbsPath $target) ]]; then echo absolute target directory else target="/${s_host:-$HOSTNAME}/${target}" if [[ $server ]]; then target="rest:${server}${target}" else target=${backup_dir}${target} fi fi local exclude=${args[--exclude_file]:-$BACKUP_EXCLUDE} 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 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\"" #cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target" local sudo="" local pcmd="${sudo} ${password} ${bin} -r ${target}" local cmd="${pcmd} backup ${source} ${exclude}" if [[ ${args[--init]} ]]; then cmd="${pcmd} init"; fi if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; fi if [[ ${args[--view]} || ${args[--view-path]} ]]; then mount=${args[--view-path]:-$BACKUP_MOUNT} mount=${mount:-"/opt/backup/view/"} echo view mount point $mount if [[ -e ${mount} ]]; then cmd="${pcmd} mount $mount"; echo browse files at $mount/snapshots/latest${source} else echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again return 3 fi fi echo $cmd confirm run this command? || return 1 eval $cmd # sudo chown -R $USER:$USER $target # sudo chown -R $USER:$USER /home/$USER/.cache/restic # sudo chmod -R g+rwX /home/$USER/.cache/restic