Source:Task Name Template – Backup: Difference between revisions
(In progress.) |
(Ready for review) |
||
Line 22: | Line 22: | ||
| style="padding:0px 40px 0px 10px; color: grey; font-size: 90%; text-align:left;" |If you have a problem, check the [[Special:MyLanguage/Troubleshooting_Guide|Troubleshooting Guide]]. | | style="padding:0px 40px 0px 10px; color: grey; font-size: 90%; text-align:left;" |If you have a problem, check the [[Special:MyLanguage/Troubleshooting_Guide|Troubleshooting Guide]]. | ||
|}</div></noinclude> | |}</div></noinclude> | ||
As of [[Special:MyLanguage/SEP_sesam_Release_Versions|4.4.3 ''Beefalo V2'']], SEP sesam | As of [[Special:MyLanguage/SEP_sesam_Release_Versions|4.4.3 ''Beefalo V2'']], SEP sesam supports a higher level of automation for performing administrative work by generating administrative objects, such as backup tasks, based on a given template. | ||
Templates can be created to allow SEP sesam administrators to automatically create backup tasks by replacing specific information with variables, thus saving time and simplifying backup management. Templates can be configured in the SEP sesam GUI -> ''Configuration'' -> ''Defaults'' -> ''Extras'' -> ''Template'', as described in [[Special:MyLanguage/4_4_3_Beefalo:Configuration#extras|GUI Configuration options: Extras]]. | |||
==Backup task name template | ==Backup task name template usage== | ||
SEP sesam used the ''Mustache'' specification for a templating language to auto-generate the name of backup tasks while creating the task using the UI server’s REST API. Due to some limitations of the ''Mustache'' template, SEP sesam introduced a more flexible and powerful ''Rythm'' template engine. | |||
The ''Rythm'' template engine has the following advantages: | |||
*Flexibility in writing template side code as it uses Java like syntax and allows embedding Java code snippets inside the template source. | |||
•Easy to integrate into an existing Java application. | |||
•Supports template inheritance as well as macros. | |||
•Handling of complex data types. | |||
The syntax used by ''Mustache'' to denote | ===Mustache syntax=== | ||
Currently, SEP sesam auto-generates the name of the backup task by using the ''Mustache'' specification for a templating language. For example, if the name property of the backup task is set to ''backup_task_<nowiki>{{client}}</nowiki>'' and the ''client'' property of the backup task evaluates to ''snowfix'', the UI server updates the name property of the backup task to ''backup_task_snowfix'' before committing this backup task to the database. | |||
The syntax used by ''Mustache'' to denote a placeholder for named property is: | |||
{{<property name>}} | {{<property name>}} | ||
The ''Rythm'' template engine uses different syntax. The full ''Rythm template source'' for achieving the same result is: | ===Rythm syntax=== | ||
The ''Rythm'' template engine uses a different syntax. The full ''Rythm template source'' for achieving the same result as in the example above is: | |||
@args String client | @args String client | ||
backup_task_@(client) | backup_task_@(client) | ||
{{note|There are no pre-configured templates available for customization. Until you configure a template, SEP sesam uses the default auto-generated names for bakup tasks.}} | |||
The | ==={{anchor|placeholder}}Using placeholders=== | ||
The following table lists placeholders that can be used in the backup task name template. | |||
{| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | {| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | ||
Line 49: | Line 59: | ||
! scope="col" | Description | ! scope="col" | Description | ||
|- | |- | ||
|<tt>client</tt> || <tt> | |<tt>client</tt> || <tt>string</tt>|| The name of the client associated with the backup task object. | ||
|- | |- | ||
|<tt>source</tt> || <tt> | |<tt>source</tt> || <tt>string</tt>|| The source property of the backup task object. | ||
|- | |- | ||
|<tt>count</tt> || <tt> | |<tt>count</tt> || <tt>string</tt>|| A number between 1 and 10000. Evaluates to the first number in this range leading to a unique task name. | ||
|- | |- | ||
|<tt>count_optional</tt> || <tt> | |<tt>count_optional</tt> || <tt>string</tt>|| Equals the ''count'' token which is used when a task already exists. | ||
|- | |- | ||
|<tt>task</tt> || <tt> | |<tt>task</tt> || <tt>tasks</tt>|| The backup task object.<br />'''''Note''': This placeholder can only be used together with a native Rythm template.'' | ||
|- | |- | ||
|} | |} | ||
==={{anchor|functions}} | ==={{anchor|functions}}Functions (''Mustache'' syntax only)=== | ||
The following transformation functions are supported when using the ''Mustache'' syntax. | |||
{{note|These functions cannot be combined when using ''Mustache''. If more complex transformations are required, use the ''Rythm'' syntax.}} | |||
{| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | {| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | ||
Line 89: | Line 100: | ||
|} | |} | ||
==={{anchor|examples}}Examples=== | ===={{anchor|examples}}Examples==== | ||
In our example, the following placeholder values are used: | In our example, the following placeholder values are used: | ||
Line 99: | Line 110: | ||
! scope="col" | Value | ! scope="col" | Value | ||
|- | |- | ||
|<tt>client</tt> || <tt> | |<tt>client</tt> || <tt>string</tt>|| <tt>SnowFix</tt> | ||
|- | |- | ||
|<tt>source</tt> || <tt> | |<tt>source</tt> || <tt>string</tt>|| <tt>C:\work\test</tt> | ||
|- | |- | ||
|<tt>count</tt> || <tt> | |<tt>count</tt> || <tt>string</tt>|| <tt>10</tt> | ||
|- | |- | ||
|} | |} | ||
=====Mustache===== | |||
Using the ''Mustache'' syntax, the templates will evaluate as follows. | |||
{| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | {| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | ||
Line 131: | Line 142: | ||
|} | |} | ||
=====Rythm===== | |||
Using the ''Rythm'' syntax, the templates will evaluate as follows. | |||
{| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | {| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #fcfcfc; border: 1px #aaa solid; border-collapse: collapse;" | ||
Line 147: | Line 157: | ||
==={{anchor|shortcuts}}Shortcuts for inner ''VMDto'' object=== | ==={{anchor|shortcuts}}Shortcuts for inner ''VMDto'' object=== | ||
You can easily access | You can easily access all field names of the task attribute ''VMDto'' by using shortcuts. Each shortcut represents a field name of the ''VMDto'' object. | ||
'''''Valid VMDto shortcuts:''''' | '''''Valid VMDto shortcuts:''''' | ||
Line 169: | Line 179: | ||
@(task.getShortType())_@(task.getSourceSegment(0))" -f d:\input.json -O remove_all -G vm-8 | @(task.getShortType())_@(task.getSourceSegment(0))" -f d:\input.json -O remove_all -G vm-8 | ||
==={{anchor|special_shortcuts}}Special shortcuts for | ==={{anchor|special_shortcuts}}Special shortcuts for easy access (without ''rhythm'' keywords)=== | ||
The ''Rythm'' syntax is not required when using special shortcuts | The ''Rythm'' syntax is not required when using special shortcuts in tags – curly braces, i.e., <tt>{{<shortcut>}}</tt>. | ||
'''''The name generation shortcuts''''' | '''''The name generation shortcuts''''' | ||
Line 180: | Line 190: | ||
! scope="col" | Description | ! scope="col" | Description | ||
|- | |- | ||
|<tt><nowiki>{{CLIENT_SHORT}}</nowiki></tt> || | |<tt><nowiki>{{CLIENT_SHORT}}</nowiki></tt> || get client without domain | ||
|- | |- | ||
|<tt><nowiki>{{TASK_TYPE_SHORT}}</nowiki></tt> || | |<tt><nowiki>{{TASK_TYPE_SHORT}}</nowiki></tt> || get short name of task type | ||
|- | |- | ||
|<tt><nowiki>{{SOURCE_LAST_ITEM}}</nowiki></tt> || | |<tt><nowiki>{{SOURCE_LAST_ITEM}}</nowiki></tt> || get last source segment separated by slash | ||
|- | |- | ||
|<tt><nowiki>{{SOURCE_ITEM[<pos>]}}</nowiki></tt> || | |<tt><nowiki>{{SOURCE_ITEM[<pos>]}}</nowiki></tt> || get segment pos separated by slash (negative pos as pos from back) | ||
|- | |- | ||
|<tt><nowiki>{{<field>}}</nowiki></tt> || | |<tt><nowiki>{{<field>}}</nowiki></tt> || use the description block field (''cli action dir last param'').<br /> | ||
''Example:'' | ''Example:'' | ||
<nowiki>{{uuid}}</nowiki>Status=Running,OwnerNode=HYPERVDEV,Clustered=No,uuid=2E4120B2-C0FC-4D99-8737-21EC5C9D7BC | <nowiki>{{uuid}}</nowiki>Status=Running,OwnerNode=HYPERVDEV,Clustered=No,uuid=2E4120B2-C0FC-4D99-8737-21EC5C9D7BC | ||
'''''Note''''': You can use all description fields (''UUID'', ''folder'', ''Guest OS'',...) from output of the list (<tt>-f -</tt>) for | '''''Note''''': You can use all description fields (''UUID'', ''folder'', ''Guest OS'',...) from output of the list (<tt>-f -</tt>) for task name. | ||
|} | |} | ||
'''''Examples''''' | '''''Examples''''' | ||
<ul><li>Backup task with | <ul><li>Backup task with type ''Hypervdev'' from input stream:</li> | ||
<nowiki>sm_cmd dir -F JSON client "/hypervdev.sep.de/Hyper-V:" | sm_cmd add taskgen "gen_{{TASK_TYPE_SHORT}}_{{SOURCE_ITEM[1]}}-{{SOURCE_ITEM[-1]}}-{{uuid}}" "-t" "Hyper-V" –c hypervdev.sep.de -f - -O remove_all -G hv-5</nowiki> | <nowiki>sm_cmd dir -F JSON client "/hypervdev.sep.de/Hyper-V:" | sm_cmd add taskgen "gen_{{TASK_TYPE_SHORT}}_{{SOURCE_ITEM[1]}}-{{SOURCE_ITEM[-1]}}-{{uuid}}" "-t" "Hyper-V" –c hypervdev.sep.de -f - -O remove_all -G hv-5</nowiki> | ||
<li>Backup task with | <li>Backup task with type ''Hypervdev'' from file:</li> | ||
<nowiki>sm_cmd add taskgen "gen_{{TASK_TYPE_SHORT}}_{{SOURCE_ITEM[1]}}-{{SOURCE_ITEM[-1]}}-{{uuid}}" "-t" "Hyper-V" -c hypervdev.sep.de -f d:\hyperv.json -O remove_all -G hv-5</nowiki> | <nowiki>sm_cmd add taskgen "gen_{{TASK_TYPE_SHORT}}_{{SOURCE_ITEM[1]}}-{{SOURCE_ITEM[-1]}}-{{uuid}}" "-t" "Hyper-V" -c hypervdev.sep.de -f d:\hyperv.json -O remove_all -G hv-5</nowiki> | ||
<li>Backup task with | <li>Backup task with type ''Path'' from file:</li> | ||
<nowiki>sm_cmd add taskgen "{{CLIENT_SHORT}}-{{TASK_TYPE_SHORT}}_{{SOURCE_LAST_ITEM}}" -G pathgroup -f c:\root\path.json –t “Path”</nowiki> | <nowiki>sm_cmd add taskgen "{{CLIENT_SHORT}}-{{TASK_TYPE_SHORT}}_{{SOURCE_LAST_ITEM}}" -G pathgroup -f c:\root\path.json –t “Path”</nowiki> | ||
</ul> | </ul> | ||
<noinclude> | <noinclude> | ||
==See also== | ==See also== | ||
[[Special:MyLanguage/4_4_3_Beefalo:Configuration#extras|GUI Configuration options: Extras]]</noinclude> | [[Special:MyLanguage/4_4_3_Beefalo:Configuration#extras|GUI Configuration options: Extras]]</noinclude> |
Revision as of 14:46, 22 October 2020
Overview
As of 4.4.3 Beefalo V2, SEP sesam supports a higher level of automation for performing administrative work by generating administrative objects, such as backup tasks, based on a given template.
Templates can be created to allow SEP sesam administrators to automatically create backup tasks by replacing specific information with variables, thus saving time and simplifying backup management. Templates can be configured in the SEP sesam GUI -> Configuration -> Defaults -> Extras -> Template, as described in GUI Configuration options: Extras.
Backup task name template usage
SEP sesam used the Mustache specification for a templating language to auto-generate the name of backup tasks while creating the task using the UI server’s REST API. Due to some limitations of the Mustache template, SEP sesam introduced a more flexible and powerful Rythm template engine.
The Rythm template engine has the following advantages:
- Flexibility in writing template side code as it uses Java like syntax and allows embedding Java code snippets inside the template source.
•Easy to integrate into an existing Java application. •Supports template inheritance as well as macros. •Handling of complex data types.
Mustache syntax
Currently, SEP sesam auto-generates the name of the backup task by using the Mustache specification for a templating language. For example, if the name property of the backup task is set to backup_task_{{client}} and the client property of the backup task evaluates to snowfix, the UI server updates the name property of the backup task to backup_task_snowfix before committing this backup task to the database.
The syntax used by Mustache to denote a placeholder for named property is:
{{<property name>}}
Rythm syntax
The Rythm template engine uses a different syntax. The full Rythm template source for achieving the same result as in the example above is:
@args String client backup_task_@(client)
Note | |
There are no pre-configured templates available for customization. Until you configure a template, SEP sesam uses the default auto-generated names for bakup tasks. |
Using placeholders
The following table lists placeholders that can be used in the backup task name template.
Name | Type | Description |
---|---|---|
client | string | The name of the client associated with the backup task object. |
source | string | The source property of the backup task object. |
count | string | A number between 1 and 10000. Evaluates to the first number in this range leading to a unique task name. |
count_optional | string | Equals the count token which is used when a task already exists. |
task | tasks | The backup task object. Note: This placeholder can only be used together with a native Rythm template. |
Functions (Mustache syntax only)
The following transformation functions are supported when using the Mustache syntax.
Note | |
These functions cannot be combined when using Mustache. If more complex transformations are required, use the Rythm syntax. |
Name | Description |
---|---|
toLower | Converts all characters in the placeholder value to lower case. |
toUpper | Converts all characters in the placeholder value to upper case. |
dashPrefix | Prepends a dash character (-) to the placeholder value, if the value is not blank. |
dotPrefix | Prepends a dot character (.) to the placeholder value, if the value is not blank. |
underPrefix | Prepends an underscore character (_) to the placeholder value, if the value is not blank. |
substring (start,end) | Evaluates to a string that is a substring of the string representation of the placeholder value. The character indices start with 0. |
replace (target,replacement) | Evaluates to a string where the target character sequence is replaced by the replacement character sequence. |
trimUnderPrefix | Removes any leading underscore character (_) from the placeholder value. |
trimUnderTrailing | Removes any trailing underscore character (_) from the placeholder value. |
Examples
In our example, the following placeholder values are used:
Name | Type | Value |
---|---|---|
client | string | SnowFix |
source | string | C:\work\test |
count | string | 10 |
Mustache
Using the Mustache syntax, the templates will evaluate as follows.
Name | Value |
---|---|
sep-task-{{client}} | sep-task-SnowFix |
sep-task-{{toLower client}} | sep-task-snowfix |
sep-task-{{toUpper client}} | sep-task-SNOWFIX |
sep-task-{{client}}-{{source}} | sep-task-SnowFix_C_work_test |
sep-task-{{client}}-{{substring(3,7) source}} | sep-task-SnowFix-work |
sep-task-{{client}}-{{replace("test","folder") source}} | sep-task-SnowFix_C_work_folder |
sep-task{{underPrefix count}} | sep-task_10 |
sep-task{{dashPrefix count_optional}} | sep-task (not exist) sep-task-0 (already exists) |
Rythm
Using the Rythm syntax, the templates will evaluate as follows.
Name | Value |
---|---|
@args String client\ntasks_rythm_@(client) | tasks_rythm_SnowFix |
@args String client, String source\ntasks_rythm_@(client.toLowerCase())_@(source.substring(3,7).toUpperCase()) | tasks_rythm_snowfix_WORK |
Shortcuts for inner VMDto object
You can easily access all field names of the task attribute VMDto by using shortcuts. Each shortcut represents a field name of the VMDto object.
Valid VMDto shortcuts: name, isVCenter, path, datacenter, moref, powerState, ipAddress, hostName, macAddress, hostSystem, cluster, version, guestFullName, uuid, sesamClient, folder, vapp, taskGroupRef, hostVersion
Example:
add task "@args de.sep.sesam.model.dto.VMDto vmDto;@ deb_ (vmDto.getMoRef())" …
is the same as
add task "@args String moref;deb_@(moref)"…
Example with GetAttribute:
add taskgen "@args de.sep.sesam.model.dto.FileDto fileDto;@(fileDto.getAdditionalInformationAsMap().get(\"Status\"))" "-c" "hypervdev" "-t" "Hyper-V" -s hyperV -f "c:\tmp\hyperv.txt" -G "hyperVGenGroup3
add taskgen "@args de.sep.sesam.model.Tasks task;qs-@(task.getClient().getShortName())- @(task.getShortType())_@(task.getSourceSegment(0))" -f d:\input.json -O remove_all -G vm-8
Special shortcuts for easy access (without rhythm keywords)
The Rythm syntax is not required when using special shortcuts in tags – curly braces, i.e., {{<shortcut>}}.
The name generation shortcuts
Shortcut | Description |
---|---|
{{CLIENT_SHORT}} | get client without domain |
{{TASK_TYPE_SHORT}} | get short name of task type |
{{SOURCE_LAST_ITEM}} | get last source segment separated by slash |
{{SOURCE_ITEM[<pos>]}} | get segment pos separated by slash (negative pos as pos from back) |
{{<field>}} | use the description block field (cli action dir last param). Example: {{uuid}}Status=Running,OwnerNode=HYPERVDEV,Clustered=No,uuid=2E4120B2-C0FC-4D99-8737-21EC5C9D7BC Note: You can use all description fields (UUID, folder, Guest OS,...) from output of the list (-f -) for task name. |
Examples
- Backup task with type Hypervdev from input stream: sm_cmd dir -F JSON client "/hypervdev.sep.de/Hyper-V:" | sm_cmd add taskgen "gen_{{TASK_TYPE_SHORT}}_{{SOURCE_ITEM[1]}}-{{SOURCE_ITEM[-1]}}-{{uuid}}" "-t" "Hyper-V" –c hypervdev.sep.de -f - -O remove_all -G hv-5
- Backup task with type Hypervdev from file: sm_cmd add taskgen "gen_{{TASK_TYPE_SHORT}}_{{SOURCE_ITEM[1]}}-{{SOURCE_ITEM[-1]}}-{{uuid}}" "-t" "Hyper-V" -c hypervdev.sep.de -f d:\hyperv.json -O remove_all -G hv-5
- Backup task with type Path from file: sm_cmd add taskgen "{{CLIENT_SHORT}}-{{TASK_TYPE_SHORT}}_{{SOURCE_LAST_ITEM}}" -G pathgroup -f c:\root\path.json –t “Path”