Created
June 23, 2023 13:14
-
-
Save giper45/813e9b5e99b28ca6a99423125ef54ef1 to your computer and use it in GitHub Desktop.
UTM snapshot feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CMD=$1 | |
VMNAME=$2 | |
SNAP_NAME=$3 | |
UTM_FOLDER=/Users/$USER/Library/Containers/com.utmapp.UTM/Data/Documents | |
UTM_VM_FOLDER=${UTM_FOLDER}/$VMNAME.utm/Data | |
mkdir -p ~/.utm-snapshots | |
# Check the value of the action argument | |
case $CMD in | |
"info") | |
echo "[+] info" | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 info <vmname>" | |
exit 1 | |
fi | |
qemu-img info $UTM_FOLDER/`ls -1 $UTM_FOLDER | grep .qcow2` | |
;; | |
"list-vms") | |
echo "[+] list-vms" | |
ls -1 $UTM_FOLDER | |
# Rest of your logic for the "list" action | |
;; | |
"list-snapshots") | |
echo "[+] list-snapshots" | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 list-snapshots <vmname>" | |
exit 1 | |
fi | |
VM_DISK=$UTM_VM_FOLDER/`ls -1 $UTM_VM_FOLDER | grep .qcow2` | |
qemu-img snapshot -l $VM_DISK | |
;; | |
"create") | |
echo "[+] create snapshot" | |
if [ "$#" -ne 3 ]; then | |
echo "Usage: $0 create <vmname> <snapshot-name>" | |
exit 1; | |
fi | |
VM_DISK=$UTM_VM_FOLDER/`ls -1 $UTM_VM_FOLDER | grep .qcow2` | |
qemu-img snapshot -c $SNAP_NAME $VM_DISK | |
# Rest of your logic for the "create" action | |
;; | |
"restore") | |
echo "[+] restore" | |
if [ "$#" -ne 3 ]; then | |
echo "Usage: $0 restore <vmname> <snapshot-name>" | |
exit 1; | |
fi | |
VM_DISK=$UTM_VM_FOLDER/`ls -1 $UTM_VM_FOLDER | grep .qcow2` | |
qemu-img snapshot -a $SNAP_NAME $VM_DISK | |
# Rest of your logic for the "restore" action | |
;; | |
*) | |
echo "Error: Invalid action. Valid actions are 'info' 'list-snapshots', 'list-vms', 'create', 'restore'" | |
exit 1 | |
;; | |
esac | |
# qemu-img snapshot -c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment