It's possible to add custom code which is executed before and after the backup process via two script extensions. They are useful if modification of the backup script is required to extent the script capabilities and will be lost and thus have to be merged again and again every time when raspiBackup will be updated.

Three extensions are available and can be used as samples for extensions. The first two report the CPU temperature and memory utilization pre and post a backup run. The third one is called at the end of the backup and can be used to execute different actions depending on the success or failure of raspiBackup.

If you create your own extension please share it with the community and announce it's availability in a comment. If there is any function missing for the extensions please write a comment and I'll check whether it's possible to provide the missing function.

 

Standardextensions

  1. Following command installs the two extension in /usr/local/bin on Raspberry Pi:
    wget http://www.linux-tips-and-tricks.de/raspiBackupSampleExtensionsInstall.sh -O raspiBackupSampleExtensionsInstall.sh -q && bash raspiBackupSampleExtensionsInstall.sh 
  2. If you want to install the extensions manually download them with your browser or execute following command on your raspberry Pi to download the tar file and extract the contents to  /usr/local/bin.
    wget http://www.linux-tips-and-tricks.de/raspiBackupSampleExtensions.tgz -O raspiBackupSampleExtensions.tgz
    tar -xzf raspiBackupSampleExtensions.tgz -C /usr/local/bin

Following scripts will be copied into /usr/local/sbin:

1) raspiBackup_mem_pre.sh and raspiBackup_mem_post.sh

2) raspiBackup_temp_pre.sh and raspiBackup_temp_post.sh

3) raspiBackup_execute_post.sh

 

To activate the extension add following parameter to the raspiBackup call

-N "temp mem execute"

or add the following line to the config file

DEFAULT_EXTENSIONS="temp mem execute"

For details of the parameters and config file see this page.

 

eMailExtension

Starting with version 0.6.1.1 there exists an emailExtension which allows to write custom code which will send the eMail. That's very useful if the supported eMail clients of the script do not support the used eMailClient. In addition the format of the eMail can be customized. A sample emailExtension which uses mailx is included in the sample extension package.

The eMailExtension is used if mailext is used as parameter for -s. A script called raspiBackup_mail.sh will be called and has to handle the email creation and sending. Following parameters will be passed to the mailExtension script:

email="$1"        # target email address
subject="$2"      # email subject
content="$3"      # email contents
parms="$4"        # addtl email parms passed with -E
append="$5"       # file to append

If you create an eMailExtension for a special eMailClient please write a comment at the bottom of this page. There may be other interested in the extension also.

 

Notes

1) It's not required to have both pre and post scripts implemented.

2) When testing the extensions the parameter -F is very useful. This flag disables the backup process and speeds up script execution.

3) The return code of the backup process is passed as parameter to the extension script. 0 <=> OK, <>0 <=> failure

4) If you want to share your extension code just create a pull request on github where all the extension source code is available for sharing and update.

Add comment

Spam Kommentare sind sinnlos !
Vor der Publizierung wird jeder Beitrag auf Spam geprüft. Leider dauert es deswegen bis ein Kommentar sichtbar wird. Dafür erhält aber kein Subscriber Spam eMails.
Die eMail ist optional und nicht öffentlich sichtbar. Sie ist notwendig um eMail Benachrichtigungen zu Antworten auf Kommentare zu erhalten und wird u.U. genutzt um offline zu kommunizieren.

Spam comments are useless !
Any comment will be reviewed first and checked for spam. Unfortunately this delays the publishing of comments but will protect subscribers from spam.
eMail is optional and hidden and is required get update notifications for any comments and may be used to contact you offline


Comments   

0 #5 framp 2016-11-28 19:18
Hi Jason,

you're welcome. But please note: The current version has a bug and the failure rc is not passed to the extension. See my comment #3.

Cu framp
Quote
0 #4 Jason 2016-11-28 19:15
Quoting framp:
Hi Jason,

np. I will add another sample extension to the extension samples which calls scriptA when the backup succeeded and scriptB when it failed. I keep you posted :-)

Cu framp


awesome! Thank you for the response, and the fantastic script!
Quote
0 #3 framp 2016-11-27 12:12
Hi Jason,

I updated the extension samples with a sample called raspiBackup_exe cute_post.sh. In addition I noticed raspiBackup had to be updated in order to pass the rc to the extension. I created a patch based on v0.6.1.3b for you. Unfortunately you didn't provide your eMail in your comment so I'm not able to send you the patched version. Please use my eMail address on the contact page to send me your eMail or let me know how you want me to provide the patch to you.

Cu framp
Quote
0 #2 framp 2016-11-27 10:22
Hi Jason,

np. I will add another sample extension to the extension samples which calls scriptA when the backup succeeded and scriptB when it failed. I keep you posted :-)

Cu framp
Quote
0 #1 Jason 2016-11-27 01:14
Do you have a good example of an extension that triggers one of two scripts, based on success or failure? I can't seem to get one to work right...
Quote