More Musings

WAL VM System backup script

This is a generic to be edited as may be desired.

My initial backup of the entire system, including virtual machines and the proxmox system itself all fitted easily onto a 64 GB USB stick: to my surprise.

Proxmox VM Backup Script

This Bash script creates backups of selected VMs on your Proxmox VE host using vzdump.

Features

  • Selective VM backup
  • Gzip compression
  • Daily timestamped folders
  • Logs actions to file

Script

“`bash

!/bin/bash

Configuration

BACKUP_DIR=”/mnt/backup/proxmox”

LOG_FILE=”/var/log/proxmox_backup.log”

DATE=$(date +%F)

VM_IDS=(“100” “110” “120”) # Add your VM IDs here

mkdir -p “BACKUP_DIR/DATE”

echo “=== Starting Proxmox Backup: DATE ===" >> "LOG_FILE”

for VMID in “${VM_IDS[@]}”; do

echo “Backing up VM VMID..." | tee -a "LOG_FILE”

vzdump $VMID \

--mode snapshot \
--compress gzip \
--dumpdir "$BACKUP_DIR/$DATE" \
--mailnotification always \
--mailto root@localhost \
>> "$LOG_FILE" 2>&1

done

echo “=== Backup Completed: DATE ===" >> "LOG_FILE”

Usage

•	Save the script as /usr/local/bin/proxmox_backup.sh
•	Make it executable:

chmod +x /usr/local/bin/proxmox_backup.sh

•	Schedule with cron (crontab -e):

0 2 * * * /usr/local/bin/proxmox_backup.sh

Notes

•	Make sure the target BACKUP_DIR has sufficient space.
•	You can change the backup mode from snapshot to stop or suspend if needed.