Date: Fri, 10 Apr 2020 16:53:38 -0700 From: David Christensen <dpchrist@holgerdanske.com> To: freebsd-questions@freebsd.org Subject: Re: Restoring and snapshots Message-ID: <e8fb0530-917a-f259-9238-5306e63b89df@holgerdanske.com> In-Reply-To: <56b4e678-0e66-e65b-b9d2-a2e79a5b7b6f@netfence.it> References: <56b4e678-0e66-e65b-b9d2-a2e79a5b7b6f@netfence.it>
next in thread | previous in thread | raw e-mail | index | archive | help
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 periodically. > 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 ./foo.sh #!/bin/sh cat='/bin/cat' dir='path with spaces' file='hello.txt' $cat "$dir/$file" $ ./foo.sh 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. David
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e8fb0530-917a-f259-9238-5306e63b89df>