Skip to content

Instantly share code, notes, and snippets.

@gsdefender
Last active July 6, 2023 20:00
Show Gist options
  • Save gsdefender/00e55ad3f41f8e5ca9c039b281d6e20a to your computer and use it in GitHub Desktop.
Save gsdefender/00e55ad3f41f8e5ca9c039b281d6e20a to your computer and use it in GitHub Desktop.
Restore Proxmox VM backup to another server
#!/bin/bash
# usage: ./restore-proxmox-vm backup.zst local:111 newlocal
tempdir=$(mktemp -d -u) # do not create directory or vma extract will fail
if [ -f "$1" ]; then zstd -d "$1"; fi
vma extract "$(basename $1 .zst)" "$tempdir"
vmid=$(($(ls -1 /etc/pve/qemu-server/*.conf | tr '\n' '\0' | xargs -0 -n 1 basename | sed -e 's:\.conf::g' | sort -n | tail -1)+1))
mv "$tempdir/qemu-server.conf" /etc/pve/qemu-server/$vmid.conf
newdisk="$3:$vmid"
sed -i -e "s:$2:$newdisk:g" /etc/pve/qemu-server/$vmid.conf
mkdir -p "$3/images/$vmid"
mv "$tempdir/disk-drive-scsi0.raw" "$3/images/$vmid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment