diff --git a/seqs/ebackup.cfg.example b/seqs/ebackup.cfg.example index 14ac1a4..a786311 100644 --- a/seqs/ebackup.cfg.example +++ b/seqs/ebackup.cfg.example @@ -1,11 +1,5 @@ #!/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 EBU_PASSPHRASE= @@ -22,6 +16,21 @@ EBU_TARGET= # base directory to backup 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 diff --git a/seqs/ebackup.sh b/seqs/ebackup.sh index 96ce9f3..818c5a3 100755 --- a/seqs/ebackup.sh +++ b/seqs/ebackup.sh @@ -1,9 +1,10 @@ #!/bin/bash toolName=duplicity +toolBin= toolPpa="ppa:duplicity-team/duplicity-release-git" toolCronDir="/etc/cron.d" -toolCronPrefix="encBackup_" +toolPrefix="encBackup_" # Get script working directory # (when called from a different directory) @@ -35,7 +36,6 @@ step_1_info() { } step_1_alias() { ALIAS="backup"; } step_1() { - checkInstalled shift local arg @@ -70,8 +70,9 @@ step_1() { dupArgs+="--full-if-older-than=$EBU_MAX_FULLBKP_AGE " fi + checkInstalled setPassphrase - exe $toolName $dupCommand $dupArgs "$EBU_SOURCE" "$EBU_TARGET" + exe $toolBin $dupCommand $dupArgs "$EBU_SOURCE" "$EBU_TARGET" unsetPassphrase if [ $purgeAfter -ne 0 ] ; then @@ -79,7 +80,7 @@ step_1() { fi } -step_3_info() { echo "Restore [TARGET]"; } +step_3_info() { echo "Restore [TARGET]"; } step_3_alias() { ALIAS="restore"; } step_3() { shift @@ -87,10 +88,15 @@ step_3() { echoerr " [E] No target provided" return -1 fi - local ebuTarget="$1" + local ebuLocalTarget="$1" + local ebuTarget="$EBU_TARGET" + if [ ! -z "$2" ] ; then + ebuTarget="$2" + fi + checkInstalled setPassphrase - exe $toolName restore "$EBU_TARGET" "$ebuTarget" + exe $toolBin restore "$EBU_TARGET" "$ebuLocalTarget" unsetPassphrase } @@ -109,14 +115,15 @@ step_5() { elif [ ! -z "$EBU_MAX_FULL_BACKUPS" ] ; then dupCommand+="remove-all-but-n-full $EBU_MAX_FULL_BACKUPS " 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 - echoerr " [E] No purge option configured" + if [ $QUIET -eq 0 ] ; then echoerr " [W] No purge option configured" ; fi return -1 fi + checkInstalled setPassphrase - exe $toolName $dupCommand --force "$ebuTarget" + exe $toolBin $dupCommand --force "$ebuTarget" unsetPassphrase } @@ -129,10 +136,11 @@ step_20() { ebuTarget="$1" 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() { shift @@ -141,26 +149,53 @@ step_22() { ebuTarget="$1" fi - exe $toolName list-current-files "$ebuTarget" + checkInstalled + exe $toolBin list-current-files "$ebuTarget" } step_70_info() { echo -n "Manage cron file for " if [ $CONTEXT_HELP -ne 0 ] ; then - echo "selected profile" + echo -n "selected profile" else - echo "profile: $SEQ_PROFILE_NAME" + echo -n "profile: $SEQ_PROFILE_NAME" fi + echo " [OPTIONS]" + echoinfo " [OPTIONS]" + echoinfo " --remove, -r : remove cron file" } step_70_alias() { ALIAS='cron'; } step_70() { - local cronScript="$toolCronDir/${toolCronPrefix}$SEQ_PROFILE_NAME" - local cronEntry="$EBU_CRONTIME $(whoami) $WDIR/$(basename -- $0) -qq -p $SEQ_PROFILE_NAME >>/dev/null" - if [ -z "$EBU_CRONTIME" ] ; then + shift + local arg + 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" else - checkFileHead "$cronScript" "$EBU_CRONTIME" + checkFileHead "$cronScript" "$cronEntry" if [ $? -ne 0 ] ; then echo " [I] Update cron for profile $SEQ_PROFILE_NAME" exep "sudo echo \"$cronEntry\" > \"$cronScript\"" @@ -221,10 +256,13 @@ checkFileHead() { } checkInstalled() { - command -v $toolName >>/dev/null - if [ $? -ne 0 ] ; then - step install - fi + if [ -z "$toolBin" ] ; then + command -v $toolName >>/dev/null + if [ $? -ne 0 ] ; then + step install + fi + toolBin="$EBU_PRECMD $(command -v $toolName)" + fi } VERSION_SEQREV=12