#2476 Issue closed: How to include a customized shell script to ReaR before or after it kicks in?

Labels: support / question, fixed / solved / done

bobbysch opened issue at 2020-08-10 13:52:

  • Description of the issue (ideally so that others can reproduce it):

There is no issue at all, just a question how to include a customized shell script to ReaR (before or after it kicks in) and store the results of the script to the same backup folder?

jsmeix commented at 2020-08-10 14:29:

We have PRE_RECOVERY_SCRIPT and POST_RECOVERY_SCRIPT
and PRE_BACKUP_SCRIPT and POST_BACKUP_SCRIPT
see "custom scripts" in default.conf
https://github.com/rear/rear/blob/master/usr/share/rear/conf/default.conf#L3129

We also have RESULT_FILES - see
https://github.com/rear/rear/blob/master/usr/share/rear/conf/default.conf#L3095

I do not understand what exactly you mean.
What do you mean with "before or after it kicks in"
and what do you mean with "the same backup folder"?

bobbysch commented at 2020-08-11 19:23:

Thanks for your kind answer.
That's great to learn about those scripts.
The same backup folder means BACKUP_URL location.
Is there a variable that I can point to that location in the custom script?

jsmeix commented at 2020-08-12 08:19:

PRE_RECOVERY_SCRIPT is run during ReaR recovery system startup via
usr/share/rear/setup/default/010_pre_recovery_script.sh
which runs before "rear" is called by the user
so ReaR config files are not yet sourced while PRE_RECOVERY_SCRIPT is run
so you need to source /etc/rear/local.conf in your PRE_RECOVERY_SCRIPT
to get the BACKUP_URL value in your PRE_RECOVERY_SCRIPT.

PRE_BACKUP_SCRIPT is run while "rear" is running via
usr/share/rear/backup/default/010_pre_backup_script.sh
so ReaR config files are already sourced when PRE_BACKUP_SCRIPT is run
so that the BACKUP_URL value could be available in your PRE_BACKUP_SCRIPT
but I think because PRE_BACKUP_SCRIPT is run via

eval "${PRE_BACKUP_SCRIPT[@]}"

the BACKUP_URL value could be not available in PRE_BACKUP_SCRIPT
when the BACKUP_URL variable was not exported so that you may need
something like

export BACKUP_URL=...

in your etc/rear/local.conf file to get the BACKUP_URL value
available also in PRE_BACKUP_SCRIPT.

PRE_BACKUP_SCRIPT is only run for "rear mkbackup" or "rear mkbackuponly"
(which run the matching scripts in usr/share/rear/backup)
but PRE_BACKUP_SCRIPT is not run for "rear mkrescue"
(which does not run scripts in usr/share/rear/backup).

FYI if you use BACKUP=NETFS:
usr/share/rear/backup/default/010_pre_backup_script.sh
is run before
usr/share/rear/backup/NETFS/default/100_mount_NETFS_path.sh
so the NETFS "mountable remote thingy" (e.g. a NFS share)
is not yet mounted when PRE_BACKUP_SCRIPT runs.


[Export of Github issue for rear/rear.]