2019-12-14 23:03:12 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -ue
|
2019-12-14 16:51:01 +01:00
|
|
|
|
2019-12-14 23:15:20 +01:00
|
|
|
CYAN='\033[01;36m'
|
|
|
|
NC='\033[00m'
|
|
|
|
|
2019-12-16 08:30:36 +01:00
|
|
|
if [ ! -t 1 ]; then
|
2019-12-14 23:15:20 +01:00
|
|
|
CYAN=''
|
|
|
|
NC=''
|
|
|
|
fi
|
|
|
|
|
|
|
|
SCRIPT=$(readlink -f $0)
|
|
|
|
DIRNAME=$(dirname $SCRIPT)
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Import all account and GPG variables.
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-12-14 16:51:01 +01:00
|
|
|
source ./b2.cred
|
2019-12-14 23:03:12 +01:00
|
|
|
export PASSPHRASE=${GPG_PASSPHRASE}
|
2019-12-14 16:51:01 +01:00
|
|
|
|
2019-12-14 23:15:20 +01:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Local directory to backup.
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-12-14 16:51:01 +01:00
|
|
|
LOCAL_DIR="/media/usb0/backup"
|
|
|
|
|
2019-12-14 23:15:20 +01:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Remove files older than 30 days.
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
echo -e "${CYAN}[${SCRIPT}] Remove files older than 30 days ${NC}"
|
|
|
|
|
2019-12-14 23:04:28 +01:00
|
|
|
duplicity remove-older-than 30D --force \
|
|
|
|
--encrypt-sign-key $GPG_KEY \
|
|
|
|
b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET}
|
|
|
|
|
2019-12-14 23:15:20 +01:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Perform a full backup.
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
echo -e "${CYAN}[${SCRIPT}] Perform a full backup ${NC}"
|
|
|
|
|
2019-12-14 16:51:01 +01:00
|
|
|
duplicity full \
|
|
|
|
--encrypt-sign-key $GPG_KEY \
|
|
|
|
${LOCAL_DIR} b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET}
|
|
|
|
|
2019-12-14 23:15:20 +01:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Clean up failures.
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
echo -e "${CYAN}[${SCRIPT}] Clean up failures ${NC}"
|
|
|
|
|
2019-12-14 16:51:01 +01:00
|
|
|
duplicity cleanup --force \
|
|
|
|
--encrypt-sign-key $GPG_KEY \
|
|
|
|
b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET}
|
|
|
|
|
2019-12-14 23:15:20 +01:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Show collection status.
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
echo -e "${CYAN}[${SCRIPT}] Show collection status ${NC}"
|
|
|
|
|
2019-12-14 16:51:01 +01:00
|
|
|
duplicity collection-status \
|
|
|
|
--encrypt-sign-key $GPG_KEY \
|
|
|
|
b2://${B2_ACCOUNT}:${B2_KEY}@${B2_BUCKET}
|
2019-12-14 23:03:12 +01:00
|
|
|
|
2019-12-14 23:15:20 +01:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Unset the GPG passphrase.
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-12-14 23:03:12 +01:00
|
|
|
unset PASSPHRASE
|