Hooks are points during the backup process where you can execute custom scripts.
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.
...
...
@@ -24,6 +25,8 @@ In the IML Backup exist the following hooks
| 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/`
...
...
@@ -34,16 +37,78 @@ They don't know an execution status of something. They can execute only scripts
### "after" actions
The "afterwards" added hooks know the execution status of the last action. that's why in the hook directory additionally we have the subdirs
*`./hooks/[Name-of-hook]/on-ok/`
*`./hooks/[Name-of-hook]/on-error/`
The "afterwards" added hooks know the execution status of the last action. That's why in the hook directory we have additionally the subdirs
If the exitcode of the last action was 0 (zero) then the scripts in the "on-ok" folder will be handled.
If the exitcode was non-zero - the scripts in the "on-error" folder.
*`./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: