diff --git a/backup.sh b/backup.sh index 3c0ca15d569bfce061311dcba65c7d3b74a2434e..2054bf541d713edf4d5641d0bd57c1d3c485e464 100755 --- a/backup.sh +++ b/backup.sh @@ -1,6 +1,10 @@ #!/bin/bash DIR=$(realpath $(dirname $0)) +if [ ! -z "$1" ]; then + conf_file=$1 + shift +fi source $DIR/inc.sh exit_on_fail(){ diff --git a/clear_backup.sh b/clear_backup.sh index 8cb9b41592a2e01e51319c96366a1b1278094665..1204b5480f26e123412948b43d5926d2f0326542 100755 --- a/clear_backup.sh +++ b/clear_backup.sh @@ -1,6 +1,10 @@ #!/bin/bash DIR=$(realpath $(dirname $0)) +if [ ! -z "$1" ]; then + conf_file=$1 + shift +fi source $DIR/inc.sh export PASSPHRASE="$encpass" diff --git a/inc.sh b/inc.sh index c1d568aae5da914fe8660dedfb3a015284563dfa..d0ff899d4d98319527a207b1b778dd2c80995641 100755 --- a/inc.sh +++ b/inc.sh @@ -1,7 +1,10 @@ #!/bin/bash DIR=$(realpath $(dirname $0)) -source $DIR/.env +if [ -z "$conf_file" ]; then + conf_file="$DIR/.env" +fi +source $conf_file # Exit the script and sendmail # $1 : exit code diff --git a/restore_file.sh b/restore_file.sh index d6353276e603431bf8b40290333150e945b33691..8b7e9aafd326d18561bc9ce04899e4cd4abec9cb 100755 --- a/restore_file.sh +++ b/restore_file.sh @@ -1,23 +1,42 @@ #!/bin/bash DIR=$(realpath $(dirname $0)) -source $DIR/inc.sh - -if [ -z "$2" ]; then - echo "Usage $0 <restore_path> <destination_path> [timeago]" +usage(){ + echo "Usage $0 [options] <restore_path> <destination_path>" echo "restore_path : path to restore without leading slash" echo "destination_path : path to download the file(s), duplicity will not override existing files" - echo "timeago : optionnal : the age of the version we want to restore, for instance 6D for 6 days ago" + echo "options" + echo " -t timeago : the age of the version we want to restore, for instance 6D for 6 days ago" + echo " -c file : config_file to use" +} + +while getopts "t:c:h" arg; do + case ${arg} in + h) + usage + exit 0 + ;; + t) + delay="-t $OPTARG" + ;; + c) + conf_file=$OPTARG + ;; + esac +done +restore_path=${@:$OPTIND:1} +destination_path=${@:$OPTIND+1:1} + +if [ -z "$destination_path" ]; then + usage exit 1 fi -if [ ! -z "$3" ]; then - delay="-t $3" -fi +source $DIR/inc.sh export PASSPHRASE="$encpass" export FTP_PASSWORD="$ftppass" -/usr/bin/duplicity --file-to-restore $delay "$1" ftp://$user@$host/$remotedir/ "$2" +/usr/bin/duplicity --file-to-restore $delay "$restore_path" ftp://$user@$host/$remotedir/ "$destination_path" unset PASSPHRASE unset FTP_PASSWORD