SOLVED Backup of VM? Snapshots?

dnilgreb

Contributor
Joined
Mar 29, 2016
Messages
168
Just set up my first VM yesterday (OnlyOffice Document Server) and I´d like to keep it backed up. What is the best way to backup a VM? Is it by just taking snapshots of the data set where the disk image is located? Or is there a better solution? I need to be able to roll back if a problem arises, as opposed to setting everything up all over again.
 

blanchet

Guru
Joined
Apr 17, 2018
Messages
515
Yes, you can snapshot the zvol.
It is strongly recommended to power off the VM before to have a consistent backup.
 

dnilgreb

Contributor
Joined
Mar 29, 2016
Messages
168
I see. How would I go about automating that? Can it be done?
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
You might want to read about snapshotting zvols. The space they consume is counted against the size of the zvol.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
I see. How would I go about automating that? Can it be done?
You can script it using the midclt and API commands. You may need to do this before the script to make ssh login work without password ssh-copy-id root@yourvm.ip (maybe even needing to setup login without password first in the VM)
ssh root@yourvm.ip 'shutdown -h now'
maybe add a wait here... sleep 20 seconds
zfs snapshot pool/path/zvol@vmname-date-time
midclt call vm.start <ID>

Get your VM ID from midclt call vm.query | jq
 

dnilgreb

Contributor
Joined
Mar 29, 2016
Messages
168
Thanks for the details. That´s something to wrap my brain around. I think I´ll stick with the manual way for now, and look into this when I need something to pass the time.

Thanks everybody!
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
You can script it using the midclt and API commands. You may need to do this before the script to make ssh login work without password ssh-copy-id root@yourvm.ip (maybe even needing to setup login without password first in the VM)
ssh root@yourvm.ip 'shutdown -h now'
maybe add a wait here... sleep 2
0 seconds
zfs snapshot pool/path/zvol@vmname-date-time
midclt call vm.start <ID>

Get your VM ID from midclt call vm.query | jq

Hey I'm just curious if you don't shut down the zvol -- What happens? I only ask this since I've definitely made snapshots of running zvols and was able to zfs send/receive the snapshot -- deleted the original snapshat -- and then used the copied snapshot as a zvol for a new VM. I had to change some network parameters and such since PCI IDs had changed however everything seemed to work.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
Hey I'm just curious if you don't shut down the zvol -- What happens?
The same as if you were running a physical machine and yanked the power cord... whatever state the disk was in at that time is what you have in the snapshot.

If you're lucky (and the chances are probably pretty good), you will be OK.

If you need to be certain that you can still boot and use the VM in a consistent state, shut it down before the snapshot.
 
Top