Scheduling
cv4pve-autosnap takes one snapshot per guest each time it runs and has no scheduler of its own: the schedule is the one of your system. Run it from a machine outside the cluster that is always on (a management VM, a server of the monitoring), so the snapshots do not depend on a single node.
Put the connection in a parameter file
Section titled “Put the connection in a parameter file”The token should not be visible in the crontab or in the list of processes. Write the connection options in a file, one per line, readable only by the account that runs the job:
--host=pve1.local,pve2.local--api-token=autosnap@pve!snap=<uuid>--vmid=@tag-snapshotchmod 600 /etc/cv4pve/autosnap.confand pass it with @, followed by the command:
cv4pve-autosnap @/etc/cv4pve/autosnap.conf snap --label=daily --keep=7In a file the value needs no quotes. Global options such as --max-parallel can go in the file too. The
rules of the file are in Options in a file.
Schedules
Section titled “Schedules”# every 2 hours, keep one day0 */2 * * * cv4pve /usr/local/bin/cv4pve-autosnap @/etc/cv4pve/autosnap.conf snap --label=2hourly --keep=12 >> /var/log/cv4pve-autosnap.log 2>&1# every night at 01:30, keep one week30 1 * * * cv4pve /usr/local/bin/cv4pve-autosnap @/etc/cv4pve/autosnap.conf snap --label=daily --keep=7 >> /var/log/cv4pve-autosnap.log 2>&1# Sunday at 03:15, keep one month15 3 * * 0 cv4pve /usr/local/bin/cv4pve-autosnap @/etc/cv4pve/autosnap.conf snap --label=weekly --keep=4 >> /var/log/cv4pve-autosnap.log 2>&1Files in /etc/cron.d take the user as sixth field; here a dedicated cv4pve account that can read
the parameter file.
schtasks /Create /TN "cv4pve-autosnap daily" /SC DAILY /ST 01:30 /RU SYSTEM ` /TR "C:\cv4pve\cv4pve-autosnap.exe @C:\cv4pve\autosnap.conf snap --label=daily --keep=7"Protect C:\cv4pve\autosnap.conf so that only the account of the task can read it. To keep the output,
run the command through cmd /c "… >> C:\cv4pve\autosnap.log 2>&1".
Keep the schedules apart
Section titled “Keep the schedules apart”Proxmox VE locks a guest while it takes one of its snapshots: a second snapshot of the same guest at the same moment fails. Start the jobs of different labels at different minutes (in the example the daily job runs at 01:30 and the weekly at 03:15, never on the hour of the 2-hourly job) and leave each job the time to finish before the next one.
Before an upgrade
Section titled “Before an upgrade”The same command works by hand, right before a risky change, with a label of its own:
cv4pve-autosnap @/etc/cv4pve/connection.conf --vmid=1010 snap --label=preupgrade --keep=3An option can be given only once: if the parameter file already holds --vmid, a second one on the
command line stops the tool with Option '--vmid' expects a single argument but 2 were provided. Keep a
file with only the connection (--host, --api-token) for runs like this one.
Watch the result
Section titled “Watch the result”The exit code is 1 when a guest did not get its snapshot or its old ones were not removed: let your
scheduler or monitoring alert on it. For more than the exit code (a message to a chat, metrics to
Prometheus) use a hook script.