Making consistent Backups is key to successful disaster recovery. I've found LVM and its snapshot functionality very helpful in that regard. So I'll cover how to create a snapshot and back it up in a consistent state and restore reliably. First things first, you'll need to have some free space in your volume group, I'll be demonstrating this in a virtual machine.
First up, let's start by creating a snapshot of a volume:
[archy@server ~]$ sudo lvmcreate -s -n lv_home_$(date +%Y%m%d) -L 10G /dev/vg_base/lv_home
This will create a snapshot with 10G COW Space which will fill up once you are writing to the lvm you've specified above. In my case, it's the '/home' mount point on the system and I'm assuming that while the backup is running, I won't write 10G of data. Keep in mind that it is possible to create automatic extending snapshots using the lvm.conf but I will not cover that here.
With the snapshot created we can now mount it and rsync the files from it to our backup destination.
Ideally, this task should be automated.
[archy@server ~]$ sudo mkdir /mnt/backup
[archy@server ~]$ sudo mount /dev/vg_base/lv_home_20191113 /mnt/backup
[archy@server ~]$ sudo rsync -vrlptgoDxh --progress -e ssh /mnt/backup/ archy@strgnas01.archyslife.lan:/srv/data/home/
Once rsync is done, the lvm can be unmounted and deleted since it's of no use anymore in this case.
[archy@server ~]$ sudo umount /mnt/backup
[archy@server ~]$ sudo lvremove --force /dev/vg_bade/lv_home_20191113
If you decide to keep the snapshot, you will be able to revert to it using lvconvert. In order to do that, you'll need to unmount the source lvm. So I'll have to log out and continue as root.
Make sure, you have no files left open which are writing to the source lvm's mount point:
[root@server ~]# lsof | grep -i '/home'
If nothing is open, you can continue.
[root@server ~]# umount /home
[root@server ~]# lvconvert --merge /dev/vg_base/lv_home_20191113
After completion, you can mount your source lvm again and log in as your normal user. Everything should be back at the point where you took the snapshot now.
Conclusion:
With LVM it is fairly simple to create persistent backups from snapshots. Now there's always zfs on linux but this happens to be rather rare in installers and especially rare with kickstart / preseed integration in the server environment. So at the time writing this, LVM is, in my opinion, your best choice.
Conclusion:
With LVM it is fairly simple to create persistent backups from snapshots. Now there's always zfs on linux but this happens to be rather rare in installers and especially rare with kickstart / preseed integration in the server environment. So at the time writing this, LVM is, in my opinion, your best choice.
Feel free to comment and / or suggest a topic.
Comments
Post a Comment