diff --git a/backup.sh b/backup.sh index d850f346ca8c2b5263c9ede5d2aa1ae557fc723a..121aef6c0eb85d92b14d7cb55adb314e1f7160a0 100755 --- a/backup.sh +++ b/backup.sh @@ -176,6 +176,8 @@ EOFbackupinfo if [ $bStart -eq 1 ]; then + _j_runHooks "10-before-backup" + sleep 3 # ------------------------------------------------------------ @@ -188,8 +190,10 @@ EOFbackupinfo echo "INFO: $(date) - Making local backups ... ${DIR_SELF}/localdump.sh ALL" | tee -a "$JOB_LOGFILE" + "${DIR_SELF}"/localdump.sh ALL | tee -a "$JOB_LOGFILE" rcBackup=$? + echo "INFO: $(date) - local backups were finished" | tee -a "$JOB_LOGFILE" echo sleep 2 diff --git a/check_clientbackup.sh b/check_clientbackup.sh index b481c54ec1e7dcf4c09f0d890dade01511389935..899154c264f145acb4bcd62c9f3f3638d9285fd3 100755 --- a/check_clientbackup.sh +++ b/check_clientbackup.sh @@ -14,6 +14,7 @@ # 2016-12-09 ah,ds v1.0 # 2022-01-19 ah v1.1 fixes with shellcheck # 2022-02-09 ah v1.2 update after changes in logging +# 2022-10-07 ah v1.3 unescape regex with space to prevent "grep: warning: stray \ before white space" # ============================================================================== . $(dirname $0)/jobhelper.sh @@ -105,14 +106,14 @@ else # sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize" # echo "$logfile" | grep -F "inc" >/dev/null # if [ $? -eq 0 ]; then - # sSearch="[ADM]\ |${sSearch}" + # sSearch="[ADM] |${sSearch}" # fi # echo --- changes: # grep -E "^(${sSearch})" "$logfile" echo # echo ">>> Summary of backed up directories:" - # cat $logfile | grep "DIR\ " + # cat $logfile | grep "DIR " echo ">>> Summary of backup actions:" cat $logfile | grep "__[A-Z][A-Z]*__" diff --git a/docs/10_Features.md b/docs/10_Features.md index 134bd0bd72a193b73ef61bd82e4b64fe5fd81e74..80e3139c26186f36a1892e9f0a1b3c65a915d127 100644 --- a/docs/10_Features.md +++ b/docs/10_Features.md @@ -131,6 +131,10 @@ graph LR ``` +# Hooks # + +You have several entry points to execute your custom scripts before, after and during th backup process. +See [Hooks](50_Hooks/_index.md) # Backup tools # diff --git a/docs/50_Hooks/_index.md b/docs/50_Hooks/_index.md new file mode 100644 index 0000000000000000000000000000000000000000..4ac8c92208a2666ed4fd52cc30cc468d6f18d760 --- /dev/null +++ b/docs/50_Hooks/_index.md @@ -0,0 +1,114 @@ +# Introduction + +Hooks are points during the backup process where you can execute custom scripts +at the beginning, at the end and during the backup process. + +All hooks are located in the `./hooks/` directory. + +We have hooks "before" a step starts and "afterwards". + +## List of hooks + +In the IML Backup exist the following hooks + +| Hook | where | description +|--- |--- |--- +| 10-before-backup | backup.sh | at the beginning of the backup +| 12-before-db-service | localdump.sh | before starting a backup of a backup type (mysql, sqlite, ...) +| 14-before-db-dump | unused +| 16-after-db-dump | unused +| 18-after-db-service | localdump.sh | after finishing a database type +| 20-before-transfer | transfer.sh | before starting transfer of all directories +| 22-before-folder-transfer| transfer.sh | before starting transfer of a single directory +| 24-after-folder-transfer | transfer.sh | after transfer of a single directory +| 26-after-prune | transfer.sh | after pruning data +| 28-after-verify | transfer.sh | after verifying data +| 30-post-backup | transfer.sh | after all backup steps + +At the beginning the startup hook (10-before-backup) and the post hook (30-post-backup) for triggering a message might be the most common to use. + +## Subdirs of a hook dir + +Below all hook directories have the subdirectory "always": `./hooks/[Name-of-hook]/always/` + +### "before" actions + +They don't know an execution status of something. They can execute only scripts that are located in "always" subdirectory. + +### "after" actions + +The "afterwards" added hooks know the execution status of the last action. That's why in the hook directory we have additionally the subdirs + +* `./hooks/[Name-of-hook]/on-ok/` - the last action was 0 (zero) +* `./hooks/[Name-of-hook]/on-error/` - if the exitcode was non-zero + +After execution of the scripts of "on-ok" or "on-error" additionally the found scripts of "always" will be executed. + +### Tree view of hook directories + +```txt +> tree -d hooks/ +hooks/ +|-- 10-before-backup +| `-- always +|-- 12-before-db-service +| `-- always +|-- 14-before-db-dump +| `-- always +|-- 16-after-db-dump +| |-- always +| |-- on-error +| `-- on-ok +|-- 18-after-db-service +| |-- always +| |-- on-error +| `-- on-ok +|-- 20-before-transfer +| `-- always +|-- 22-before-folder-transfer +| `-- always +|-- 24-after-folder-transfer +| |-- always +| |-- on-error +| `-- on-ok +|-- 26-after-prune +| |-- always +| |-- on-error +| `-- on-ok +|-- 28-after-verify +| |-- always +| |-- on-error +| `-- on-ok +`-- 30-post-backup + |-- always + |-- on-error + `-- on-ok + +34 directories +``` + +### What will be executed? + +When processing a hook all files will be sorted in alphabetic order. Files starting with a dot will be ignored. Each found executable file will be executed. + +## Example + +Before the backup starts we want to update some local information that we want to put as latest information. +I have a script that gets the list of installed linux packages as a textfile. If my system is damaged and I need to reinstall it this list will help me to reinstall all applications and libraries. + +If my bash script that does the job is `/home/axel/scripts/list_packages.sh` ... and we let it run on each start of the backup. That's why we use the *10-before-backup* hook: + +Create a file named *hooks/10-before-backup/always/10_list_packages.sh* which has the content: + +```sh +#!/usr/bin/env bash +/home/axel/scripts/list_packages.sh +``` +If you have the installation in a user directory keep in mind that the backup runs as root. Set executable permissions for root. If owner and group is your user then set exection permissions for the world: 0755: + +```sh +> chmod 0755 hooks/10-before-backup/always/10_list_packages.sh +> ls -l hooks/10-before-backup/always +total 4 +-rwxr-xr-x 1 axel axel 79 Oct 7 22:36 10_get_installed_packages.sh +``` diff --git a/docs/99_Glossary.md b/docs/99_Glossary.md index b95f767472eb69bf81ebef6e303b9ad48ccf1b43..d3808193162fc000e2161dfea1468c3b227aedde 100644 --- a/docs/99_Glossary.md +++ b/docs/99_Glossary.md @@ -1,19 +1,45 @@ ## Explaination of some words +### B + * **backup** = save current data "somewhare".<br>Store your backup outside the local system to have a copy you can access if the system is damaged. -* **cronjob** = start a command in a defined cycle. ie. eve3ry hour, every day, once a week and so on +### C + +* **cronjob** = start a command in a defined cycle. ie. every hour, every day, once a week and so on + +### D * **database dump** = backup a database / scheme into a single file +* **Duplicity** = Commandline backup tool; set of scripts written in Python; <https://duplicity.gitlab.io/duplicity-web/> + +### F + * **full backup** = backup of all data of the local system. +### H + +* **hook** = entry points during the backup process where you can execute custom scripts. + +### I + * **incremental backup** = backup of data that have changed since the last backup. +### P + * **prune** = delete old backup sets and thin data in the backup repository. <br>As an example: You can make an hourly backup and define to keep all of them for a week, daily backups for 90 days and monthly backups starting from 1 to 36 monthes (=3 years). The prune actions removes data in the backup storage to thin out your backup data. - + +### R + +* **Restic** = Commandline backup tool; a single binary is compiled with Go; <https://restic.net/> + * **restore** = copy data back from a made backup to the local system. +### T + * **ttl** = time to live<br>Definition how long an information is valid before it needs to be updated again. +### V + * **verify** = check the integrity of backup data \ No newline at end of file diff --git a/hooks/10-before-backup/always/.gitkeep b/hooks/10-before-backup/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/12-before-db-service/always/.gitkeep b/hooks/12-before-db-service/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/14-before-db-dump/always/.gitkeep b/hooks/14-before-db-dump/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/16-after-db-dump/always/.gitkeep b/hooks/16-after-db-dump/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/16-after-db-dump/on-error/.gitkeep b/hooks/16-after-db-dump/on-error/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/16-after-db-dump/on-ok/.gitkeep b/hooks/16-after-db-dump/on-ok/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/18-after-db-service/always/.gitkeep b/hooks/18-after-db-service/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/18-after-db-service/on-error/.gitkeep b/hooks/18-after-db-service/on-error/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/18-after-db-service/on-ok/.gitkeep b/hooks/18-after-db-service/on-ok/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/20-before-transfer/always/.gitkeep b/hooks/20-before-transfer/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/22-before-folder-transfer/always/.gitkeep b/hooks/22-before-folder-transfer/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/24-after-folder-transfer/always/.gitkeep b/hooks/24-after-folder-transfer/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/24-after-folder-transfer/on-error/.gitkeep b/hooks/24-after-folder-transfer/on-error/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/24-after-folder-transfer/on-ok/.gitkeep b/hooks/24-after-folder-transfer/on-ok/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/26-after-prune/always/.gitkeep b/hooks/26-after-prune/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/26-after-prune/on-error/.gitkeep b/hooks/26-after-prune/on-error/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/26-after-prune/on-ok/.gitkeep b/hooks/26-after-prune/on-ok/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/28-after-verify/always/.gitkeep b/hooks/28-after-verify/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/28-after-verify/on-error/.gitkeep b/hooks/28-after-verify/on-error/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/28-after-verify/on-ok/.gitkeep b/hooks/28-after-verify/on-ok/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/30-post-backup/always/.gitkeep b/hooks/30-post-backup/always/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/30-post-backup/on-error/.gitkeep b/hooks/30-post-backup/on-error/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hooks/30-post-backup/on-ok/.gitkeep b/hooks/30-post-backup/on-ok/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/jobhelper.sh b/jobhelper.sh index d1efb90873c8e2fdb919daf772bb2b29d7aa00fb..51062390c0b845217f10b75f2775d01d3465e85e 100755 --- a/jobhelper.sh +++ b/jobhelper.sh @@ -12,6 +12,7 @@ # 2017-01-23 ah,ds v1.1 added j_getLastBackupAge # 2017-02-16 ah,ds v1.2 added storage helper function # 2018-02-13 ah,ds v1.3 detect samba shares based on a flag +# 2022-10-07 ah v1.4 unescape regex with space to prevent "grep: warning: stray \ before white space" # ================================================================================ @@ -130,7 +131,7 @@ function j_getDirs2Backup(){ # param string path # ------------------------------------------------------------ function j_getSetnameOfPath(){ - grep "^set.*dir\ =\ $*$" "${DIRFILE}" | cut -f 1 -d "=" | sed "s#\-\-dir\ ##g" + grep "^set.*dir = $*$" "${DIRFILE}" | cut -f 1 -d "=" | sed "s#\-\-dir ##g" } # ------------------------------------------------------------ @@ -172,13 +173,49 @@ function _j_getvar(){ >&2 echo "ERROR: cannot read file: ${1}. Abort." exit 100 fi - grep "^${2}\ =\ " < "${1}"| cut -f 3- -d " " + grep "^${2} = " < "${1}"| cut -f 3- -d " " } # ------------------------------------------------------------ # read local jobdescription and set as variables # ------------------------------------------------------------ +# ------------------------------------------------------------ +# execute hook skripts in a given directory in alphabetic order +# param string name of hook directory +# param string optional: integer of existcode or "" for non-on-result hook +# ------------------------------------------------------------ +function _j_runHooks(){ + local _hookbase="$1" + local _exitcode="$2" + local _hookdir="$( dirname $0 )/hooks/$_hookbase" + + if [ -z "$_exitcode" ]; then + _hookdir="$_hookdir/always" + elif [ "$_exitcode" = "0" ]; then + _hookdir="$_hookdir/on-ok" + else + _hookdir="$_hookdir/on-error" + fi + for hookscript in $( ls -1a "$_hookdir" | grep -v "^\." | sort ) + do + if [ -x "$_hookdir/$hookscript" ]; then + h3 "HOOK: start $_hookdir/$hookscript ..." + $_hookdir/$hookscript + else + h3 "HOOK: SKIP $_hookdir/$hookscript (not executable) ..." + fi + done + + # if an exitcode was given as param then run hooks without exitcode + # (in subdir "always") + if [ -n "$_exitcode" ]; then + _j_runHooks "$_hookbase" + fi + + echo +} + # ------------------------------------------------------------ # parse day of week and day of month and echo 0 or 1 # @@ -299,36 +336,6 @@ function _j_setLogfile(){ export JOB_LOGFILE } -# ------------------------------------------------------------ -# date helper for job entries in start-time-inc/ start-time-full -# * get first the first entry or - if many - the latest entry -# * if empty: take value from start-time -# param string one of start-time-inc|start-time-full -# ------------------------------------------------------------ -# function _j_fetchLatestStarttime(){ -# sLatest= -# sStart=`_j_getvar ${JOBFILE} "$1" | sed "s#[\ \:\-]##g"` -# for sTime in `echo $sStart | sed "s#,# #g"` -# do -# if [ -z $sLatest ]; then -# sLatest=$sTime -# fi -# if [ $sTime -le `date +%H%M` ]; then -# sLatest=$sTime -# fi -# done -# if [ -z $sLatest ]; then -# $sLatest=`_j_getvar ${JOBFILE} "start-time" | sed "s#[\ \:\-]##g"` -# fi -# if [ -z $sLatest ]; then -# color error -# echo ERROR: missing start time info for $1 -# color reset -# exit 1 -# fi -# echo $sLatest -# } - # ------------------------------------------------------------ # check if a binary exists - and abort if not # param string name of file diff --git a/localdump.sh b/localdump.sh index 3bb293ae694dc2026b0abfe00ea9d95c063e4200..36abbfe34e9fe995d54b964ce3633b919482b441 100755 --- a/localdump.sh +++ b/localdump.sh @@ -204,7 +204,7 @@ if [ -d "${BACKUP_TARGETDIR}" ]; then cd "${BACKUP_TARGETDIR}" if [ -z $1 ]; then - find -type f | sed "s#__[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9].*##g" | grep -v ".meta" | sort -ud| sed "s#^\./##g" + find -type f | sed "s#__[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9].*##g" | grep -v "\.meta" | sort -ud| sed "s#^\./##g" else ls -ltr "$*__"* | sed "s#^\./##g" fi @@ -354,7 +354,9 @@ # ----- start service specific script h2 "START SCRIPT FOR ${SERVICENAME} - $BACKUP_SCRIPT" + _j_runHooks "12-before-db-service" . $BACKUP_SCRIPT $mode + _j_runHooks "18-after-db-service" "$rc" # ----- post jobs: cleanup cleanup_backup_target diff --git a/plugins/localdump/couchdb.sh b/plugins/localdump/couchdb.sh index 5015682d4b6297d15c06d3189e4a4345c3ca64f6..f948c6de165861ad9434752a079e3e2cf46ea784 100755 --- a/plugins/localdump/couchdb.sh +++ b/plugins/localdump/couchdb.sh @@ -12,6 +12,7 @@ # 2017-03-27 ..... v1.0 restore # 2022-01-20 v1.1 fixes with shellcheck # 2022-03-17 v1.2 WIP: add lines with prefix __DB__ +# 2022-10-07 ah v1.3 unescape regex with space to prevent "grep: warning: stray \ before white space" # ================================================================================ if [ -z "$BACKUP_TARGETDIR" ]; then @@ -108,7 +109,7 @@ function doBackup(){ loadInstance "$COUCHDB_INSTANCE" echo "--- instance: $COUCHDB_INSTANCE" - if curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.*\ 200\ "; then + if curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.* 200 "; then _doBackupOfSingleInstance @@ -186,7 +187,7 @@ function restoreByFile(){ loadInstance "$COUCHDB_INSTANCE" echo "connect $couchdbhost on port $couchdbport with user $couchdbuser" - if ! curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.*\ 200\ " >/dev/null; then + if ! curl --head -X GET "$COUCHDB_URL" 2>/dev/null | grep "^HTTP.* 200 " >/dev/null; then color error echo ERROR: couch DB instance is not available curl -X GET "$COUCHDB_URL" diff --git a/plugins/localdump/couchdb2.sh b/plugins/localdump/couchdb2.sh index ea4bd3f472e650e1b93b09f72fe7084f6d1ee0d5..50a65f95d6b88158c59dbc2d0bde103b562de334 100755 --- a/plugins/localdump/couchdb2.sh +++ b/plugins/localdump/couchdb2.sh @@ -20,6 +20,7 @@ # 2022-04-07 v1.5 check archive file, not only seq file # 2022-04-14 v1.6 backup security infos (no restore yet) # 2022-04-21 v1.7 restore security infos +# 2022-10-07 ah v1.8 unescape regex with space to prevent "grep: warning: stray \ before white space" # ================================================================================ if [ -z "$BACKUP_TARGETDIR" ]; then @@ -123,7 +124,7 @@ function doBackup(){ loadInstance "$COUCHDB_INSTANCE" echo "--- instance: $COUCHDB_INSTANCE" - if curl --head -X GET "$COUCH_URL" 2>/dev/null | grep "^HTTP.*\ 200\ "; then + if curl --head -X GET "$COUCH_URL" 2>/dev/null | grep "^HTTP.* 200 "; then echo OK, connected. sleep 2 _doBackupOfSingleInstance @@ -303,7 +304,7 @@ function restoreByFile(){ if [ $bFastMode -eq 0 ]; then echo connect $couchdbhost on port $couchdbport with user $couchdbuser - curl --head -X GET $COUCH_URL 2>/dev/null | grep "^HTTP.*\ 200\ " >/dev/null + curl --head -X GET $COUCH_URL 2>/dev/null | grep "^HTTP.* 200 " >/dev/null if [ $? -ne 0 ]; then color error echo ERROR: couch DB instance is not available diff --git a/plugins/localdump/ldap.sh b/plugins/localdump/ldap.sh index 8d301aae168f187641db719c26c6e1d7fb97cf29..83ac400006ba581fa08ac8766ca8d06b6f8edf33 100755 --- a/plugins/localdump/ldap.sh +++ b/plugins/localdump/ldap.sh @@ -13,6 +13,7 @@ # 2021-12-13 ah v1.1 detect config path # 2021-12-14 ah v1.2 detect sbin path to execute slapcat without path # 2022-03-17 v1.3 WIP: add lines with prefix __DB__ +# 2022-10-07 ah v1.4 unescape regex with space to prevent "grep: warning: stray \ before white space" # ================================================================================ @@ -76,7 +77,7 @@ function doLdapBackup(){ for cfgname in $(ldapsearch -Y EXTERNAL -H ldapi:/// -s base -b '' -LLL configContext | grep "configContext" | cut -f 2 -d ":") do echo DN $cfgname - cfg2=$(echo $cfgname | sed "s#[\ =,]#_#g") + cfg2=$(echo $cfgname | sed "s#[ =,]#_#g") outfile=$(hostname)_ldap_olc_config__$(get_outfile ${cfg2}).ldif dump_ldap "$cfgname" "$BACKUP_TARGETDIR/$outfile" @@ -88,7 +89,7 @@ function doLdapBackup(){ for cfgname in $(ldapsearch -Y EXTERNAL -H ldapi:/// -s base -b "" -LLL "namingContexts" | grep "namingContexts" | cut -f 2 -d ":") do echo DN $cfgname - cfg2=`echo $cfgname | sed "s#[\ =,]#_#g"` + cfg2=`echo $cfgname | sed "s#[ =,]#_#g"` outfile=$(hostname)_ldap_data__$(get_outfile ${cfg2}).ldif dump_ldap "$cfgname" "$BACKUP_TARGETDIR/$outfile" diff --git a/plugins/transfer/duplicity.sh b/plugins/transfer/duplicity.sh index 2b1788c16734b024aa1182ddeeea06118b93d3c7..1764a95156e1f60465e04b1d4d8d32ba89cf402e 100644 --- a/plugins/transfer/duplicity.sh +++ b/plugins/transfer/duplicity.sh @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------------- # ah - Axel Hahn <axel.hahn@iml.unibe.ch> # 2021-05-19 ah v0.0 INIT ... WIP +# 2022-10-07 ah v1.1 unescape regex with space to prevent "grep: warning: stray \ before white space" # ================================================================================ @@ -211,7 +212,7 @@ local _date= echo "--- Existing snapshots:" t_restoreDoShowVolumes \ - | grep -E "(Full|Incremental).*[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\ " \ + | grep -E "(Full|Incremental).*[0-9][0-9]:[0-9][0-9]:[0-9][0-9] " \ | sort -u > $tmpoutVolumes if [ `cat $tmpoutVolumes | wc -l` -eq 0 ]; then color error diff --git a/plugins/transfer/restic.sh b/plugins/transfer/restic.sh index 75a92cb2c52209a8db71b3063ccc5724ed9c0acc..032fe28339dc3c7814517543ec40071623fd6b7b 100644 --- a/plugins/transfer/restic.sh +++ b/plugins/transfer/restic.sh @@ -213,6 +213,8 @@ color reset t_rcCheckPrune $_myrc + _j_runHooks "26-after-prune" "$_myrc" + echo } # verify backup data @@ -231,6 +233,7 @@ color reset t_rcCheckVerify $_myrc + _j_runHooks "28-after-verify" "$_myrc" echo } diff --git a/transfer.sh b/transfer.sh index 2355de80c3c8b8b75e0b4749ca10ebbed2df0af3..ccb716bfc5780a2f324db7c7c8b387adc4916403 100755 --- a/transfer.sh +++ b/transfer.sh @@ -32,6 +32,7 @@ # 2022-02-10 ah v2.2 update logging (removing tee) # 2022-10-01 ah v2.3 customize prune and verify action # 2022-10-04 ah v2.4 prune and verify are non directory based +# 2022-10-07 ah v2.5 unescape regex with space to prevent "grep: warning: stray \ before white space" # ================================================================================ @@ -65,8 +66,7 @@ # check if [ -z "$STORAGE_BIN" ]; then - # STORAGE_BIN=restic - STORAGE_BIN=duplicity + STORAGE_BIN=restic fi CFGPREFIX=${STORAGE_BIN}_ @@ -219,13 +219,14 @@ function setAction(){ fi . `dirname $0`/plugins/transfer/$STORAGE_BIN.sh || exit 1 - test -z "$STORAGE_REGISTER" || . `dirname $0`/plugins/register/$STORAGE_REGISTER.sh || exit 1 # -------------------------------------------------------------------------------- # ----- Check requirements t_checkRequirements || exit 1 + test -z "$STORAGE_REGISTER" || . `dirname $0`/plugins/register/$STORAGE_REGISTER.sh || exit 1 + echo Check locking of a running transfer if [ -f "${lockfile}" ]; then color error @@ -268,6 +269,8 @@ function setAction(){ exit 2 fi + _j_runHooks "20-before-transfer" + # -------------------------------------------------------------------------------- # ----- BACKUP VARS @@ -357,11 +360,11 @@ function setAction(){ if [ ! -z $backupid ]; then - for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-include" | sed "s#\ #${sSpaceReplace}#g"` + for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-include" | sed "s# #${sSpaceReplace}#g"` do ARGS_BACKUP="${ARGS_BACKUP} $( t_getParamInlude $sItem)" done - for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-exclude" | sed "s#\ #${sSpaceReplace}#g"` + for sItem in `_j_getvar ${DIRFILE} "${backupid}\-\-exclude" | sed "s# #${sSpaceReplace}#g"` do ARGS_BACKUP="${ARGS_BACKUP} $( t_getParamExlude $sItem)" done @@ -379,6 +382,9 @@ function setAction(){ if [ $doBackup -eq 0 ]; then echo "SKIP backup" else + + _j_runHooks "22-before-folder-transfer" + sCmd="$( t_backupDirGetCmdBackup )" echo "what: ${BACKUP_DIR}" echo "target: ${sTarget}" | sed 's#:[^:]*@#:**********@#' @@ -391,6 +397,7 @@ function setAction(){ echo t_rcCheckBackup $myrc "${BACKUP_DIR}" + _j_runHooks "24-after-folder-transfer" "$myrc" fi echo @@ -410,6 +417,8 @@ function setAction(){ fi echo done + else + echo "SKIP backup of dirs" fi # --- prune @@ -469,6 +478,8 @@ function setAction(){ echo Backup FAILED :-/ fi color reset + + _j_runHooks "30-post-backup" "$rc" echo typeset -i TIMER_TRANSFER=`date +%s`-$TIMER_TRANSFER_START echo `date` $ACTION DONE in $TIMER_TRANSFER sec