Star

Created With

linkHooks

If you want to perform some commands before and/or after a backup or restore, you can use hooks.

They consist of a list of commands that will be executed in the same directory as the config file or in the dir directory if configured.

The following hooks groups are supported, none are required:

.autorestic.yml
1linklocations:

2link my-location:

3link from: /data

4link to: my-backend

5link hooks:

6link backup:

7link before:

8link - echo "One"

9link - echo "Two"

10link - echo "Three"

11link after:

12link - echo "Byte"

13link failure:

14link - echo "Something went wrong"

15link success:

16link - echo "Well done!"

17link restore:

18link dir: /var/www/html

19link before:

20link - echo "Let's restore this backup!"

21link after:

22link - echo "Finished to restore"

23link failure:

24link - echo "A problem has been encountered :("

25link success:

26link - echo "Successfully restored!"

linkFlowchart

  1. before hook
  2. Run backup
  3. after hook
    • success hook if no errors were found
    • failure hook if at least one error was encountered

If the before hook encounters errors the backup and after hooks will be skipped and only the failed hooks will run.

linkEnvironment variables

All hooks are exposed to the AUTORESTIC_LOCATION environment variable, which contains the location name.

The after and success hooks have access to additional information with the following syntax:

1link$AUTORESTIC_[TYPE]_[I]

2link$AUTORESTIC_[TYPE]_[BACKEND_NAME]

Every type of metadata is appended with both the name of the backend associated with and the number in which the backends where executed.

linkAvailable Metadata Types

linkExample

Assuming you have a location bar that backs up to a single backend named foo you could expect the following env variables:

1link$AUTORESTIC_LOCATION=bar

2link$AUTORESTIC_FILES_ADDED_0=42

3link$AUTORESTIC_FILES_ADDED_FOO=42

HooksFlowchartEnvironment variablesAvailable Metadata TypesExample

Home Quick Start Installation Configuration Upgrade

Locationschevron_right

Overview Hooks

Optionschevron_right

Cron Docker Volumes

Backendchevron_right
CLIchevron_right
Migrationchevron_right

Examples Docker QA Community Contributors