New sequence for encrypted backups supporting profiles using duplicity

This commit is contained in:
2021-02-02 22:56:14 +01:00
parent 548c0bfc1c
commit 88af37f925
2 changed files with 75 additions and 28 deletions

View File

@@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
# How often the backup job should be run
# Default is to run every day at 02:01 am
# (see man 5 crontab for syntax help)
# m h dom mon dow
#EBU_CRONTIME='1 2 * * *'
# Passphrase for symmetrical(default) or asymmetrical encryption # Passphrase for symmetrical(default) or asymmetrical encryption
EBU_PASSPHRASE= EBU_PASSPHRASE=
@@ -22,6 +16,21 @@ EBU_TARGET=
# base directory to backup # base directory to backup
EBU_SOURCE= EBU_SOURCE=
# a command that runs duplicity e.g.
# shape bandwidth use via trickle
# "trickle -s -u 640 -d 5120" # 5Mb up, 40Mb down"
#EBU_PRECMD=""
# How often the backup job should be run
# Default is to run every day at 02:01 am
# (see man 5 crontab for syntax help)
# m h dom mon dow
#EBU_CRONTIME='1 2 * * *'
# Uncomment to save the output of the cron run to a logfile
# log file name will be "encBackup_profilename.log"
#EBU_LOG_DIR='/var/log'
# #
## Age options ## Age options

View File

@@ -1,9 +1,10 @@
#!/bin/bash #!/bin/bash
toolName=duplicity toolName=duplicity
toolBin=
toolPpa="ppa:duplicity-team/duplicity-release-git" toolPpa="ppa:duplicity-team/duplicity-release-git"
toolCronDir="/etc/cron.d" toolCronDir="/etc/cron.d"
toolCronPrefix="encBackup_" toolPrefix="encBackup_"
# Get script working directory # Get script working directory
# (when called from a different directory) # (when called from a different directory)
@@ -35,7 +36,6 @@ step_1_info() {
} }
step_1_alias() { ALIAS="backup"; } step_1_alias() { ALIAS="backup"; }
step_1() { step_1() {
checkInstalled
shift shift
local arg local arg
@@ -70,8 +70,9 @@ step_1() {
dupArgs+="--full-if-older-than=$EBU_MAX_FULLBKP_AGE " dupArgs+="--full-if-older-than=$EBU_MAX_FULLBKP_AGE "
fi fi
checkInstalled
setPassphrase setPassphrase
exe $toolName $dupCommand $dupArgs "$EBU_SOURCE" "$EBU_TARGET" exe $toolBin $dupCommand $dupArgs "$EBU_SOURCE" "$EBU_TARGET"
unsetPassphrase unsetPassphrase
if [ $purgeAfter -ne 0 ] ; then if [ $purgeAfter -ne 0 ] ; then
@@ -79,7 +80,7 @@ step_1() {
fi fi
} }
step_3_info() { echo "Restore [TARGET]"; } step_3_info() { echo "Restore <LOCAL TARGET> [TARGET]"; }
step_3_alias() { ALIAS="restore"; } step_3_alias() { ALIAS="restore"; }
step_3() { step_3() {
shift shift
@@ -87,10 +88,15 @@ step_3() {
echoerr " [E] No target provided" echoerr " [E] No target provided"
return -1 return -1
fi fi
local ebuTarget="$1" local ebuLocalTarget="$1"
local ebuTarget="$EBU_TARGET"
if [ ! -z "$2" ] ; then
ebuTarget="$2"
fi
checkInstalled
setPassphrase setPassphrase
exe $toolName restore "$EBU_TARGET" "$ebuTarget" exe $toolBin restore "$EBU_TARGET" "$ebuLocalTarget"
unsetPassphrase unsetPassphrase
} }
@@ -109,14 +115,15 @@ step_5() {
elif [ ! -z "$EBU_MAX_FULL_BACKUPS" ] ; then elif [ ! -z "$EBU_MAX_FULL_BACKUPS" ] ; then
dupCommand+="remove-all-but-n-full $EBU_MAX_FULL_BACKUPS " dupCommand+="remove-all-but-n-full $EBU_MAX_FULL_BACKUPS "
elif [ ! -z "$EBU_MAX_FULLS_WITH_INCRS" ] ; then elif [ ! -z "$EBU_MAX_FULLS_WITH_INCRS" ] ; then
dupCommand+="remove-all-but-n-full $EBU_MAX_FULLS_WITH_INCRS " dupCommand+="remove-all-inc-of-but-n-full $EBU_MAX_FULLS_WITH_INCRS "
else else
echoerr " [E] No purge option configured" if [ $QUIET -eq 0 ] ; then echoerr " [W] No purge option configured" ; fi
return -1 return -1
fi fi
checkInstalled
setPassphrase setPassphrase
exe $toolName $dupCommand --force "$ebuTarget" exe $toolBin $dupCommand --force "$ebuTarget"
unsetPassphrase unsetPassphrase
} }
@@ -129,10 +136,11 @@ step_20() {
ebuTarget="$1" ebuTarget="$1"
fi fi
exe $toolName collection-status "$ebuTarget" checkInstalled
exe $toolBin collection-status "$ebuTarget"
} }
step_22_info() { echo "List backup files [BACKUP TARGET]"; } step_22_info() { echo "List backup files [TARGET]"; }
step_22_alias() { ALIAS='list'; } step_22_alias() { ALIAS='list'; }
step_22() { step_22() {
shift shift
@@ -141,26 +149,53 @@ step_22() {
ebuTarget="$1" ebuTarget="$1"
fi fi
exe $toolName list-current-files "$ebuTarget" checkInstalled
exe $toolBin list-current-files "$ebuTarget"
} }
step_70_info() { step_70_info() {
echo -n "Manage cron file for " echo -n "Manage cron file for "
if [ $CONTEXT_HELP -ne 0 ] ; then if [ $CONTEXT_HELP -ne 0 ] ; then
echo "selected profile" echo -n "selected profile"
else else
echo "profile: $SEQ_PROFILE_NAME" echo -n "profile: $SEQ_PROFILE_NAME"
fi fi
echo " [OPTIONS]"
echoinfo " [OPTIONS]"
echoinfo " --remove, -r : remove cron file"
} }
step_70_alias() { ALIAS='cron'; } step_70_alias() { ALIAS='cron'; }
step_70() { step_70() {
local cronScript="$toolCronDir/${toolCronPrefix}$SEQ_PROFILE_NAME" shift
local cronEntry="$EBU_CRONTIME $(whoami) $WDIR/$(basename -- $0) -qq -p $SEQ_PROFILE_NAME >>/dev/null" local arg
if [ -z "$EBU_CRONTIME" ] ; then local cronRemove=0
local cronScript="$toolCronDir/${toolPrefix}$SEQ_PROFILE_NAME"
local cronLog='>/dev/null'
local cronEntry="$EBU_CRONTIME $(whoami) $WDIR/$(basename -- $0) -qq -p $SEQ_PROFILE_NAME"
for arg in "$@" ; do
case "$1" in
--remove|-r)
cronRemove=1
shift
;;
esac
done
if [ ! -z "$EBU_LOG_DIR" ] ; then
cronLog="$EBU_LOG_DIR/${toolPrefix}${SEQ_PROFILE_NAME}.log"
exe touch "$cronLog"
exe chmod 600 "$cronLog"
fi
cronEntry+=" >$cronLog"
if [ -z "$EBU_CRONTIME" ] || [ $cronRemove -ne 0 ] ; then
echo " [I] Removing cron for profile $SEQ_PROFILE_NAME"
exe rm -r "$cronScript" exe rm -r "$cronScript"
else else
checkFileHead "$cronScript" "$EBU_CRONTIME" checkFileHead "$cronScript" "$cronEntry"
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo " [I] Update cron for profile $SEQ_PROFILE_NAME" echo " [I] Update cron for profile $SEQ_PROFILE_NAME"
exep "sudo echo \"$cronEntry\" > \"$cronScript\"" exep "sudo echo \"$cronEntry\" > \"$cronScript\""
@@ -221,10 +256,13 @@ checkFileHead() {
} }
checkInstalled() { checkInstalled() {
if [ -z "$toolBin" ] ; then
command -v $toolName >>/dev/null command -v $toolName >>/dev/null
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
step install step install
fi fi
toolBin="$EBU_PRECMD $(command -v $toolName)"
fi
} }
VERSION_SEQREV=12 VERSION_SEQREV=12