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
-
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.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.