Last updated on Thursday 21st of April 2022 04:44:13 PM
©XSIBackup Using Regular Expressions
Use regexp to select or exclude items©XSIBackup allows to select VMs with a Regular Expression and also to add an exclude pattern via the --exclude argument also using some Regexp.
It uses the Regex functions in the regex.h C file: regcomp() and regexec(). These functions are somewhat limited when compared to the Regex engines that you can find in other languages, like Python, Bash, etc...
Still, it's more than enough to select VMs based on alphanumeric patterns, although the expressions to use are not always obvious if you are used to other common engines.
In this post we will cover how to select and exclude VMs and disks based on the built-in regex feature.
You define a Regular Expression inside the VMs() argument by prepending the select string with a [^] character.
Selecting _XSIREP virtual machinesIt is a common practice when using ©XSIBackup to replicate VMs to some server off-site or in your LAN network to then backup those VMs. That allows to have a hot site while also keeping an archive from which you can restore any VM from an extense repository of restore points. Using CBT is a great help, as that way the time it takes to sync your replicas is drastically reduced.
In this case you need to also use the --options=O argument to weave the _XSIREP filter, which prevents selecting this type of VMs by default.
Your backup command would look like this:
Please, note how we used the regular expression ^[a-zA-Z0-9]*_XSIREP instead of ^*._XSIREP, which is not valid and will select no VMs.
The used expression reads as: select any VM beginning by any number (*) of lower or upper case letters and numbers ([a-zA-Z0-9]) and ending in _XSIREP.
The above backup command will select all VMs ending in _XSIREP and back them up to a repository at /vmfs/volumes/backup/repo01
Select virtual machines by some patternSimilarly you can select any VM by a regular expression. It is important that you develop some naming scheme that allows to quickly identify VMs by their name. Per instance, you may name Windows VMs by prepending a "W" and use the rest of the name to denote some other characteristic, such as the system type, i.e.: W7001 could be used to name some Windows 7 virtual machine, being 001 a simple system number.
This way you can esily backup all Windows 7 virtual machines by using some regexp pattern like the one below.
Similarly Linux VMs could be prepended with "L" plus a two letter code for the distro type, i.e.: LDB001. This could identify some Linux Debian guest, or LRH002 for some Linux Red Hat and so on.
The above example would backup all Linux VMs no matter which type of distro they are.
Select multiple types at the same timeYou may want to combine multiple types of guests in a backup or replica group. To do so you need to use the [|] character as the OR logical operator.
The above example would select all Windows 7 (^W7) plus all Linux Debian (^LDB) VMs according to the proposed naming scheme.
Exclude regexp patterns©XSIBackup allows to define an --exclude regexp pattern to skip some files present in the VMs assigned to the backup job. In case of the --exclude argument you don't need to start the REGEXP with a [^] sign. You may per instance use the command below to replicate all Windows VMs and exclude their .log files from the replicas.
You will notice that the .log files are excluded and that some lines like this show up in the interactive log on screen while testing the job.