From 1123c1bd8ca2f81b1ecdb353eab27ba0a2f4425f Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 14 Dec 2019 23:15:20 +0100 Subject: [PATCH] Nicer script formatting --- b2-backup.sh | 51 ++++++++++++++++++++++++++++++++++++++------- backup.sh | 8 +++++++ registry-cleaner.sh | 5 +++++ 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/b2-backup.sh b/b2-backup.sh index 099ae23..c60c648 100755 --- a/b2-backup.sh +++ b/b2-backup.sh @@ -2,32 +2,69 @@ set -ue -# Import all account and GPG variables +CYAN='\033[01;36m' +NC='\033[00m' + +if [ -t 1 ]; then + CYAN='' + NC='' +fi + +SCRIPT=$(readlink -f $0) +DIRNAME=$(dirname $SCRIPT) + +# ----------------------------------------------------------------------------- +# Import all account and GPG variables. +# ----------------------------------------------------------------------------- source ./b2.cred export PASSPHRASE=${GPG_PASSPHRASE} -# Local directory to backup +# ----------------------------------------------------------------------------- +# Local directory to backup. +# ----------------------------------------------------------------------------- LOCAL_DIR="/media/usb0/backup" -# Remove files older than 30 days +# ----------------------------------------------------------------------------- +# Remove files older than 30 days. +# ----------------------------------------------------------------------------- + +echo -e "${CYAN}[${SCRIPT}] Remove files older than 30 days ${NC}" + duplicity remove-older-than 30D --force \ --encrypt-sign-key $GPG_KEY \ b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET} -# Perform a full backup +# ----------------------------------------------------------------------------- +# Perform a full backup. +# ----------------------------------------------------------------------------- + +echo -e "${CYAN}[${SCRIPT}] Perform a full backup ${NC}" + duplicity full \ --encrypt-sign-key $GPG_KEY \ ${LOCAL_DIR} b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET} -# Cleanup failures +# ----------------------------------------------------------------------------- +# Clean up failures. +# ----------------------------------------------------------------------------- + +echo -e "${CYAN}[${SCRIPT}] Clean up failures ${NC}" + duplicity cleanup --force \ --encrypt-sign-key $GPG_KEY \ b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET} -# Show collection-status +# ----------------------------------------------------------------------------- +# Show collection status. +# ----------------------------------------------------------------------------- + +echo -e "${CYAN}[${SCRIPT}] Show collection status ${NC}" + duplicity collection-status \ --encrypt-sign-key $GPG_KEY \ b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET} -# Unset the GPG passphrase +# ----------------------------------------------------------------------------- +# Unset the GPG passphrase. +# ----------------------------------------------------------------------------- unset PASSPHRASE diff --git a/backup.sh b/backup.sh index 8a6c712..44988ff 100755 --- a/backup.sh +++ b/backup.sh @@ -8,6 +8,14 @@ YELLOW='\033[01;33m' CYAN='\033[01;36m' NC='\033[00m' +if [ -t 1 ]; then + RED='' + GREEN='' + YELLOW='' + CYAN='' + NC='' +fi + SCRIPT=$(readlink -f $0) DIRNAME=$(dirname $SCRIPT) diff --git a/registry-cleaner.sh b/registry-cleaner.sh index 5d533c9..c9f70f7 100755 --- a/registry-cleaner.sh +++ b/registry-cleaner.sh @@ -5,6 +5,11 @@ set -e CYAN='\033[01;36m' NC='\033[00m' +if [ -t 1 ]; then + CYAN='' + NC='' +fi + SCRIPT=$(readlink -f $0) DIRNAME=$(dirname $SCRIPT)