Last updated on Monday 28th of February 2022 08:52:48 PM

©XSIBackup, Advanced cron: alternatives to xsibackup-cron

 Please note that this post is relative to old deprecated software ©XSIBackup-Classic. Some facts herein contained may still be applicable to more recent versions though.

For new instalations please use new ©XSIBackup which is far more advanced than ©XSIBackup-Classic.

Take on account that since v. 11.0.0 ©XSIBackup uses the ESXi crontab. This post was written to overcome some older ©XSIBackup limitations when it would run on its own crontab.

You can nevertheless apply the same general concepts, should you want ©XSIBackup be run from some external centralized crontab.

Some users have more complex scheduling requirements than what can be achieved with a combination of weekday and time, this post is for them.

©XSIBackup's crontab file (xsibackup-cron) is a way to schedule weekly backups, ranging from "once a week" to "every day" schedules. This covers the vast majority of user's needs and allows to keep cron programming simple. Nevertheless, there are cases in which some Sysadmin wants to configure a scheduled task that goes beyond what can be easily achieved with ©XSIBackup's default scheduling system.

Let's say that you want to configure a backup to be run every hour. It might be a small VM that we might want to backup or a OneDiff diff backup to keep a mirror VM in sync. In this particular scenarios performing an hourly backup may be perfectly feasible and reasonable. So, let's delve into the different options we have when we need to get out of the road.

You have basically two options to program more flexible schedules: one of them is to change ©XSIBackup's date mask to accomodate your needs, the second option is to use ESXi's root crontab directly.

1) Change ©XSIBackup's date mask:

©XSIBackup uses time stamps in the form "Mon 13:23" that are matched against the same pattern for the current time. The xsibackup-cron file is called every minute from the ESXi's crontab at /var/spool/cron/crontabs/root and if any of the configured times is matched at any backup job line, then XSIBackup execution is performed. The [Day Of Week]+[Time] is coded into the string parsed to the date function (+"%a %H:%M"). To tweak this, you must change this string to any value supported by the Linux date function.

#!/bin/sh
#################################################################################
#
# ©XSIBACKUP Automated Backups for ESXi 5.1, 5.5, 6.0 & 6.5
# By Daniel J. Garcia Fidalgo (33hops.com) daniel.garcia@33hops.com
# Copyright ©2013-2017 | 33HOPS, Sistemas de Informacion y Redes, S.L.
# ALL RIGHTS RESERVED
#
#################################################################################

*NOW="$( date +"%a %H:%M" | awk '{print tolower($0)}' )"
hash -r
keyvalstr="$@"
CURRDIR=$(dirname $0)


Once you have accomplished the above, just use the same mask to define --time in your xsibackup-cron file. Let's use an example to concrete the described procedure into something more tangible:

You may use the following date stamp: date +"%M" for the (*)NOW (Please, note that the asterisk sign is not part of the source code, just a way to highlight the NOW variable) variable, that will give you the minute of the hour. If you then configure your xsibackup-cron file to run a job with a --time argument like the one shown below, you will get your cron to execute the job every time the minutes of the hour are "00", and thus you'll be executing the job every hour on the "00" minute. You can use any minute from 00 to 59 to have your backup executed that minute every hour.
/vmfs/volumes/datastore1/xsibackup-dir/xsibackup backupId=00 --time="00" --backup-room=1000 --date-dir=yes --backup-point="/vmfs/volumes/backup3" --backup-type=custom --backup-vms="W1001,LIN03" --mail-to=daniel@33hops.com --use-smtp=1


2) Use ESXi root crontab:

You can also use the ESXi's crontab to execute your ©XSIBackup jobs. This is fairly easy: first of all just test your backup job interactively and add it to a text file, you can name it however you want and you must place it in a persistent path. Future versions of ©XSIBackup will use the xsi-dir/conf/jobs as the steady path to store this kind of files, so please stick to it. We'll use the file xsi-dir/conf/jobs/my-backup.job, this file needs to be executable for the ESXi cron to be able to run it, so you'll need to change its permissions this way:

# chmod 0700 /vmfs/volumes/datastore1/xsi-dir/conf/jobs/my-backup.job


Once your backup job has been tested (you never know if a sequence of commands contains any errors until you test it) you can place it to the above file adding the additional argument --exec=yes at the end of the backup job line. This last argument is fundamental for the ESXi's cron to execute the job.

Now that you have the backup job ready to be triggered, just edit the ESXi's root crontab in the path /var/spool/cron/crontabs/root and add the job as you would do in any other Linux or Unix environment. ATENTION: please note that the /var/spool/cron/crontabs/root file does not have write permissions by default, so you will need to change them before editing it, otherwise you won't be able to save the modifications you make.