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: