2.1 KiB
2.1 KiB
vSphere Snapshot Backup Tool
Simple CLI to automate the snapshot -> copy -> compress -> delete workflow for a VM on vCenter/ESXi.
Requirements
- Python 3.8+
- See
requirements.txt(pyvmomi, requests, paramiko, zstandard)
Basic usage
python vsphere_backup.py --host vc.example.local --user administrator@vsphere.local --vm MyVM --dest /backups/MyVM --compress
Optional SFTP upload
python vsphere_backup.py --host vc.example.local --user admin --vm MyVM --dest /tmp/backups --sftp-host backup.example.com --sftp-user backup --sftp-password secret
Notes & caveats
- The script creates a snapshot on the VM and downloads the VM's
.vmdkand.vmxfiles from the datastore while the snapshot exists — do NOT copy.vmdkwithout snapshot. - The script attempts to use
zstd -19if available; otherwise it falls back to Pythonzstandard. - SSL verification is disabled with
--no-verify-sslfor convenience with self-signed vCenter/ESXi certs. - Test carefully in dev before using in production. This is a minimal DIY backup tool and does not replace a full backup product.
Web GUI
A Flask-based web interface to manage your backups, schedules, and NFS mounts.
Running with PM2 (Recommended for Linux production)
PM2 natively supports Python applications and can keep the server running across restarts.
-
Install PM2 (requires Node.js):
npm install -g pm2 -
Start the Web GUI: Using the provided
ecosystem.config.js:pm2 start ecosystem.config.js(Optional) If you are running inside a Python virtual environment (e.g.
venv), editecosystem.config.jsto uncomment and point theinterpreterto your venv's python executable:interpreter: './venv/bin/python3' -
Useful PM2 Commands:
- Status:
pm2 status - Logs:
pm2 logs vsphere-backup-gui - Restart:
pm2 restart vsphere-backup-gui - Stop:
pm2 stop vsphere-backup-gui - Setup auto-start on server boot:
pm2 startupand then run the command it outputs, followed bypm2 save.
- Status: