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
100-before-backup backup.sh at the beginning of the backup
200-before-db-service localdump.sh before starting a backup of a backup type (mysql, sqlite, …)
210-before-db-dump unused
220-after-db-dump unused
230-after-db-service localdump.sh after finishing a database type
300-before-transfer transfer.sh before starting transfer of all directories
310-before-folder-transfer transfer.sh before starting transfer of a single directory
320-after-folder-transfer transfer.sh after transfer of a single directory
330-after-prune transfer.sh after pruning data
340-after-verify transfer.sh after verifying data
400-post-backup transfer.sh after all backup steps

At the beginning the startup hook (100-before-backup) and the post hook (400-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

> tree -d hooks/
hooks/
|-- 100-before-backup
|   `-- always
|-- 200-before-db-service
|   `-- always
|-- 210-before-db-dump
|   `-- always
|-- 220-after-db-dump
|   |-- always
|   |-- on-error
|   `-- on-ok
|-- 230-after-db-service
|   |-- always
|   |-- on-error
|   `-- on-ok
|-- 300-before-transfer
|   `-- always
|-- 310-before-folder-transfer
|   `-- always
|-- 320-after-folder-transfer
|   |-- always
|   |-- on-error
|   `-- on-ok
|-- 330-after-prune
|   |-- always
|   |-- on-error
|   `-- on-ok
|-- 340-after-verify
|   |-- always
|   |-- on-error
|   `-- on-ok
`-- 400-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 100-before-backup hook:

Create a file named hooks/100-before-backup/always/10_list_packages.sh which has the content:

#!/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:

> chmod 0755 hooks/100-before-backup/always/10_list_packages.sh
> ls -l hooks/100-before-backup/always
total 4
-rwxr-xr-x 1 axel axel 79 Oct  7 22:36 10_get_installed_packages.sh