Project

General

Profile

Feature #797

Recover Files From a ZFS Snapshot

Added by Daniel Curtis over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Immediate
Assignee:
Category:
File Server
Target version:
Start date:
04/12/2016
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

Description

I accidentally deleted a bunch of important files from a jail that was running FreeNAS 9.3; but will work on FreeBSD as well. Luckily, I had setup my jails to have periodic snapshots taken for just this very reason.

ZFS to the rescue!

  • Log into the FreeNAS administration panel and open a Shell.
  • Check the status of the snapdir for the examplejail jail zvol:
    zfs get snapdir zpool/jails/examplejail
    
    • Example output:
      NAME                     PROPERTY  VALUE    SOURCE
      zpool/jails/examplejail  snapdir   hidden   default
      
  • Set the snapdir value to visible:
    zfs set snapdir=visible zpool/jails/examplejail
    
  • Check which snapshots are available:
    ls /mnt/zpool/jails/examplejail/.zfs/snapshot/
    
    • Example output:
      auto-20160330.0900-2w   auto-20160405.0900-2w   auto-20160411.0900-2w           
      auto-20160331.0900-2w   auto-20160406.0900-2w   auto-20160412.0900-2w           
      auto-20160401.0900-2w   auto-20160407.0900-2w                                   
      auto-20160404.0900-2w   auto-20160408.0900-2w
      
  • Now use rsync to copy the files back to the original jail:
    rsync -avh -n /mnt/zpool/jails/examplejail/.zfs/snapshot/auto-20160411.0900-2w/var/vmail/vmail1/example.com/bob/ /mnt/zpool/jails/examplejail/var/vmail/vmail1/example.com/bob/
    
    • NOTE: Make sure to remove the -n (dryrun) flag to run the sync for real, or else you won't actually be copying the data.
  • When the sync is complete set the example jail zvol snapdir property back to hidden:
    zfs set snapdir=hidden zpool/jails/examplejail
    

Resources

History

#1 Updated by Daniel Curtis over 4 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

#2 Updated by Daniel Curtis over 4 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF