Script API: Difference between revisions

From wiki.zmanda.com
Jump to navigation Jump to search
No edit summary
 
(reorganize examples, change _ to -, general editing)
Line 1: Line 1:
==Introduction==
==Introduction==
Pre&Post script are use to execute script before or after amanda command, they can be executed on the client or server, once for each DLE or once for each client.
Pre- and post-scripts are use to execute scripts before or after certain amanda commands.  The scripts can be executed on the client or server, once for each [[DLE]] or once for each client host. Uses for pre- and post-scripts include:
* to stop and start database servers so that the binary backup is consistent
* to take a snapshot of a database
* to send emails or other notifications


= Script calling convention =
= Script calling convention =
This is subject to change
This is subject to change
   /path/to/script [execute_on]+ [--config <config>] [--host <host>] [--disk <disk>] [--device <device>]
   /path/to/script [execute-on]+ [--config <config>] [--host <host>] [--disk <disk>] [--device <device>]
 
   input of fd0:
   input of fd0:
     tool property
     tool property (format TBD)
   output on fd1
   output on fd1
     free format, will go to the amanda debug file.
     free format, will go to the amanda debug file.


execute_on can be one or many of:
execute-on is a comma-separated list of one or more words of the form <tt>(pre|post)-(dle|host)-(selfcheck|estimate|backup)</tt>.  The whole list is:
   pre-dle-selfcheck
   pre-dle-selfcheck
   pre-host-selfcheck
   pre-host-selfcheck
Line 24: Line 27:
   post-dle-backup
   post-dle-backup
   post-host-backup
   post-host-backup
Disk and device are provided only if the script is executed for a DLE.
The disk and device arguments to the script are provided only if the script is executed for a DLE.
 
Pre- and post-scripts are part of the [[Application API]].


=How to use=
=How to use=
== The script must be defined in amanda.conf ==
Scripts are defined in amanda.conf, and then referenced from a dumptype.
 
== Define the script in amanda.conf ==
Define the "my_script" script using the "myscript" binary.
Define the "my_script" script using the "myscript" binary.
   define script-tool my_script {
   define script-tool my-script {
    "script-base"                      # inherit config of the script-base script-tool
     comment "a comment"
     comment "a comment"
    "my_script"                      # inherit config of the my_app application
     plugin  "myscript"                # filename of the script, in the dumper dir
     plugin  "myscript"                # name of the application, it must be installed in dumper dir
     execute-where server              # or client
     execute_where server              # or client
     execute-on   pre-dle-backup
     execute_on   pre-dle-backup
     property "mailto" "amandabackup"  # can set arbitrary properties
     property "mailto" "amandabackup"  # can set property
  }
== Use the script in a dumptype ==
Reference the script-tool with the <tt>script</tt> parameter:
  define dumptype user-tar-scripted {
    user-tar
    script "my-script"
   }
   }
The dumptype must specify the script to use
Note that the dumptype declaration ''must'' be below the script-tool declaration in the configuation file.


== script-email example ==
== Email example ==
   define script-tool sc-email {
   define script-tool sc-email {
     comment "script-email"
     comment "email me before this DLE is backed up"
     plugin  "script-email"
     plugin  "script-email"
     execute_on pre-dle-backup
     execute-on pre-dle-backup
     execute_where server                 # or client
     execute-where server
     property "mailto" "martinea"
     property "mailto" "martinea"
   }
   }
your dumptype must include: script "sc-email"
   define dumptype user-tar-email {
   define dumptype user-tar-email {
     user-tar
     user-tar
     script "sc-email"
     script "sc-email"
   }
   }
== Complex Examples ==
Just as you can include dumptypes in a DLE, you can include script-tool definitions in a dumptype:


   define dumptype user-tar-email2 {
   define dumptype user-tar-email2 {
Line 57: Line 73:
     script {
     script {
       "sc-email"
       "sc-email"
       execute_where client
       execute-where client
       execute_on   post-dle-backup, post-host-estimate
       execute-on   post-dle-backup, post-host-estimate
     }
     }
   }
   }
Your DLE entry must use the user-tar-email or user-tar-email2 dumptype
 
You can even combine all of this in a [[DLE]]:
 
myhost /my/disk {
    user-tar
    script {
      "sc-email"
      execute-where client
      execute-on    post-dle-backup, post-host-estimate
    }
} -1 local

Revision as of 14:48, 23 February 2008

Introduction

Pre- and post-scripts are use to execute scripts before or after certain amanda commands. The scripts can be executed on the client or server, once for each DLE or once for each client host. Uses for pre- and post-scripts include:

  • to stop and start database servers so that the binary backup is consistent
  • to take a snapshot of a database
  • to send emails or other notifications

Script calling convention

This is subject to change

 /path/to/script [execute-on]+ [--config <config>] [--host <host>] [--disk <disk>] [--device <device>]

 input of fd0:
   tool property (format TBD)
 output on fd1
   free format, will go to the amanda debug file.

execute-on is a comma-separated list of one or more words of the form (pre|post)-(dle|host)-(selfcheck|estimate|backup). The whole list is:

 pre-dle-selfcheck
 pre-host-selfcheck
 post-dle-selfcheck
 post-host-selfcheck
 pre-dle-estimate
 pre-host-estimate
 post-dle-estimate
 post-host-estimate
 pre-dle-backup
 pre-host-backup
 post-dle-backup
 post-host-backup

The disk and device arguments to the script are provided only if the script is executed for a DLE.

Pre- and post-scripts are part of the Application API.

How to use

Scripts are defined in amanda.conf, and then referenced from a dumptype.

Define the script in amanda.conf

Define the "my_script" script using the "myscript" binary.

 define script-tool my-script {
    "script-base"                       # inherit config of the script-base script-tool
    comment "a comment"
    plugin  "myscript"                # filename of the script, in the dumper dir
    execute-where server              # or client
    execute-on    pre-dle-backup
    property "mailto" "amandabackup"  # can set arbitrary properties
 }

Use the script in a dumptype

Reference the script-tool with the script parameter:

 define dumptype user-tar-scripted {
   user-tar
   script "my-script"
 }

Note that the dumptype declaration must be below the script-tool declaration in the configuation file.

Email example

 define script-tool sc-email {
   comment "email me before this DLE is backed up"
   plugin  "script-email"
   execute-on pre-dle-backup
   execute-where server
   property "mailto" "martinea"
 }

 define dumptype user-tar-email {
   user-tar
   script "sc-email"
 }

Complex Examples

Just as you can include dumptypes in a DLE, you can include script-tool definitions in a dumptype:

 define dumptype user-tar-email2 {
   user-tar
   script {
     "sc-email"
     execute-where client
     execute-on    post-dle-backup, post-host-estimate
   }
 }

You can even combine all of this in a DLE:

myhost /my/disk {
   user-tar
   script {
     "sc-email"
     execute-where client
     execute-on    post-dle-backup, post-host-estimate
   }
} -1 local