[FreeBSD] Added VM backup script
This commit is contained in:
parent
7821a9980e
commit
4ea2b0f9c7
54
FreeBSD/vm-backup.csh
Normal file
54
FreeBSD/vm-backup.csh
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/csh
|
||||||
|
|
||||||
|
## config section
|
||||||
|
set vm_dataset = "zroot/vms"
|
||||||
|
set backup_dataset = "tank/backup/bhyve"
|
||||||
|
set backup_date = `date "+%Y-%m-%d"`
|
||||||
|
|
||||||
|
# Snapshot all VMs
|
||||||
|
echo ""
|
||||||
|
echo "################# SNAPSHOT VM #################"
|
||||||
|
foreach vm (`ls /usr/vms | \
|
||||||
|
grep -v .config | \
|
||||||
|
grep -v .iso | \
|
||||||
|
grep -v .templates`)
|
||||||
|
|
||||||
|
## stopping vm
|
||||||
|
vm stop $vm
|
||||||
|
|
||||||
|
## give vm time to shut down properly
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
## snapshot vm
|
||||||
|
echo "Snapshot VM: $vm"
|
||||||
|
zfs snapshot $vm_dataset/$vm@$backup_date
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
## start VM
|
||||||
|
vm start $vm
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# Backup all VM snapshots
|
||||||
|
echo ""
|
||||||
|
echo "################## BACKUP VM ##################"
|
||||||
|
foreach vm (`ls /usr/vms | \
|
||||||
|
grep -v .config | \
|
||||||
|
grep -v .iso | \
|
||||||
|
grep -v .templates`)
|
||||||
|
|
||||||
|
## Send snapshot to backup destination
|
||||||
|
echo "Backup VM: $vm"
|
||||||
|
zfs send $vm_dataset/$vm@$backup_date | pv | zfs recv -F $backup_dataset/$vm
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
## Delete snapshot
|
||||||
|
zfs destroy $vm_dataset/$vm@$backup_date
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# report done
|
||||||
|
echo ""
|
||||||
|
echo "############### ALL DONE THANKS ###############"
|
||||||
|
echo ""
|
Loading…
Reference in New Issue
Block a user