5.5 KiB
Back up and restore Windows Server on Pegasus
Windows_Server is the Microsoft Active Directory domain controller VM on Pegasus. It runs under system libvirt. Its boot disk is sda, and its network is the libvirt default network.
The backup taken on 12 November 2026 is in /srv/vm-backups/Windows_Server-20261112T123847Z/. The 80 GiB virtual disk occupies about 7 GiB on Pegasus. The backup contains the QCOW2 disk, the inactive VM definition, the network definition, and a SHA-256 manifest. The disk and checksums passed verification. A restore boot has yet to be tested.
Create a full live backup
Connect to Pegasus with ssh pegasus and run these commands in Bash. The VM stays online during the copy. A live disk backup has crash consistency, which corresponds to recovering after an unexpected shutdown. For a clean shutdown point, use a maintenance window and copy the QCOW2 after the guest has shut down.
set -euo pipefail
export LC_ALL=C
umask 077
vm=Windows_Server
root=/srv/vm-backups
backup="$root/$vm-$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p -m 711 "$root"
mkdir -m 711 "$backup"
virsh -c qemu:///system dumpxml "$vm" --inactive > "$backup/$vm.xml"
virsh -c qemu:///system net-dumpxml default > "$backup/default-network.xml"
spec=$(mktemp /tmp/windows-server-backup.XXXXXX)
trap 'rm -f "$spec"' EXIT
cat > "$spec" <<XML
<domainbackup mode='push'>
<disks>
<disk name='sda' backup='yes' type='file'>
<driver type='qcow2'/>
<target file='$backup/$vm.qcow2'/>
</disk>
</disks>
</domainbackup>
XML
virsh -c qemu:///system backup-begin "$vm" --backupxml "$spec"
while :; do
job=$(virsh -c qemu:///system domjobinfo "$vm")
if grep -qE '^Job type:[[:space:]]+None' <<< "$job"; then
break
fi
sleep 5
done
result=$(virsh -c qemu:///system domjobinfo "$vm" --completed --keep-completed)
printf '%s\n' "$result"
grep -qE '^Job type:[[:space:]]+Completed' <<< "$result"
sudo chown "$(id -u):$(id -g)" "$backup/$vm.qcow2"
chmod 600 "$backup/$vm.qcow2"
chmod 700 "$backup"
qemu-img check "$backup/$vm.qcow2"
(
cd "$backup"
sha256sum "$vm.qcow2" "$vm.xml" default-network.xml > SHA256SUMS
sha256sum -c SHA256SUMS
)
printf 'Verified backup in %s\n' "$backup"
Keep the backup directory private because its disk contains the directory database. Keep a second protected copy on separate storage if the backup must survive loss of Pegasus or its storage.
Restore on Pegasus
Use this procedure to replace the failed VM with the backup. Shut down the original VM before restoring under the same identity. Keep other copies of this domain controller off the production network to avoid duplicate machine, domain controller, MAC, or IP identities.
-
Connect with
ssh pegasus. Pick the backup and validate its contents.set -euo pipefail export LC_ALL=C umask 077 vm=Windows_Server backup=/srv/vm-backups/Windows_Server-20261112T123847Z (cd "$backup" && sha256sum -c SHA256SUMS) qemu-img check "$backup/$vm.qcow2" virsh -c qemu:///system list --all virsh -c qemu:///system net-list --all -
If the old VM is running, shut it down gracefully with
virsh -c qemu:///system shutdown Windows_Server. Wait untilvirsh -c qemu:///system domstate Windows_Serverreportsshut off. If the VM is already defined, save its current definition for rollback. The original disk stays at its existing path. -
If the
defaultnetwork is missing, define it from the backup withvirsh -c qemu:///system net-define "$backup/default-network.xml". If it exists, compare it with the saved definition, including any address reservations. If inactive, start it withvirsh -c qemu:///system net-start default. -
Copy the verified disk to a new path and define the VM from a copy of the saved XML. These commands assume the original libvirt image directory and boot disk path used by the saved definition.
if virsh -c qemu:///system dominfo "$vm" >/dev/null 2>&1; then test "$(virsh -c qemu:///system domstate "$vm")" = 'shut off' fi stamp=$(date -u +%Y%m%dT%H%M%SZ) disk="/var/lib/libvirt/images/$vm-restored-$stamp.qcow2" restore_xml=$(mktemp /tmp/windows-server-restore.XXXXXX) trap 'rm -f "$restore_xml"' EXIT if virsh -c qemu:///system dominfo "$vm" >/dev/null 2>&1; then virsh -c qemu:///system dumpxml "$vm" --inactive \ > "/srv/vm-backups/$vm-before-restore-$stamp.xml" fi sudo test ! -e "$disk" sudo cp --sparse=always "$backup/$vm.qcow2" "$disk" sudo qemu-img check "$disk" sed "s|/var/lib/libvirt/images/Windows_Server.qcow2|$disk|" \ "$backup/$vm.xml" > "$restore_xml" grep -F "file='$disk'" "$restore_xml" virsh -c qemu:///system define "$restore_xml" virsh -c qemu:///system domblklist "$vm" --inactive --details virsh -c qemu:///system start "$vm" -
Open the VM console and confirm Windows starts. Verify Active Directory and DNS with
dcdiag /test:Advertising /test:Services /test:DNSin an elevated Windows shell. From the Laravel checkout with the Microsoft AD profile active, runphp artisan ad:sync --email --dry-runand confirm LDAPS bind and search results. This dry run records audit history.
If the replacement fails and the original disk is usable, shut the restored VM down, redefine it with the saved Windows_Server-before-restore-*.xml, and start it using its original disk. For a restore rehearsal, use a separate libvirt host with an isolated network. For an AD recovery involving other domain controllers, coordinate the restore with the domain's replication and AD recovery procedure before reconnecting the restored VM.