From owner-freebsd-questions@freebsd.org Fri Apr 10 23:53:43 2020 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 82E7427E7CD for ; Fri, 10 Apr 2020 23:53:43 +0000 (UTC) (envelope-from dpchrist@holgerdanske.com) Received: from holgerdanske.com (holgerdanske.com [184.105.128.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "xray.he.net", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48zZbV36Plz3KNQ for ; Fri, 10 Apr 2020 23:53:42 +0000 (UTC) (envelope-from dpchrist@holgerdanske.com) Received: from 99.100.19.101 ([99.100.19.101]) by holgerdanske.com with ESMTPSA (ECDHE-RSA-AES128-GCM-SHA256:TLSv1.2:Kx=ECDH:Au=RSA:Enc=AESGCM(128):Mac=AEAD) (SMTP-AUTH username dpchrist@holgerdanske.com, mechanism PLAIN) for ; Fri, 10 Apr 2020 16:53:38 -0700 Subject: Re: Restoring and snapshots To: freebsd-questions@freebsd.org References: <56b4e678-0e66-e65b-b9d2-a2e79a5b7b6f@netfence.it> From: David Christensen Message-ID: Date: Fri, 10 Apr 2020 16:53:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <56b4e678-0e66-e65b-b9d2-a2e79a5b7b6f@netfence.it> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 48zZbV36Plz3KNQ X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of dpchrist@holgerdanske.com has no SPF policy when checking 184.105.128.27) smtp.mailfrom=dpchrist@holgerdanske.com X-Spamd-Result: default: False [-1.68 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; NEURAL_HAM_MEDIUM(-0.96)[-0.958,0]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; IP_SCORE(-0.62)[ipnet: 184.104.0.0/15(0.54), asn: 6939(-3.60), country: US(-0.05)]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; TO_DN_NONE(0.00)[]; AUTH_NA(1.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-0.998,0]; DMARC_NA(0.00)[holgerdanske.com]; RCVD_IN_DNSWL_NONE(0.00)[27.128.105.184.list.dnswl.org : 127.0.10.0]; R_SPF_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:6939, ipnet:184.104.0.0/15, country:US]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Apr 2020 23:53:43 -0000 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