KVM Vm Backup Strategy.
Need advice /suggestion on improving KVM based vm's backup.
I have couple of Xeon Based Servers where we have implemented KVM based Virtualization using Ubuntu Server 16.04.2 ( LTS )
The performance and ease of operation is much better than Hyper-V and VMWare.
Kindly note that while implementing KVM we are not using LVM partitioning due to various reasons and we are relied on tried, tested ext4 formatted disks and any kind of raid. We wanted a simple and easy back up system.
However need advice on the following script meant for KVM VM Advice.
The Script is as follows. #!/bin/bash
Script written by Techganesh
This script is intended to run on srv1 [ 192.168.1.2 ]
The backup is intended on srv2 [192.168.1.3 ] in /srv1_vm_backup
The VM resides on srv1 in /vm directory
We want backup without shutting down VM
The script will run thru crontab job of root in midnight - once a day.
User Created files inside VM are backup thru other software
There is ample space on srv2
Ssh login to root without password is already implemented
Declared Variables for easy change
suspend='virsh suspend'
resume='virsh resume'
source_dir='/vm/'
target_dir='/srv1_vm_backup'
target_server='root@192.168.1.3'
DAY=$(date +"%d%b%Y")
sync='rsync -avzhe ssh'
vm_on_run=/usr/bin/virsh list --all | grep running | awk {'print $2'}
log_opt='--log-file'
bkup_log='/var/log/kvm_vm/backup_log'
ext='qcow2'
Find the VM Running
for vm in $vmlist do mytime=$(date +"%d-%b-%Y@%H:%M") $suspend $vm echo "Suspended $vm backup_purpose at $mytime "
$sync $source_dir/$vm.$ext $target_server:$target_dir/$vm.$ext $log_opt=$bkup_log/$vm.$ext_$DAY.log
echo "Backed up $vm successfully ! Resuming ...$mytime"
sleep 1
$resume $vm
sleep 1
done sleep 3 exit 0
Posted Jun 17, 2017, 11:09 AM UTC