16

I'm working on a project that will teach linux to youth. Knowing they will have a tendency to delete or corrupt items in their home directories we are looking for a good snapshot option. We will not have access to fancy tools available from major storage vendors and are hoping to find a solution at the file system level.

I've read a lot about btrfs but have little experience. I have some experience with LVM but I'm unfamiliar with its snapshoting feature. Do either filesystem or another have the option to create snapshots either on demand or scheduled? Then make these snapshot always available without root in like a .snapshot folder in each home folder?

Idealy this solutions allows a user to self-restore backups on demand within say a 24 to 48 hour window. We will have another backup process for the system and more global backups. But we do not want this process to be used by students who just make 'mistakes'.

RichVel
  • 3,633
Gray Race
  • 933

4 Answers4

11

(Updated Sept 2023)

Filesystems

On Linux, btrfs is the simplest option for snapshots within a filesystem. It is reasonably stable and complete, based on this 2021 article, as long as you don't use the RAID features. It does have some fsck and repair tools.

ZFS is another option with good snapshot support, and is now cross-platform for Linux, FreeBSD, etc. It's actively developed by the OpenZFS project, and is more complete than btrfs.

LVM

This LVM answer has some details on the pro's and con's of using LVM snapshots, and some btrfs/ZFS links. With some filesystems (ext4 and XFS), LVM will take care of freezing the FS before it takes the snapshot, but LVM snapshots can have performance problems and still have some bugs.

I don't think LVM is a great solution for this 'quick snapshot of user data' application - it's still weaker than btrfs or ZFS in 2022.

rsnapshot

You may also want to look at rsnapshot, which is a user-space tool that creates snapshots using any filesystem, without using LVM.

Since rsnapshot uses rsync and stores the snapshots under a series of directories, using hard links between different snapshots if a file has not changed, it can run surprisingly quickly even on reasonably large sets of files.

It is used a lot for backups but can also be used for this sort of user-data snapshot requirement, and with a little setup can enable anyone to restore their snapshotted files, by using read-only NFS or Samba - see this HOWTO section on restoring files. Files can be restored with standard Linux tools as rsnapshot mirrors the source directory into each snapshot directory.

rsnapshot is quite flexible using its standard features, and since it's written in Perl it's quite easy to customise it, e.g. if you want to provide on-demand snapshots.

The main drawbacks compared to filesystem snapshots are speed, disk space, and not being a 'point in time' snapshot:

  • speed - every file must be checked, even if many are skipped
  • disk space - each file that changes results in a new copy in the snapshot, whereas filesystem snapshots only copy new blocks in the file
  • point in time - rsnapshot doesn't capture all files at a single point in time, unlike filesystem snapshots. Also known as being non-atomic
RichVel
  • 3,633
7

As of 2022, btrfs is considered stable for non-RAID setups, and it offers transparent and stable snapshots.

The top answer is from 2011 and mentions that both btrfs and ZFS are considered unstable. 11 years later, that is no longer the case for btrfs or ZFS on Linux.

5

Just spotted the "Comparison of file systems" page on Wikipedia. There's a snapshot capabilities column - just wanted people to be aware of this in the future.

Dave M
  • 4,494
Chopper3
  • 101,808
2

You should not use LVM snapshots for this purpose because they impose a big performance penalty (especially if you have multiple "rolling" snapshots active at the same time). Unfortunately Linux simply does not have any mature file systems with support for snapshots.

Therefore I recommend to use FreeBSD on your file server. The default UFS2 file system format supports snapshots. FreeBSD also includes proper ZFS implementation (unlike the ugly kludge found in Linux) with snapshots and many other very advanced features. When coupled with a simple tool such as this it is quite similar to what high-end storage vendors such as NetApp offer.

If you have one server dedicated to function as a file server, you might want to look at FreeNAS which packages FreeBSD and ZFS nicely into an appliance-like system.

snap
  • 1,251