Advertisement
Guest User

Down'n'dirty KVM backup

a guest
Mar 24th, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #set up variables
  4. lvmrootdir=/dev/data1/
  5. qemuconfdir=/etc/libvirt/qemu/
  6. backupdir=/mnt/external/vmbackups/
  7. #lvm snapshot variable below
  8.  
  9. #get a list of all virtual machines on this host
  10. virsh list --all
  11.  
  12. read -p "Please specify the (exact) name of the VM you would like to backup: " -e vmname
  13.  
  14. echo Backing up $lvmrootdir$vmname
  15. echo Associated config file is $qemuconfdir$vmname.xml
  16.  
  17. #check for existing backup folder
  18. if [ -d $backupdir$vmname ]; then
  19. echo Directory $backupdir$vmname already exists.
  20. else
  21. mkdir $backupdir$vmname
  22. echo Creating $backupdir$vmname
  23. fi
  24. echo Creating a snapshot...
  25. lvcreate -L10G -s -n SNAPSHOT$vmname $lvmrootdir$vmname
  26. snapshotdir=$lvmrootdir"SNAPSHOT"$vmname
  27.  
  28. echo Backing up the virtual disc, this may take a while.
  29.  
  30. dd if=$snapshotdir of=$backupdir$vmname/$vmname.dd
  31.  
  32. echo Disc backup complete, compressing the backup.
  33.  
  34. gzip -v $backupdir$vmname/$vmname.dd
  35.  
  36. echo Copying config file to $backupdir$vmname/$vmname.xml
  37.  
  38. cp $qemuconfdir$vmname.xml $backupdir$vmname/$vmname.xml
  39. echo Cleaning up...
  40. lvremove -f $snapshotdir
  41. echo Backup completed
  42. echo Exiting...
  43.  
  44. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement