KVM SR: export: use new slapos.toolbox qemu qmp wrapper.
[slapos.git] / software / kvm / template / kvm-export.sh.in
1 #!/bin/bash
2 # Create a backup of the disk image of the virtual machine
3 QEMU_IMG=${kvm-instance:qemu-img-path}
4 SNAPSHOT_NAME=$(date +%s)
5 DISK_PATH=${kvm-instance:disk-path}
6 BACKUP_PATH=${:backup-disk-path}
7 QMP_CLIENT=${buildout:directory}/software_release/bin/qemu-qmp-client
8
9 if [ ! -f $DISK_PATH ]; then
10 echo "Nothing to backup, disk image doesn't exist yet."
11 exit 0;
12 fi
13
14 $QMP_CLIENT ${kvm-instance:socket-path} suspend && \
15 $QEMU_IMG snapshot -c $SNAPSHOT_NAME $DISK_PATH
16 $QMP_CLIENT ${kvm-instance:socket-path} resume
17
18 if [ -f $BACKUP_PATH ]; then
19 rm $BACKUP_PATH
20 fi
21 $QEMU_IMG convert -f qcow2 -O qcow2 -s $SNAPSHOT_NAME $DISK_PATH $BACKUP_PATH && \
22 $QEMU_IMG snapshot -d $SNAPSHOT_NAME $DISK_PATH