From 358ee631878a8bfc5bee0bbee033340c7571f25a Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Fri, 4 Jun 2021 10:55:45 +0200 Subject: [PATCH] fixup --- backup.sh | 5 +++-- inc.sh | 29 +++++++++++++++-------------- restore_file.sh | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/backup.sh b/backup.sh index 14871fa..7433708 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 4515dfd..2ad0412 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 5fdf8ae..b38f893 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 -- GitLab