Proxmox VM Auto-Upgrade Script (qm + vzdump) with Network Tests and Auto-Restore

Proxmox VM Auto-Upgrade Script (qm + vzdump) with Network Tests and Auto-Restore

This article describes a simple (but effective) automation script for Proxmox VE that:

  • creates a backup of a VM (optional),
  • starts the VM if it was originally stopped,
  • runs apt upgrade + reboot inside the VM,
  • performs network tests before and after the update,
  • restores from backup automatically if tests fail (optional),
  • shuts down the VM again if it was originally stopped.

Where to download the script

You can download the script directly from my website:

soban.pl/bash/upgrade_proxmox_qm.sh

Required folders

Before you run anything, create two folders for scripts and logs:

Install the script

Download the file into /root/automate_scripts/ and make it executable:

How it works (high level)

  • Backup (vzdump snapshot + zstd) is executed first (if enabled).
  • If the VM was stopped, the script starts it and waits WAIT_TIME seconds.
  • Runs network tests BEFORE update:
  • Executes apt update/upgrade/dist-upgrade/autoremove/clean and finally reboots the VM.
  • Waits again (WAIT_TIME) and runs the same tests AFTER update.
  • If tests fail and a backup exists, it performs qmrestore automatically.
  • If the VM was originally stopped, it shuts down the VM at the end.

Usage

The script expects exactly two arguments:

  • VMID – the Proxmox VM ID
  • TIME_SEC – how long to wait after start/reboot (in seconds)

Tip: choose a WAIT_TIME that matches your VM boot time and apt upgrade duration. Typical values are 300 to 1000 seconds depending on the VM.

Full script (for reference)

If you prefer to keep everything in one place, below is the full script exactly as used in this setup:

Cron jobs (weekly schedule + per-VM logs)

Below is an example crontab that runs upgrades once a week (different VM each weekday) and writes separate logs to /root/logs/.

Edit root crontab:

Paste rules like these (comments in English):

Quick checks / troubleshooting

  • Make sure root can SSH into the VM by hostname (the script uses ssh root@<vm-hostname>).
  • Make sure DNS (or /etc/hosts) resolves the VM hostname correctly from the Proxmox host.
  • If apt needs user interaction, ensure your VMs are set up for non-interactive upgrades (or pin/hold packages that prompt).

That’s it. Drop the script into /root/automate_scripts/, send logs into /root/logs/, and your weekly VM maintenance becomes mostly fire-and-forget.