@NumberSix Have you read the ZFS primer? If not, you should.
Background information about the Zettabyte File System (ZFS).
www.truenas.com
ZFS is a copy-on-write filesystem. So it never overwrites data in place. It writes new data, then re-arranges internal data structures to point to the new data (the re-written data structures are also written to new locations ...) and finally releases the old blocks that are not referenced anymore as "free".
A snapshot does not reside in any particular file. It is part of the ZFS dataset in question. A snapshot means that the old data is not released for future overwriting but kept - with appropriate management information pointing to it.
So I have this dataset:
Code:
root@freenas[~]# zfs list -r -t all hdd/scripts
NAME USED AVAIL REFER MOUNTPOINT
hdd/scripts 1.81M 4.44T 1.81M /mnt/hdd/scripts
Now I take a snapshot:
Code:
root@freenas[~]# zfs snapshot hdd/scripts@2359
root@freenas[~]# zfs list -r -t all hdd/scripts
NAME USED AVAIL REFER MOUNTPOINT
hdd/scripts 1.81M 4.44T 1.81M /mnt/hdd/scripts
hdd/scripts@2359 0B - 1.81M -
This snapshot is just a reference to the current state of the dataset. I can - if I like - rollback to it and undo any changes:
Code:
root@freenas[~]# touch /mnt/hdd/scripts/foobarbaz
root@freenas[~]# ll /mnt/hdd/scripts/foobarbaz
-rw-r--r-- 1 root wheel uarch 0 Apr 29 00:01 /mnt/hdd/scripts/foobarbaz
root@freenas[~]# zfs rollback hdd/scripts@2359
root@freenas[~]# ll /mnt/hdd/scripts/foobarbaz
ls: /mnt/hdd/scripts/foobarbaz: No such file or directory
So the rollback returned the dataset to the state it had before I created that empty file.
Now to save a snapshot in a real file, that you can copy off your NAS and store somewhere else, do something like this:
Code:
root@freenas[~]# zfs send hdd/scripts@2359 >/mnt/hdd/share/archiv/hdd-scripts@2359
root@freenas[~]# ll /mnt/hdd/share/archiv/hdd-scripts@2359
-rw-r--r-- 1 root nogroup uarch 3617384 Apr 29 00:04 /mnt/hdd/share/archiv/hdd-scripts@2359
So now there is a file in my "archiv" dataset that contains all the data of the "scripts" dataset at the time I took the snapshot.
Now imagine your entire NAS goes *poof* but you have this file on some medium. You set up a new ZFS capable system and copy the file over somehow. To restore:
Code:
root@freenas[~]# zfs receive hdd/scripts-restored < /mnt/hdd/share/archiv/hdd-scripts@2359
root@freenas[~]# ll /mnt/hdd/scripts-restored
total 110
drwxr-xr-x 3 root wheel uarch 9 Mar 19 23:39 ./
drwxr-xr-x 8 root wheel uarch 8 Apr 29 00:07 ../
-rwxr-xr-x 1 root wheel uarch 227 Jan 15 2020 backup-config.sh*
drwxr-xr-x 2 root wheel uarch 32 Apr 29 00:00 config/
-rwxr-xr-x 1 root wheel uarch 56599 Jan 11 2020 disklist.pl*
-rwxr-xr-x 1 root wheel uarch 117 May 29 2020 nvme-power.sh*
-rwxr-xr-x 1 root wheel uarch 795 Apr 14 16:50 nvme-wear.sh*
-rwxr-xr-x 1 root wheel uarch 276 Jan 11 2020 shutdown-bhyve.sh*
-rwxr-xr-x 1 root wheel uarch 709 Jan 31 23:12 zpool-metrics.sh*
Now
/mnt/hdd/scripts-restored
contains exactly the data of
/mnt/hdd/scripts
at the time I took that snapshot.
BTW: note how I use ZFS dataset names ("pool/path/path") for all the ZFS operations, but real file paths ("/mnt/path/path/file") when referencing a file.
HTH,
Patrick