Restore a single file from Snapshot

All your general support questions for OpenZFS on OS X.

Restore a single file from Snapshot

Postby Tsur » Mon Jun 25, 2018 8:59 pm

So I've been dutifully taking weekly snapshots for the past year. I've accidentally deleted a file, but I'm not certain when I deleted it. I rotate two backups biweekly, so I know I deleted it at least a month ago. I definitely don't want to rollback my entire system.

So in practical terms, how do I browse the contents of my snapshots to locate the file and then restore it?
Tsur
 
Posts: 22
Joined: Thu Jan 07, 2016 2:11 pm

Re: Restore a single file from Snapshot

Postby lundman » Tue Jun 26, 2018 9:51 pm

zfs mount $snapshot
ls -l $mountpoint/.zfs/$snapshot/path/to/file
zfs umount $snapshot

then just change $snapshot do go back in time until you find it.
User avatar
lundman
 
Posts: 1335
Joined: Thu Mar 06, 2014 2:05 pm
Location: Tokyo, Japan

Re: Restore a single file from Snapshot

Postby Tsur » Fri Jun 29, 2018 9:05 am

Thanks for the help.

But I guess I was wondering (hoping) if there's some sort of snapshot "viewer" functionality or utility - an easier way to browse the contents of multiple snapshots.
Tsur
 
Posts: 22
Joined: Thu Jan 07, 2016 2:11 pm

Re: Restore a single file from Snapshot

Postby thePoet » Tue Jul 03, 2018 6:37 am

I’m not sitting in front of my computer to prove this out, but I believe if you configure Finder to show hidden files, the .zfs directory that you will mount the snapshot to should be visible. You will still need to use the command line to mount and unmount the snapshots, but you will be able to look through the files, copy, etc through Finder like normal.
thePoet
 
Posts: 23
Joined: Sat May 24, 2014 8:12 am

Re: Restore a single file from Snapshot

Postby kingneutron » Sat Mar 16, 2019 4:50 pm

Tsur wrote:Thanks for the help.

But I guess I was wondering (hoping) if there's some sort of snapshot "viewer" functionality or utility - an easier way to browse the contents of multiple snapshots.


--Sorry for resurrecting an old thread, but I just ran into this myself and have a decent solution. (I'm used to snapshots auto-mounting on the Linux side of things.) If you have Homebrew installed, ' brew install mc ' (midnight commander) and you can use these scripts I created to help:

BEGIN zfs-osx-mount-snapshot.sh
Code: Select all
#!/bin/bash

# REF: https://openzfsonosx.org/wiki/FAQ#Q.29_How_can_I_access_the_.zfs_snapshot_directories.3F

# Auto-set snapshot dir as visible on all (mounted/imported) pools
for zds in `zpool list |grep -v ALLOC |awk '{print $1}'`; do
  zfs set snapdir=visible $zds
done

# EDITME - modify the part after grep to search for and mount what you want to work on
for zds in `zfs list -r -t snapshot -o name,used,refer,mountpoint,creation |grep virtbox |awk '{print $1}'`; do
  zfs mount $zds 
done

df -h

exit;

--As of 2019.0316, zfs for osx v1.8.2:

How can I access the .zfs snapshot directories?
A) You need to set snapdir visible and manually mount a snapshot.

$ sudo zfs set snapdir=visible tank/bob
$ sudo zfs mount tank/bob@yesterday
$ ls -l /tank/bob/.zfs/snapshot/yesterday/
You can see existing snapshots via:

$ zfs list -t snapshot
Q) Is .zfs snapdir auto-mounting supported?
A) No, not at this time. You must manually "zfs mount" snapshots manually to see them in the snapdir.

Q) OK, I manually mounted my snapshot but still cannot see it in Finder. What gives?
A) Currently mounted snapshots are only visible from Terminal, not from Finder.


--Once you have edited the script (run it as root and don't forget to chmod +x it) you can fire up ' mc /Volumes ' and use a text-based dual-pane interface to browse your snapshot(s) and copy file(s) from one pane to the other (use Tab to switch panes.) When done messing around with snapshots:

BEGIN zfs-osx-unmount-snapshots.sh
Code: Select all
#!/bin/bash

for zds in `df|grep '.zfs' |awk '{print $1}'`; do
  zfs umount $zds
done

df -h

exit;


HTH - I recommend running the scripts from root/bin directory ( /var/root/bin/) and use ' sudo su - '
kingneutron
 
Posts: 13
Joined: Sat Mar 16, 2019 4:37 pm



Return to General Help

Who is online

Users browsing this forum: jawbroken and 27 guests