Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Help about MediaWiki
FUTO
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Introduction to a Self Managed Life: a 13 hour & 28 minute presentation by FUTO software
(section)
Main Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Step 8: Restoring a virtual machine from a backup == So you messed up and deleted everything inside your virtual machine. You want to go back to where you were before. Remember: '''A BACKUP PLAN IS ONLY AS GOOD AS HOW EASY IT IS TO RESTORE FROM A BACKUP!''' <span id="basic-restore"></span> === Basic Restore === By “basic restore” I mean what to do when you messed up a program configuration or deleted files inside a virtual machine or corrupted something accidentally. You want to go back to the image of the virtual machine you had before, on the same happycloud host computer. <span id="before-you-start"></span> ==== 8.1 Before You Start ==== I’m assuming the following is true: - Your virtual machine is already defined in Virtual Machine Manager(you see it when you run virtual machine manager GUI) - Your backups are in <code>/mediapool/vmbackups</code> - The backups were created using the qemu-img backup script I provided above - You just need to restore the virtual machine’s disk because you messed up some files or programs <span id="find-your-backup"></span> ==== 8.2 Find Your Backup ==== # List available backups for your virtual machine: <pre>ls -l /mediapool/vmbackups/name-of-your-virtual-machine-*.qcow2</pre> You’ll see files named like this: - <code>name-of-your-virtual-machine-20240101.qcow2</code> - <code>name-of-your-virtual-machine-20240108.qcow2</code> These are the disk image files that have all of the data/programs/databases/operating system. Each backup will have an XML file to go with it: - <code>name-of-your-virtual-machine-20240101.xml</code> - <code>name-of-your-virtual-machine-20240108.xml</code> These are the files that tell virtual machine manager all of the details about your virtual machine(RAM/CPU, hardware setup, etc.) Pick the most recent backup before you screwed something up. <span id="fast-restore"></span> ==== Fast Restore: ==== # Turn off the virtual machine <pre># Shut down the virtual machine gracefully virsh shutdown name-of-your-virtual-machine # Wait until it's actually off. Check status with: virsh list --all</pre> <ol start="2" style="list-style-type: decimal;"> <li>Backup Current Disk (just in case)</li></ol> <pre># Move the current (messed up/broken) disk with date mv /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2 /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2.broken-$(date +%Y%m%d)</pre> <ol start="3" style="list-style-type: decimal;"> <li>Restore Backup</li></ol> <pre># a cool command to put the virtual machine back where it was qemu-img convert -p -f qcow2 -O qcow2 /mediapool/vmbackups/name-of-your-virtual-machine-20240101.qcow2 /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2 # set permissions so that our virtual machine management stuff can use it. chown libvirt-qemu:kvm /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2 chmod 644 /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2</pre> <ol start="4" style="list-style-type: decimal;"> <li>Start the Virtual Machine</li></ol> <pre>virsh start name-of-your-virtual-machine</pre> <span id="check-the-restore"></span> ==== Check the Restore ==== # Watch the virtual machine console in Virtual Machine Manager to make sure it boots # Try logging in when it’s up # Check that services(mailcow, immich, syncthing) actually work <span id="complicated-restore"></span> === Complicated Restore === Let’s say you destroyed more. You also messed up the virtual machine’s configuration in virsh. You edited the xml file for the virtual machine or messed with its settings in the '''Virtual Machine Manager''' GUI, and now nothing works. For a complete restore of both disk & configuration: # Remove the current virtual machine: <pre>virsh destroy name-of-your-virtual-machine virsh undefine name-of-your-virtual-machine</pre> <ol start="2" style="list-style-type: decimal;"> <li>Restore the Disk:</li></ol> <pre># Convert the compressed backup to the images directory qemu-img convert -p -f qcow2 -O qcow2 /mediapool/vmbackups/name-of-your-virtual-machine-20240101.qcow2 /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2 # Fix permissions chown libvirt-qemu:kvm /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2 chmod 644 /var/lib/libvirt/images/name-of-your-virtual-machine.qcow2</pre> <ol start="3" style="list-style-type: decimal;"> <li>Restore the virtual machine config:</li></ol> <pre># The backup includes the XML configuration file virsh define /mediapool/vmbackups/name-of-your-virtual-machine-20240101.xml</pre> <ol start="4" style="list-style-type: decimal;"> <li>Start the VM:</li></ol> <pre>virsh start name-of-your-virtual-machine</pre> <span id="common-screwups"></span> === Common screwups === # '''“Failed to convert image”''': #* Make sure you have enough disk space #* Check that the backup file isn’t corrupted # '''“Failed to start VM”''': #* Usually permissions. Everyone is excited to realize they had a backup file whilst copying it back; in the excitement of realizing you actually HAVE a backup, nobody remembers to set permissions on the backup file. #* Check that the XML file matches the system config. use virtual machine manager for this to see if anything sticks out in the GUI as a stupid mistake. #* Verify all paths exist # '''“Could not access storage file”''': Check paths in both: #* <code>/var/lib/libvirt/images/</code> #* The virtual machine XML config #* Make sure permissions are right (644 for files) <span id="verifying-success"></span> === Verifying Success === After restoration, verify: 1. VM boots properly 2. Network connectivity works 3. All services start correctly 4. Data and configurations are as expected 5. Check logs for any errors If something isn’t right, you can always try an older backup - they’re kept for 56 days. <span id="accessing-your-samba-share-from-any-device"></span>
Summary:
Please note that all contributions to FUTO may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
FUTO:Copyrights
for details).
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:
Cancel
Editing help
(opens in new window)