Backup VMware ESXi to Linux with ZFS
Lowest budget backups for your free VMware ESXi hypervisor.
- Install ZFS support
apt-add-repository -y ppa:zfs-native/stable
apt-get update
apt-get -y install ubuntu-zfs
- Create RAID-Z2 (double parity) zpool
zpool create data raidz2 \
/dev/disk/by-id/ata-ST31000340NS_9QJ6ZHJJ \
/dev/disk/by-id/ata-ST31000340NS_9QJ718FG \
/dev/disk/by-id/ata-WDC_WD1002FBYS-02A6B0_WD-WMATV7379900 \
/dev/disk/by-id/ata-WDC_WD10EACS-00ZJB0_WD-WCASJ0857564 \
/dev/disk/by-id/ata-WDC_WD10EACS-00ZJB0_WD-WCASJ0945918 \
-o ashift=12 -o failmode=continue
- Create filesystem with compression (and deduplication if you feel brave)
zfs set atime=off data
zfs create data/backup
zfs set compression=on data/backup
#zfs set dedup=on data/backup
- Install NFS server
apt-get -y install nfs-kernel-server
- Export new ZFS filesystem to VMware ESXi
mkdir /data/backup/esx
echo "/data/backup 10.0.0.11(rw,async,no_subtree_check,no_root_squash)" >>/etc/exports
exportfs -rv
service nfs-kernel-server restart
- Mount new NFS export to VMware (Config > Storage > Add Storage > NFS > enter Linux server IP, /data/backup as path and BACKUP as name.
- Create SSH key on Linux, just answer with enter to all questions
ssh-keygen
- Copy /root/.ssh/id_rsa.pub to /data/backup
cp /root/.ssh/id_rsa.pub /data/backup
- Enable SSH remote access to ESXi, see VMware docs for details if you haven't already done this
- Login to ESXi using SSH
ssh root@10.0.0.11
- Enable passwordless SSH logins (following commands are entered on ESXi shell)
mv /vmfs/volumes/BACKUP/id_rsa.pub /etc/ssh/keys-root/authorized_keys
chmod 0400 /etc/ssh/keys-root/authorized_keys
- Logout from ESXi shell and reconnect using SSH. You should now be able to login without password.
- Install ghettoVCB (enter rest of command on Linux side, not esx shell)
cd /data/backup
wget https://github.com/lamw/ghettoVCB/archive/master.tar.gz
tar xvzf master.tar.gz
mv ghettoVCB-master scripts
rm -f master.tar.gz
- Create config file and keep weekly backups for entire year
mv ghettoVCB.conf ghettoVCB.conf.dist
cat <<'_EOF_'>ghettoVCB.conf
VM_BACKUP_VOLUME=/vmfs/volumes/BACKUP/esx/
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=52
_EOF_
- Schedule backups
cat <<'_EOF_'>>/etc/crontab
# Backup ESXi every Saturday night
5 1 * * Sat root (ssh root@10.0.0.11 -C '/vmfs/volumes/BACKUP/scripts/ghettoVCB.sh -a -g /vmfs/volumes/BACKUP/scripts/ghettoVCB.conf') >>/data/backup/esx/logi 2>>/data/backup/esx/logi
_EOF_
- Do first run manually so we don't need to wait until Saturday
ssh root@10.0.0.11 -C '/vmfs/volumes/BACKUP/scripts/ghettoVCB.sh -a -g /vmfs/volumes/BACKUP/scripts/ghettoVCB.conf'
- Install server with bunch of disks and Ubuntu 14.04. Use mdraid-1 for OS disks.
- Install ZFS support
apt-add-repository -y ppa:zfs-native/stable
apt-get update
apt-get -y install ubuntu-zfs
- Create RAID-Z2 (double parity) zpool
zpool create data raidz2 \
/dev/disk/by-id/ata-ST31000340NS_9QJ6ZHJJ \
/dev/disk/by-id/ata-ST31000340NS_9QJ718FG \
/dev/disk/by-id/ata-WDC_WD1002FBYS-02A6B0_WD-WMATV7379900 \
/dev/disk/by-id/ata-WDC_WD10EACS-00ZJB0_WD-WCASJ0857564 \
/dev/disk/by-id/ata-WDC_WD10EACS-00ZJB0_WD-WCASJ0945918 \
-o ashift=12 -o failmode=continue
- Create filesystem with compression (and deduplication if you feel brave)
zfs set atime=off data
zfs create data/backup
zfs set compression=on data/backup
#zfs set dedup=on data/backup
- Install NFS server
apt-get -y install nfs-kernel-server
- Export new ZFS filesystem to VMware ESXi
mkdir /data/backup/esx
echo "/data/backup 10.0.0.11(rw,async,no_subtree_check,no_root_squash)" >>/etc/exports
exportfs -rv
service nfs-kernel-server restart
- Mount new NFS export to VMware (Config > Storage > Add Storage > NFS > enter Linux server IP, /data/backup as path and BACKUP as name.
- Create SSH key on Linux, just answer with enter to all questions
ssh-keygen
- Copy /root/.ssh/id_rsa.pub to /data/backup
cp /root/.ssh/id_rsa.pub /data/backup
- Enable SSH remote access to ESXi, see VMware docs for details if you haven't already done this
- Login to ESXi using SSH
ssh root@10.0.0.11
- Enable passwordless SSH logins (following commands are entered on ESXi shell)
mv /vmfs/volumes/BACKUP/id_rsa.pub /etc/ssh/keys-root/authorized_keys
chmod 0400 /etc/ssh/keys-root/authorized_keys
- Logout from ESXi shell and reconnect using SSH. You should now be able to login without password.
- Install ghettoVCB (enter rest of command on Linux side, not esx shell)
cd /data/backup
wget https://github.com/lamw/ghettoVCB/archive/master.tar.gz
tar xvzf master.tar.gz
mv ghettoVCB-master scripts
rm -f master.tar.gz
- Create config file and keep weekly backups for entire year
mv ghettoVCB.conf ghettoVCB.conf.dist
cat <<'_EOF_'>ghettoVCB.conf
VM_BACKUP_VOLUME=/vmfs/volumes/BACKUP/esx/
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=52
_EOF_
- Schedule backups
cat <<'_EOF_'>>/etc/crontab
# Backup ESXi every Saturday night
5 1 * * Sat root (ssh root@10.0.0.11 -C '/vmfs/volumes/BACKUP/scripts/ghettoVCB.sh -a -g /vmfs/volumes/BACKUP/scripts/ghettoVCB.conf') >>/data/backup/esx/logi 2>>/data/backup/esx/logi
_EOF_
service cron restart
ssh root@10.0.0.11 -C '/vmfs/volumes/BACKUP/scripts/ghettoVCB.sh -a -g /vmfs/volumes/BACKUP/scripts/ghettoVCB.conf'
Comments
Post a Comment
Got something to say?!