Skip to content
Snippets Groups Projects
Commit b2ad27c6 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'add-hooks' into 'master'

Add hooks

See merge request !80
parents b980df48 db3cbe5c
No related branches found
No related tags found
1 merge request!80Add hooks
Showing
with 153 additions and 4 deletions
...@@ -176,6 +176,8 @@ EOFbackupinfo ...@@ -176,6 +176,8 @@ EOFbackupinfo
if [ $bStart -eq 1 ]; then if [ $bStart -eq 1 ]; then
_j_runHooks "10-before-backup"
sleep 3 sleep 3
# ------------------------------------------------------------ # ------------------------------------------------------------
...@@ -188,8 +190,10 @@ EOFbackupinfo ...@@ -188,8 +190,10 @@ EOFbackupinfo
echo "INFO: $(date) - Making local backups ... ${DIR_SELF}/localdump.sh ALL" | tee -a "$JOB_LOGFILE" echo "INFO: $(date) - Making local backups ... ${DIR_SELF}/localdump.sh ALL" | tee -a "$JOB_LOGFILE"
"${DIR_SELF}"/localdump.sh ALL | tee -a "$JOB_LOGFILE" "${DIR_SELF}"/localdump.sh ALL | tee -a "$JOB_LOGFILE"
rcBackup=$? rcBackup=$?
echo "INFO: $(date) - local backups were finished" | tee -a "$JOB_LOGFILE" echo "INFO: $(date) - local backups were finished" | tee -a "$JOB_LOGFILE"
echo echo
sleep 2 sleep 2
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# 2016-12-09 ah,ds v1.0 # 2016-12-09 ah,ds v1.0
# 2022-01-19 ah v1.1 fixes with shellcheck # 2022-01-19 ah v1.1 fixes with shellcheck
# 2022-02-09 ah v1.2 update after changes in logging # 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 . $(dirname $0)/jobhelper.sh
...@@ -105,14 +106,14 @@ else ...@@ -105,14 +106,14 @@ else
# sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize" # sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize"
# echo "$logfile" | grep -F "inc" >/dev/null # echo "$logfile" | grep -F "inc" >/dev/null
# if [ $? -eq 0 ]; then # if [ $? -eq 0 ]; then
# sSearch="[ADM]\ |${sSearch}" # sSearch="[ADM] |${sSearch}"
# fi # fi
# echo --- changes: # echo --- changes:
# grep -E "^(${sSearch})" "$logfile" # grep -E "^(${sSearch})" "$logfile"
echo echo
# echo ">>> Summary of backed up directories:" # echo ">>> Summary of backed up directories:"
# cat $logfile | grep "DIR\ " # cat $logfile | grep "DIR "
echo ">>> Summary of backup actions:" echo ">>> Summary of backup actions:"
cat $logfile | grep "__[A-Z][A-Z]*__" cat $logfile | grep "__[A-Z][A-Z]*__"
......
...@@ -131,6 +131,10 @@ graph LR ...@@ -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 # # Backup tools #
......
# 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
```
## Explaination of some words ## 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. * **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 * **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. * **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. * **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. * **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. * **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. * **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 * **verify** = check the integrity of backup data
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment