Skip to content

Preflight and Postflight scripts

François edited this page Jun 10, 2015 · 2 revisions

The WABAC Machine allows you to run a script before and after a backup.

Preflight and postflight scripts can be used to do a lot of things, such as :

  • Mounting/unmounting an external hard disk drive, a remote volume, a disk image or an encrypted volume ;
  • Pause, stop, or dump a database and restart it after ;
  • Parse the WABAC Machine log ;
  • Send reports ;
  • Shutdown or sleep a computer ;
  • ...

Setting up

Create your script, store it wherever you want, and test it.

Once you are sure it runs properly, edit your WABAC Machine configuration file and set the preflight and/or postflight preferences to their respective path.

For example, let's say I want to run /home/john/Shell/WABACMachin/preflight.sh as a preflight script, I would edit my configuration file like this :

preflight=/home/john/Shell/WABACMachin/preflight.sh

If you don't want to run a preflight / postflight script, just leave the preference empty.

Writing your scripts

Remember that your preflight script MUST return an exit code (zero if everything is OK). The WABAC Machine will only run if the preflight script returns 0 !

Here is a very small template that you can use :

#!/bin/bash

function whatever_you_want()
{
    local exit_code

    # Do whatever you want here
    # Important being that exit_code gets a suitable value.
    # exit_code = 0  means that everything ran well.
    # exit_code != 0 means that something wrong occurred, and the backup process will not run.

    return ${exit_code}
}

whatever_you_want

Tips

  • For further security, you should chmod 600 your scripts.
  • Remember that your scripts will most likely be run as root.
  • Remember that you can use some functions provided by the WABAC Tools.
  • Since the preflight and postflight scripts are included using source, you can also use the functions and variables defined in WABACMachine.sh (this includes the preferences set in your configuration file).
  • You can also decide to create another configuration file (eg. to store remote share information, ...) and use source in your scripts to import them.