How do snapshots work?

Status
Not open for further replies.

roby84

Dabbler
Joined
Jun 17, 2012
Messages
11
Hello,
I'm trying to understand how snapshots of Freenas work. I have Freenas 8.0.3 release and I have 4 TB of data on it that I would like to backup with snapshots. My questions are:

1. I know that they are stored locally, but since I just have 1 TB of free space and 4 TB of data, do they have enough space to be stored, or it doesn't care about free space?

2. How are the snapshots stored? Is it an exact copy of my files or they have a different format?

3. If I want to restore just some files, can I restore them individually from snapshots?

Thank you and sorry for my beginner questions.

Roberto
 

bollar

Patron
Joined
Oct 28, 2012
Messages
411
Snapshots are very interesting:

First off, snapshots aren't a backup. They are a way to rollback to earlier versions of the file system, but if the array becomes damaged, the snapshots are lost as well.

1. On the local machine, snapshots are metadata only. When snapshots are created, they don't use any space at all. As you make changes to your files, zfs will protect the blocks of data that used to be used for the file and that's how space is used. If you have many file changes, then your used disk space will increase rapidly. If you don't have many changes, then you may not even notice how much space the snapshots take.

You'll have to balance the need to get at older versions of files against the space it takes to reserve the space for each of those blocks no longer used.

2. Since snapshots are metadata, it's really just a list of the files on the system, the specific blocks they use, and a map that prevents those blocks from being used for new or modified files. They're not really files, per se. If you replicate the snapshot to another machine, that's when the metadata is converted into a file stream and ultimately copied into files.

3. No, you can't restore a single file -- you have to clone or rollback the entire zfs dataset. However, clones are cool: You can clone the dataset, which makes that snapshot of the file system browsable by you and doesn't take any space that isn't already used! It gives you access to the files using the blocks used by the production file system, plus the reserved blocks used to revert back in time. Once you've pulled out the files you need, you can destroy the clone without impacting your snapshots, or your users.
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
Very good overall, but one slight correction: "don't use any space at all" is incorrect, some minor space for metadata is required for a snapshot. Substitute "don't use any significant space".

Also, it is "sort of" possible to restore a single file, but it requires some command line use. You can rummage around in your snapshots! If you have a "/mnt/tank/mydocs", let's say, you can go to "/mnt/tank/mydocs/.zfs/snapshot" and see a list of directories corresponding to the snapshots. You can go into the snapshot directory, and the files are readable (but not writable). Also, if you're using CIFS, you'll notice that the "Previous Versions" feature is available if your Windows version supports it; it works through this same mechanism.
 
Status
Not open for further replies.
Top