How to Automate ESXi 3.5/4 Backups Using Free Tools: Scripting Snapshots and File Transfers


2 views

Unlike vSphere with its backup APIs, ESXi's free edition requires manual approaches. The fundamental process involves:

  1. VM snapshot creation (atomic state capture)
  2. File-level copy of VM disks (*.vmdk) and configs (*.vmx)
  3. Snapshot consolidation
# Minimal toolkit requirements:
1. ESXi SSH access (enable via DCUI or vSphere Client)
2. vCLI or PowerCLI for snapshot operations
3. SCP/rsync alternatives for file transfer
4. BusyBox cron for scheduling

Here's a working bash script using the VMware CLI:

#!/bin/bash
VM_NAME="prod-web-01"
BACKUP_DIR="/vmfs/volumes/NAS/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M)

# Create snapshot
vim-cmd vmsvc/getallvms | grep "$VM_NAME" | awk '{print $1}' | \
xargs -I {} vim-cmd vmsvc/snapshot.create {} "auto-backup-$TIMESTAMP"

# Backup critical files
find "/vmfs/volumes/datastore1/$VM_NAME" -type f $-name "*.vmx" -o -name "*.vmdk"$ \
-exec cp {} "$BACKUP_DIR/$VM_NAME-$TIMESTAMP" \;

# Remove snapshot
vim-cmd vmsvc/getallvms | grep "$VM_NAME" | awk '{print $1}' | \
xargs -I {} vim-cmd vmsvc/snapshot.remove {} $(vim-cmd vmsvc/snapshot.get {} | grep -A1 "auto-backup" | head -n1 | cut -d":" -f2)

ESXi's limited cron implementation requires manual config:

# Edit crontab
cat > /var/spool/cron/crontabs/root << 'EOF'
0 2 * * * /bin/sh /scripts/esxi-backup.sh > /var/log/backup.log 2>&1
EOF

# Apply changes
kill -HUP $(cat /var/run/crond.pid)
  • ghettoVCB: Community-developed bash script with delta backups
  • RCLONE: Statically compiled builds work on ESXi for cloud backups
  • OVF Tool: For exporting VMs in standard format
  • Snapshot chains can grow uncontrollably - always verify removal
  • BusyBox awk/grep variants may behave differently than GNU versions
  • File permissions must be preserved during transfers (use -p flag with SCP)



Backing up VMware ESXi 3.5/4 servers presents unique challenges due to their stripped-down Linux architecture. The absence of common utilities like rsync and cron requires creative solutions for automated VM protection.

The fundamental backup workflow for ESXi involves:

  • Creating VM snapshots through the vSphere CLI (vCLI)
  • Transferring VM files using SCP or alternative methods
  • Committing snapshots to maintain storage efficiency

You'll need these components for a complete solution:

  1. vSphere CLI (for ESXi 3.5/4 compatibility)
  2. SSH/SCP access (enabled via Tech Support Mode)
  3. Custom shell scripts for automation

Here's a basic framework for automating backups:

#!/bin/sh
# ESXi 3.5/4 Backup Script
VM_NAME="your_vm_name"
BACKUP_DIR="/vmfs/volumes/datastore1/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)

# Create snapshot
vim-cmd vmsvc/snapshot.create $(vim-cmd vmsvc/getallvms | grep "$VM_NAME" | awk '{print $1}') "Backup_$TIMESTAMP" "Automated backup snapshot" 1 1

# Copy VM files
scp -r /vmfs/volumes/datastore1/$VM_NAME backupuser@backupserver:$BACKUP_DIR/$VM_NAME-$TIMESTAMP

# Remove snapshot
vim-cmd vmsvc/snapshot.remove $(vim-cmd vmsvc/getallvms | grep "$VM_NAME" | awk '{print $1}') $(vim-cmd vmsvc/snapshot.get $(vim-cmd vmsvc/getallvms | grep "$VM_NAME" | awk '{print $1}') | grep -A1 'Snapshot Id' | tail -n1 | awk '{print $NF}')

Since ESXi lacks cron, consider these alternatives:

  • Run scripts from a management server using Scheduled Tasks
  • Use a lightweight cron implementation like busybox cron
  • Implement time-based triggers through a separate Linux host

For environments without SCP:

# Alternative using nc (netcat)
tar czf - /vmfs/volumes/datastore1/$VM_NAME | nc -l 1234
# On backup server:
nc esxi_host_ip 1234 | tar xzf - -C /backup/location

Remember these critical points:

  • Snapshots aren't backups - they're temporary points-in-time
  • Monitor snapshot growth to avoid storage depletion
  • Test restoration procedures regularly
  • Consider downtime requirements for transaction-consistent backups