Job scheduling under ESXi 6

Fonte: ARDITI - WIKI
Saltar para a navegação Saltar para a pesquisa

Reference: https://apice.unibo.it/xwiki/bin/view/Apice/esxi6Scheduling

It’s necessary, in order to schedule a job, to modify manually root’s crontab and make changes durable after a reboot auto-generating the change on the crontab.

Example: Make daily snapshot of a particular Guest Server

Create a script in /vmfs/volumes/datastore1/scripts named feto-snapshot.sh

#!/bin/sh
#Number of sbapshots to retain
snapshotretain=8
echo SnapshotRetain $snapshotretain
# Get id of VM named Feto
vmid=$(vim-cmd vmsvc/getallvms | grep Feto | awk '{print $1}')
#Create new snapshot
vim-cmd vmsvc/snapshot.create $vmid backup 'Snapshot created by feto-snapshot.sh Script' 0 0
vim-cmd vmsvc/snapshot.get $vmid
#Number of existing snapshot
snapshotcnt=$(vim-cmd vmsvc/snapshot.get $vmid | grep "Snapshot Id" | wc -l)
echo SnapshotCount $snapshotcnt
#Number of snapshots to delete
snapshotdelete=$(($snapshotcnt - $snapshotretain))
#Delete snapshots
echo SnapshotDelete $snapshotdelete
while [ $snapshotdelete -gt 0 ]
do
  sid=$(vim-cmd vmsvc/snapshot.get $vmid | grep "\-\-Snapshot Id" | head -1 | awk '{print $4}')
  echo DeleteSnapshotID $sid
  vim-cmd vmsvc/snapshot.remove $vmid $sid
  snapshotdelete=$(($snapshotdelete - 1))
done

Add the crontab line to /var/spool/cron/crontabs/root

#min hour day mon dow command
1    1    *   *   *   /sbin/tmpwatch.py
1    *    *   *   *   /sbin/auto-backup.sh
0    *    *   *   *   /usr/lib/vmware/vmksummary/log-heartbeat.py
*/5  *    *   *   *   /sbin/hostd-probe ++group=host/vim/vmvisor/hostd-probe
00   1    *   *   *   localcli storage core device purge
14 4 * * * /vmfs/volumes/datastore1/scripts/feto-snapshot.sh > /vmfs/volumes/datastore1/scripts/feto-snapshot.log 2>&1

To activate changes

Run the command ps | grep crond or cat /var/run/crond.pid to identify cron daemon’s PID.
Run the command kill <pid> using crond’s PID to kill the process.
Run the command crond or busybox crond to load again the cron daemon, causing to install automatically the new crontab.