Restoring and snapshots

David Christensen dpchrist at
Fri Apr 10 23:53:43 UTC 2020

On 2020-04-10 02:30, Andrea Venturoli wrote:
> Hello.
> When I'm doing backups/dumps of ZFS filesystems (with whatever tool), I 
> use snapshots.
> So, suppose I have the following datasets:
> /etc
> /usr
> /usr/local
> /var
> I'll snapshot them and back up
> /etc/.zfs/snapshot/snapname/
> /usr/.zfs/snapshot/snapname/
> /usr/local/.zfs/snapshot/snapname/
> /var/.zfs/snapshot/snapname/
> Then I'll get the same directory structure when restoring.
> Any idea how to easily remove the .zfs/snap and go back to the original 
> tree?

ZFS can roll back a filesystem per a snapshot.  See zfs(8) 'rollback'. 
Make sure you understand the warnings about destroyed data and about 
recursive child snapshots.  You will want to disable all services that 
use the filesystem(s) while you rollback.  Better yet, unmount the 
filesystem(s) while you rollback.  Whichever snapshot(s) you rollback 
to, they will remain after the rollback.

If you want to restore only parts of a filesystem, I believe you must 
use filesystem-level tools.

Consider implementing zfs-auto-snapshot.

The ZFS analog of dump(8) is 'zfs send' and the ZFS analog of restore(8) 
is 'zfs receive', but there are differences.  While you can put storage 
device(s) between the two commands and support one ZFS pool over time, I 
have a "live" server and pool, a "standby" server and pool, and several 
"external disk" pools.  I put the 'send' and 'receive' commands into a 
pipeline and "replicate" from the "live" pool to the other pools 

> I tried writing a few lines of script, but I found out that's not so 
> easy (due to directories which must overlap, spaces in file names, etc...).
> Any hint?
>   bye & Thanks
>      av.

I am not sure I understand what you mean by "directories which must 
overlap" (?).

The numerous shells and languages each have their own idiosyncrasies 
when it comes to spaces in file and directory names.

For example, suppose I want to view the contents of a text file in a 
directory whose name contains spaces.  If I use Bash and command 
completion, this works:

$ cat path\ with\ spaces/hello.txt
hello, world!

Using Bash by hand, these also work -- note the placement of single quotes:

$ cat 'path with spaces'/hello.txt
hello, world!

$ cat 'path with spaces/hello.txt'
hello, world!

But, this breaks:

$ cat path with spaces/hello.txt
cat: path: No such file or directory
cat: with: No such file or directory
cat: spaces/hello.txt: No such file or directory

Translating the above into a Bourne shell script (which also works under 
Bash) -- note the placement of single and double quotes:

$ cat ./
dir='path with spaces'
$cat "$dir/$file"

$ ./
hello, world!

The key concept is that each path component needs to be preserved as a 
single unit, and not broken into pieces if it contains spaces.


More information about the freebsd-questions mailing list