SOLVED Is it possible to restore a single file from the snapshot of a zvol?

glauco

Guru
Joined
Jan 30, 2017
Messages
526
Is it possible to restore a single file from the snapshot of a zvol?
Said zvol is used by a virtual machine.
With regular ZFS datasets, I can easily restore files by browsing the snapshot files at <dataset>/.zfs/snapshot/<snapshot>, but zvols, I can't even see them in the virtual_machines dataset where they're stored...
zfs list -t snapshot | grep vm1 shows me the snapshots were taken as expected.
Thanks.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
You can always copy another fresh ZVOL from the snapshot (zfs send|zfs recieve), add that as a second disk to the guest, and access the files inside the guest.

What kind of filesystem did the guest operating system put on the ZVOL? If it's NTFS you can possibly mount it read-only in TrueNAS, too ...
 

glauco

Guru
Joined
Jan 30, 2017
Messages
526
I see, that makes sense, thank you!
I guess I'm going to have to read the zfs man pages for send and receive.
It's a Debian Linux VM so I guess the file system is ext4.
 

glauco

Guru
Joined
Jan 30, 2017
Messages
526
Let me follow up so that it can help others in the future: your solution totally worked.
I didn't even have to read the man pages, I just typed zfs send mypool/virtual_machines/vm1@snapshot | zfs receive mypool/virtual_machines/vm1_ro, then attached the zvol to the vm while it was running but it froze so I had to restart it.
At reboot, fdisk -l showed the new disk so I mounted it with mount /dev/vdb2 /mnt and that allowed me to copy the file I needed. umount /tmp to unmount the virtual disk.
Stop the VM, go to its devices, find the disk (it's the one with highest device ID) and delete it (odd naming choice because it doesn't really delete it, it just disconnects it).
Then go to Storage > Pools and delete the zvol (this time, it gets deleted for real).
It feels reassuring to be able to recover files from VM snapshots, thanks!
 
Top