diff --git a/backup.sh b/backup.sh index 14871fa5d8ae6078ba471344a85a5c9fd627162a..74337089d66e9a49dbdd7f6ec6aca2c0d7fd84bd 100755 --- a/backup.sh +++ b/backup.sh @@ -6,6 +6,7 @@ if [ ! -z "$1" ]; then shift fi source $DIR/inc.sh +exec &> >(tee -a "$log_file") exit_on_fail(){ [ $1 -ne 0 ] && leave $@ @@ -37,8 +38,8 @@ backup(){ echo "Creating encrypted incremental backup: $bckplist " run_duplicity --full-if-older-than $BK_FULL_FREQ \ --include ${bckplist// / --include } \ - --exclude /root/.cache/duplicity/ - --exclude '**' + --exclude /root/.cache/duplicity/ \ + / ret=$? if [ -z "$retries" ] then diff --git a/inc.sh b/inc.sh index 4515dfda7994dcde5446b60817a86999771c7c16..2ad0412dd65a8bd4e415b6c3ddc0aa1981ecbddb 100755 --- a/inc.sh +++ b/inc.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [ `whoami` != "root" ]; then + echo "this script must be run as root" + exit 1 +fi + DIR=$(realpath $(dirname $0)) if [ -z "$conf_file" ]; then conf_file="$DIR/.env" @@ -10,10 +15,12 @@ if [ -z "$log_file" ]; then log_file=/var/log/bckp.log fi -exec &> >(tee -a "$logfile") if [ -z "$verbosity" ]; then verbosity="notice" +fi + +remote="ftp://$user@$host/$remotedir/" # Exit the script and sendmail # $1 : exit code @@ -44,16 +51,16 @@ EOF run_duplicity(){ export PASSPHRASE="$encpass" export FTP_PASSWORD="$ftppass" - #set -x - /usr/bin/duplicity --archive-dir /root/.cache/duplicity/$archive_dir --verbosity $verbosity \ + set -x + /usr/bin/duplicity --verbosity $verbosity \ $@ \ $remote - #set +x + set +x unset PASSPHRASE unset FTP_PASSWORD } -cleanup() { +cleanup(){ echo "Cleaning" run_duplicity cleanup --force } @@ -65,13 +72,7 @@ delete_old_backups(){ collection_state } -collection_state() { - echo "Backups state" - run_duplicity collection-status +collection_state(){ + echo "Backups state" + run_duplicity collection-status } - -if [ `whoami` != "root" ] -then - echo "this script must be run as root" - exit 1 -fi diff --git a/restore_file.sh b/restore_file.sh index 5fdf8aee8a04b2562d939450dfd4935f7bdae887..b38f893c1d5ef087107692e3feefe198fb01a807 100755 --- a/restore_file.sh +++ b/restore_file.sh @@ -36,7 +36,7 @@ source $DIR/inc.sh export PASSPHRASE="$encpass" export FTP_PASSWORD="$ftppass" -/usr/bin/duplicity --archive-dir $archive_dir --verbosity $verbosity --file-to-restore $delay "$restore_path" ftp://$user@$host/$remotedir/ "$destination_path" +/usr/bin/duplicity --verbosity $verbosity --file-to-restore $delay "$restore_path" $remote "$destination_path" unset PASSPHRASE unset FTP_PASSWORD