Creating Automated vSphere Backup Environment Using Command Line Scripting
Important
Since Bacula version 16.0.7, a new solution has been introduced to replace the scan_datacenter tool. It is highly recommended to use the new solution - Automatic Objects Integration (Scan Plugin) as the scan_datacenter will soon be deprecated. See an example for vSphere.
There is a script called “scan_datacenter.pl” that is integral to BWeb’s “VMware Center” located in “/opt/bweb/bin”. In Step 4 of 4 in the BWeb Automated VMware Backups section of this document, we have already created an Admin type job called “Admin_AutoVM”, and scheduled it to run daily at 21:00.
If we take a look at this Job in BWeb (Configuration –> Director –> Jobs –> Admin_AutoVM), we can see that the scan_datacenter.pl script has been automatically configured to be called in a RunScript section of this Admin job. Runscripts are job resources that can run any shell script before or after a backup job or administrative task as in this case.
The scan_datacenter.pl script is called with some specific command line parameters that are used to create the new FileSets and Jobs for each VM found.
We can simply cut and paste this working example into a new custom script which can be run manually, run automatically via cron, or via a Bacula Admin type Job as in the Admin_AutoVM Admin Job example.
Here is the command in the Admin Job’s RunScript section as it was created by BWeb’s VMware Center’s “Backup multiple virtual machines wizard” in the previous section of this guide:
/bin/sh -c "perl -I'/opt/bweb/lib/' /opt/bweb/bin/scan_datacenter.pl
--server 'vcenter-65' --jobdefs 'DefaultJob' --job 'vsphere_%%v'
--fileset 'vsphere_%%v' --fs_option Signature=md5 --plugin_option
quiesce_host=try --plugin_option abort_on_error=1 --directive
Storage=File1 --directive Schedule=WeeklyFull --directive
Client=glb-almalinux9-tst-fd --directive Accurate=yes --description
'Generated from 'Admin_AutoVM'. Do not edit manually.' --remove_jobs
--commit_and_reload"
In this example, there are a number of command line options being used. For example, we can see that for the FileSet name and the Job name, each will be prefaced by “vmware_” - the name of the VM found. This means that each Job/FileSet pair will have the same name, making the correlation between Jobs and FileSets for each VM backup easy.
There are a few Job-specific “–directive” settings specified too. Importantly, “Accurate mode” is enabled for these Jobs - a requirement for Differential and Incremental VMware VM backups. For the “–directive” values, use the upper camel case (camel case with the first letter capitalised) writing method, for example:
--directive AllowDuplicateJobs=yes --directive SpoolSize=100000000
Also, we can see there are a few vSphere plugin-specific settings specified by using the “–plugin_option” command line parameter multiple times.
And finally, because this Admin type Job will run once per day at 21:00, there are two options specified so that new Jobs and FileSets are automatically committed to the Director’s configuration “–commit_and_reload”, and also, any VMs that no longer exist have their FileSet and Job resources removed from the Director’s configuration due to the “–remove_jobs” option.
A full listing of all available command line options to the scan_datacenter.pl script can be seen simply by running this script with no command line parameters.
The scan_datacenter.pl
script was introduced with BWeb
version 8.10. Interim versions required to download and install
the Perl SDK from VMware (not longer required from version 12.2.4).
See also
Go back to:
Go back to the main BWeb VMware Center Module page.
Go back to the main vSphere Plugin page.