You are not logged in.
Background
I'm quite technical and fairly familiar with Linux, but I'm new to Arch and LVM so I thought Newbie Corner would be the safe option for this question! ![]()
I have a LVM volume group which contains my root and home partitions. After learning about LVMs snapshot abilities, it piqued my interest and I started thinking about how this could be used for backups.
Below is a little script I have which backs up to media I have mounted at "/mnt/data". Currently this is just another partition, but were I to actually use this script long-term, I'd probably push the tar off to a network location for safety.
I took heavy inspiration from this Wiki page.
I've actually tried this script, and it does backup without error. Also, after I booted from a Live Arch USB, I tried deleting the contents of the root and home partitions on the hard drive, then restoring from the tars using the command at the bottom, rebooting and it seemingly works!
Question
So I guess my question is ultimately - is this a good method for backing up? Despite it seemingly working in my first tests, would there be any drawbacks that I don't foresee?
Code
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
dateString=$(date --utc +%Y-%m-%d_%H-%M-%SZ)
homeName=home_$dateString
rootName=root_$dateString
lvcreate --size 1G --snapshot --name $homeName /dev/lvmVg/home
lvcreate --size 1G --snapshot --name $rootName /dev/lvmVg/root
mkdir /mnt/$homeName
mkdir /mnt/$rootName
mount /dev/lvmVg/$homeName /mnt/$homeName
mount /dev/lvmVg/$rootName /mnt/$rootName
tar --acls --xattrs -cpvf /mnt/data/$homeName.tar.gz -C /mnt/$homeName/ --exclude=./lost+found .
tar --acls --xattrs -cpvf /mnt/data/$rootName.tar.gz -C /mnt/$rootName/ --exclude=./lost+found .
umount /mnt/$homeName
umount /mnt/$rootName
rmdir /mnt/$homeName
rmdir /mnt/$rootName
lvremove -y /dev/lvmVg/$homeName
lvremove -y /dev/lvmVg/$rootName#cd into directory and run this code on backup tar
tar --acls --xattrs -xpf backupfileOffline
So I guess my question is ultimately - is this a good method for backing up?Why bother with the snapshot? Why not just tar or rsync your most important files?
If it's just a facility to revert back to an older state of the system then by all means use the snapshot but I would keep it simple particularly for the precious files. Many would agree that snapshots are not backups.
Last edited by d_fajardo (2021-05-18 06:43:52)
Offline
I do similar kinds of backups here with btrfs instead of LVM.
A problem is that restoring from this kind of backup is like a crash from the point of view of the system because it was snapshot of a running system. I did restore from my backups several times and it always worked out fine but this might not always be the case.
Why bother with the snapshot? Why not just tar or rsync [...] files?
With the snapshot you have a guarantee that the files are not changing while your tar or rsync command is running.
If you already have a setup that can do snapshots, it just makes sense to do a snapshot and then run tar/rsync on that snapshot instead of on your live files.
Offline
Thanks, both, for the replies!
Why bother with the snapshot? Why not just tar or rsync [...] files?
As Ropid mentioned, it seems like a useful way of freezing the filesystem in place to carry out a backup.
It also means I don't have to worry about special files in places like /proc/ - as far as I'm aware it's just "real" files.
Although if someone more knowledgeable could confirm my assumptions here that would be handy ![]()
I do similar kinds of backups here with btrfs instead of LVM.
A problem is that restoring from this kind of backup is like a crash from the point of view of the system because it was snapshot of a running system. I did restore from my backups several times and it always worked out fine but this might not always be the case.
That's a really good point.
My hope was that should I need to use this, it'd be the equivalent to having a hard drive state where a cold, sudden shutdown had occurred, and modern systems seem completely resilient to that. But it could be that I'm being optimistic.
One thing that I wish I could do is have the two snapshots occur truly simultaneously. I doubt one happening milliseconds after another is a huge issue, but I guess theoretically it could still lead to some inconsistency if during the snapshots there is a process working on root and home partitions simultaneously.
Offline
it'd be the equivalent to having a hard drive state where a cold, sudden shutdown had occurred
That is what snapshots can do but I don't see a need for backing up the snapshot.
I would still recommend a hard copy backup, even without compression, of your most important files. Otherwise doing a backup of a snapshot is adding layers of complication where what you actually need is a genuine reproduction of the original, at least to the most important data.
Offline
Additionally LVM snapshots are known to have significant performance implications, read up on this and then decide if this is still a method that makes sense for your use case and needs.
"the wind-blown way, wanna win? don't play"
Offline