Backing up a living system
No Silver Bullets
Snapshots don't come free of disadvantages. The main disadvantage, as previously discussed, is that using snapshots requires careful planning. If you intend to use snapshots as part of your backup strategy for a folder, you need to store the contents of that folder on snapshot-capable storage to begin with.
Another issue is performance. LVM in particular is known for taking a performance hit when it must keep multiple snapshots taken from the same filesystem [3].
The biggest problem with LVM snapshots, however, is that their life is finite. LVM snapshots track the changes done to the original filesystem (see the box "How Do LVM Snapshots Work?"). If enough changes are done to the original filesystem, the LVM snapshot will run out of space to register the changes. Modern LVM supports dynamic expansion of the snapshot volume if it detects it is running out of room [4], but hard drive space is finite and the snapshot may yet be dropped if it needs to grow past the physical storage medium's capabilities.
How Do LVM Snapshots Work?
An LVM snapshot volume does not actually contain a copy of all the files as they were in the original filesystem when the snapshot was taken.
When a snapshot is taken, the volume manager takes note of the state of the original filesystem at the time of the snapshot. When a file is modified after the snapshot is taken, the old version of the file (the one you would expect to find in a snapshot) is moved to the snapshot volume area. This way, the snapshot volume only contains copies of data that has been modified since the snapshot point.
The snapshot volume can be mounted as a regular filesystem. If the user tries to access a file through the snapshot, LVM checks if the file has been modified since the snapshot point. If not, the file is retrieved from the original filesystem. If the file has been modified, the version from the snapshot area is retrieved instead.
As a result, a snapshot volume does not need to be as large as the original volume because it only contains the changes between the snapshot and the current date. Using a small snapshot volume, however, comes with risks: If the original is modified to the point that the changes are larger than the snapshot volume, the snapshot volume will be dropped and rendered broken. It is, therefore, important to allocate enough room for the snapshot volume.
Not every filesystem is suitable for use in conjunction with LVM snapshots. Filesystems must support freezing in order to guarantee that the resulting snapshots are in a consistent state when they are taken. XFS and ext4 are known to work well, and there are more options [2].
It is worth noticing that many applications with data you might want to back up don't guarantee the consistency of their files while the application is running. For example, a busy database might work asynchronously, keeping many operations in a RAM cache and committing them to disk periodically. Creating a backup that perfectly mirrors the filesystem the database is stored in will then create a copy with inconsistent data, because many database operations may not have been committed to disk. It is important to check the documentation of the programs you are backing up in order to learn of potential pitfalls.
Conclusions
Classic Unix tools are not advisable for making backups for files and folders that are being modified during the process, because backup corruption can occur as a result. This article has covered LVM as a safer alternative for Linux, but there are other tools for the task, including ZFS and BTRFS snapshots.
Many programs, especially services intended for production, suggest their own means for creating backups (Figure 4). Databases are notorious for including their own backup utilities, and if you are indeed using a real database (such as MariaDB or PostgreSQL) you should consider using their tools instead of backup utilities that operate at filesystem or block device level.
Infos
- "Is Dump Really Deprecated?" by Antonios Christofides: https://dump.sourceforge.io/isdumpdeprecated.html#canusedump
- Freeze support committed into the kernel for a number of filesystems: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c4be0c1dc4cdc37b175579be1460f15ac6495e9a
- "LVM Snapshot Performance" by John Leach: https://johnleach.co.uk/posts/2010/06/18/lvm-snapshot-performance/
- "[PATCH] automatic snapshot extension with dmeventd (BZ 427298)": https://listman.redhat.com/archives/lvm-devel/2010-October/msg00010.html
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.