Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #set up variables
- lvmrootdir=/dev/data1/
- qemuconfdir=/etc/libvirt/qemu/
- backupdir=/mnt/external/vmbackups/
- #lvm snapshot variable below
- #get a list of all virtual machines on this host
- virsh list --all
- read -p "Please specify the (exact) name of the VM you would like to backup: " -e vmname
- echo Backing up $lvmrootdir$vmname
- echo Associated config file is $qemuconfdir$vmname.xml
- #check for existing backup folder
- if [ -d $backupdir$vmname ]; then
- echo Directory $backupdir$vmname already exists.
- else
- mkdir $backupdir$vmname
- echo Creating $backupdir$vmname
- fi
- echo Creating a snapshot...
- lvcreate -L10G -s -n SNAPSHOT$vmname $lvmrootdir$vmname
- snapshotdir=$lvmrootdir"SNAPSHOT"$vmname
- echo Backing up the virtual disc, this may take a while.
- dd if=$snapshotdir of=$backupdir$vmname/$vmname.dd
- echo Disc backup complete, compressing the backup.
- gzip -v $backupdir$vmname/$vmname.dd
- echo Copying config file to $backupdir$vmname/$vmname.xml
- cp $qemuconfdir$vmname.xml $backupdir$vmname/$vmname.xml
- echo Cleaning up...
- lvremove -f $snapshotdir
- echo Backup completed
- echo Exiting...
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement