mirror of
				https://github.com/oSoWoSo/DistroHopper.git
				synced 2024-08-14 22:46:53 +00:00 
			
		
		
		
	Add snapshot management support
This commit is contained in:
		
							parent
							
								
									fb627583b9
								
							
						
					
					
						commit
						a79e16e1b7
					
				
					 2 changed files with 98 additions and 23 deletions
				
			
		
							
								
								
									
										12
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
										
									
									
									
								
							|  | @ -82,10 +82,12 @@ Usage | ||||||
|   quickemu --vm ubuntu.conf |   quickemu --vm ubuntu.conf | ||||||
| 
 | 
 | ||||||
| You can also pass optional parameters | You can also pass optional parameters | ||||||
|   --delete   : Delete the disk image. |   --delete                : Delete the disk image. | ||||||
|   --efi      : Enable EFI BIOS. |   --efi                   : Enable EFI BIOS. | ||||||
|   --restore  : Restore the snapshot. |   --snapshot apply <tag>  : Apply/restore a snapshot. | ||||||
|   --snapshot : Create a disk snapshot. |   --snapshot create <tag> : Create a snapshot. | ||||||
|  |   --snapshot delete <tag> : Delete a snapshot. | ||||||
|  |   --snapshot info         : Show disk/snapshot info. | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ## TODO | ## TODO | ||||||
|  | @ -93,7 +95,7 @@ You can also pass optional parameters | ||||||
|   - [x] Make display configuration more robust |   - [x] Make display configuration more robust | ||||||
|   - [x] Improve stdout presentation |   - [x] Improve stdout presentation | ||||||
|   - [x] Make disk image optionally size configurable |   - [x] Make disk image optionally size configurable | ||||||
|   - [ ] Improve snapshot management |   - [x] Improve snapshot management | ||||||
|   - [ ] Create desktop launcher for a VM |   - [ ] Create desktop launcher for a VM | ||||||
|   - [x] Fix Virgil 3D on EFI boot |   - [x] Fix Virgil 3D on EFI boot | ||||||
|   - [x] Get QEMU `-audiodev` working for audio input, something like: |   - [x] Get QEMU `-audiodev` working for audio input, something like: | ||||||
							
								
								
									
										109
									
								
								quickemu
									
										
									
									
									
								
							
							
						
						
									
										109
									
								
								quickemu
									
										
									
									
									
								
							|  | @ -9,25 +9,67 @@ function disk_delete() { | ||||||
|   fi |   fi | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function vm_restore() { | function snapshot_apply() { | ||||||
|   if [ -f "${disk_img_snapshot}" ]; then |   local snapshot_tag="${1}" | ||||||
|     mv "${disk_img_snapshot}" "${disk_img}" |   if [ -z "${snapshot_tag}" ]; then | ||||||
|  |     echo "ERROR! No snapshot tag provided." | ||||||
|  |     exit | ||||||
|  |   fi | ||||||
|  | 
 | ||||||
|  |   if [ -e "${disk_img}" ]; then | ||||||
|  |     ${QEMU_IMG} snapshot -q -a "${snapshot_tag}" "${disk_img}" | ||||||
|  |     if [ $? -eq 0 ]; then | ||||||
|  |       echo "SUCCESS! Applied snapshot ${snapshot_tag} to ${disk_img}" | ||||||
|  |     else | ||||||
|  |       echo "ERROR! Failed to apply snapshot ${snapshot_id} to ${disk_img}" | ||||||
|  |     fi | ||||||
|  |   else | ||||||
|  |     echo "NOTE! ${disk_img} not found. Doing nothing." | ||||||
|   fi |   fi | ||||||
|   echo "SUCCESS! Restored ${disk_img_snapshot}" |  | ||||||
|   exit 0 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function vm_snapshot() { | function snapshot_create() { | ||||||
|   if [ -f "${disk_img_snapshot}" ]; then |   local snapshot_tag="${1}" | ||||||
|     mv "${disk_img_snapshot}" "${disk_img_snapshot}.old" |   if [ -z "${snapshot_tag}" ]; then | ||||||
|  |     echo "ERROR! No snapshot tag provided." | ||||||
|  |     exit | ||||||
|   fi |   fi | ||||||
|   qemu-img create -b "${disk_img}" -f qcow2 "${disk_img_snapshot}" -q | 
 | ||||||
|   if [ $? -eq 0 ]; then |   if [ -e "${disk_img}" ]; then | ||||||
|     echo "SUCCESS! Created ${disk_img_snapshot}" |     ${QEMU_IMG} snapshot -q -c "${snapshot_tag}" "${disk_img}" | ||||||
|  |     if [ $? -eq 0 ]; then | ||||||
|  |       echo "SUCCESS! Created snapshot ${snapshot_tag} of ${disk_img}" | ||||||
|  |     else | ||||||
|  |       echo "ERROR! Failed to create snapshot ${snapshot_tag} of ${disk_img}" | ||||||
|  |     fi | ||||||
|   else |   else | ||||||
|     echo "ERROR! Failed to create ${disk_img_snapshot}" |     echo "NOTE! ${disk_img} not found. Doing nothing." | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function snapshot_delete() { | ||||||
|  |   local snapshot_tag="${1}" | ||||||
|  |   if [ -z "${snapshot_tag}" ]; then | ||||||
|  |     echo "ERROR! No snapshot tag provided." | ||||||
|  |     exit | ||||||
|  |   fi | ||||||
|  | 
 | ||||||
|  |   if [ -e "${disk_img}" ]; then | ||||||
|  |     ${QEMU_IMG} snapshot -q -d "${snapshot_tag}" "${disk_img}" | ||||||
|  |     if [ $? -eq 0 ]; then | ||||||
|  |       echo "SUCCESS! Deleted snapshot ${snapshot_tag} of ${disk_img}" | ||||||
|  |     else | ||||||
|  |       echo "ERROR! Failed to delete snapshot ${snapshot_tag} of ${disk_img}" | ||||||
|  |     fi | ||||||
|  |   else | ||||||
|  |     echo "NOTE! ${disk_img} not found. Doing nothing." | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function snapshot_info() { | ||||||
|  |   if [ -e "${disk_img}" ]; then | ||||||
|  |     ${QEMU_IMG} info "${disk_img}" | ||||||
|   fi |   fi | ||||||
|   exit 0 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function get_port() { | function get_port() { | ||||||
|  | @ -207,7 +249,8 @@ ENABLE_EFI=0 | ||||||
| readonly QEMU="/snap/bin/qemu-virgil" | readonly QEMU="/snap/bin/qemu-virgil" | ||||||
| readonly QEMU_IMG="/snap/bin/qemu-virgil.qemu-img" | readonly QEMU_IMG="/snap/bin/qemu-virgil.qemu-img" | ||||||
| readonly LAUNCHER=$(basename $0) | readonly LAUNCHER=$(basename $0) | ||||||
| SNAPSHOT=0 | SNAPSHOT_ACTION="" | ||||||
|  | SNAPSHOT_TAG="" | ||||||
| VM="" | VM="" | ||||||
| 
 | 
 | ||||||
| while [ $# -gt 0 ]; do | while [ $# -gt 0 ]; do | ||||||
|  | @ -219,7 +262,18 @@ while [ $# -gt 0 ]; do | ||||||
|       DELETE=1 |       DELETE=1 | ||||||
|       shift;; |       shift;; | ||||||
|     -snapshot|--snapshot) |     -snapshot|--snapshot) | ||||||
|       SNAPSHOT=1 |       SNAPSHOT_ACTION="${2}" | ||||||
|  |       if [ -z "${SNAPSHOT_ACTION}" ]; then | ||||||
|  |         echo "ERROR! No snapshot action provided." | ||||||
|  |         exit 1 | ||||||
|  |       fi | ||||||
|  |       shift | ||||||
|  |       SNAPSHOT_TAG="${2}" | ||||||
|  |       if [ -z "${SNAPSHOT_TAG}" ] && [ "${SNAPSHOT_ACTION}" != "info" ]; then | ||||||
|  |         echo "ERROR! No snapshot tag provided." | ||||||
|  |         exit 1 | ||||||
|  |       fi | ||||||
|  |       shift | ||||||
|       shift;; |       shift;; | ||||||
|     -vm|--vm) |     -vm|--vm) | ||||||
|       VM="$2" |       VM="$2" | ||||||
|  | @ -253,11 +307,30 @@ fi | ||||||
| 
 | 
 | ||||||
| if [ ${DELETE} -eq 1 ]; then | if [ ${DELETE} -eq 1 ]; then | ||||||
|   disk_delete |   disk_delete | ||||||
|   exit 0 |   exit | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| if [ ${SNAPSHOT} -eq 1 ]; then | if [ -n "${SNAPSHOT_ACTION}" ]; then | ||||||
|   vm_snapshot |   case ${SNAPSHOT_ACTION} in | ||||||
|  |     apply) | ||||||
|  |       snapshot_apply "${SNAPSHOT_TAG}" | ||||||
|  |       snapshot_info | ||||||
|  |       exit;; | ||||||
|  |     create) | ||||||
|  |       snapshot_create "${SNAPSHOT_TAG}" | ||||||
|  |       snapshot_info | ||||||
|  |       exit;; | ||||||
|  |     delete) | ||||||
|  |       snapshot_delete "${SNAPSHOT_TAG}" | ||||||
|  |       snapshot_info | ||||||
|  |       exit;; | ||||||
|  |     info) | ||||||
|  |       snapshot_info | ||||||
|  |       exit;; | ||||||
|  |     *) | ||||||
|  |       echo "ERROR! \"${SNAPSHOT_ACTION}\" is not a supported snapshot action." | ||||||
|  |       usage;; | ||||||
|  |   esac | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| vm_boot | vm_boot | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue