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

©ESXi Cron Programming - How to use the extended ©XSIBackup Classic crontab to run any task

 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.

Since version 11.0.0 this post is irrelevant, as ©XSIBackup Classic uses the ©ESXi crontab which offers full crontab flexibility. We'll keep it for users of versions below 11.0.0


The ©ESXi cron is a very limited service provided by Busybox, which crontab is not even persistent across host reboots. This is quite annoying for the more experienced sysadmins, who are willing to take control of the server.

The only way to workaround this issue is to add the cron commands to a startup script, which in turn adds then to the crontab. This is extremely cumbersome and very unpractical. This is the method that ©XSIBackup Classic uses to install its crontab, although in this case the process is automated and just takes a short command and a key stroke from part of the user.

Once ©XSIBackup Classic has installed its crontab, you may add backup jobs there, which will be executed at the scheduled times. As most crontabs, ©XSIBackup Classic's is called every minute, and if there's something to do, a backup job is triggered. You can add other bash commands into this file, in fact it's a bash file, but, if you do so, those commands will be executed every minute.

We have added some simple logic to this crontab so that you can use it to run any script or program of your choice, including of course ©XSIBackup Classic jobs. ©XSIBackup Classic's crontab syntax is simpler than that of regular Linux crontabs, and much more intuitive. It allows you to set execution times in two different ways or fashions:

1 - By weekday, hour and minute, i.e.: "Fri 17:03", where Fri is the weekday acronym followed by hh:mm

2 - By day of the month, hour and minute, i.e.: "17t20:33", where 17 is a month day and t is a constant, followed by hh:mm

©XSIBackup Classic's crontab is designed to execute recurring tasks, so by combining weekly and monthly options, you can easily program almost anything you may need.

This is an extended xsibackup-cron file that you can use to extend its functionality, it will be added as an option in next ©XSIBackup Classic version.

#!/bin/sh

# This is your XSIBackup crontab, you can add your backup schedules here
# You can use regular XSIBackup commands appending the parameter --time="Day HH:mm", i.e. --time="Mon 21:57"
# The --time format is compounded by three letters weekday acronym (Mon,Tue,Wed,Thu,Fri,Sat,Sun) + space + hh:mm
# You can also use --time strings with the syntax "MMthh:mm", where MM is a two digit month day, t is a constant,
# hh is a two digit hour and mm is a two digit minute. Two digit means you must use zeros to the left where needed.
# You can add multiple "moments" in a --time argument separated by a pipeline | like: 16t13:46|Tue 21:33|Sun 19:21
#
# Example:
# /vmfs/volumes/datastore1/xsibackup-dir/xsibackup backupId=00X \
# --time="Mon 02:00|Tue 02:00|Wed 02:00|Thu 02:00|Fri 02:00|Sat 02:00|Sun 02:00" \
# --date-dir=yes --backup-point="/vmfs/volumes/backup4" --backup-type=custom \
# --backup-vms="WDES01,CRM,LCENT64,LCENT53" --mail-to=daniel@33hops.com --debug-info=yes \
# --use-smtp=1 --on-success="backupid->01" --on-error="backupid->01"
#
#
# Run other tasks:
# Uncomment some line below to run any script or command of your choice
#
# run_this_at="Fri 17:53"
# run_this_at="16t18:04"
#
#
if [ "$run_this_at" != "" ]
then
if [ "$run_this_at" == "$( date +"%a %H:%M" )" -o "$run_this_at" == "$( date +%d't'%H':'%M )" ]
then
# Place the call to your scripts or commands here
echo "HELLO WORLD!"
# You can also add XSIBackup jobs, omitting the --time argument
# Make sure you add the --exec=yes directive at the end of the backup
# job string to force XSIBackup to run, this is not optional
# They will be chained by their --on-success and --on-error arguments
# Be careful not to duplicate backup Ids, jobs here will be considered
fi
fi