Back-up of /home of a running system using lv snapshot

By | October 19, 2017

Following is a simple and easy way to do a consistent back-up of the /home directory (usually mounted in a separate partition) on a running system.
We do not have the luxury of being able to stop the operations of a server and unmount the home partition to make sure no changes are done during the back-up. To be able to pull this off we use the wonderful feature of logical volume snapshot.

STEP 1: Check the logical volume and physical volume status

STEP 2: Free some space on the physical volume
The problem now is the whole physical volume is filled and there is no free space for the logical volume snapshot. We can try to shrink some logical volume but both /dev/fedora/home and /dev/fedora/root are mounted and we cannot shrink a mounted partition.
The solution is the swap logical volume.

STEP 3: Shrink the swap space

First disable the swap

Then reduce the swap logical volume

Format the new smaller swap

Activate the new smaller swap

Check the new status of the physical volume

STEP 4: Create the logical volume snapshot

We see that we have now more than 1GB free on the physical volume. As our “/dev/fedora/home” is relatively small and by choosing a down time when not a lot of IO operations are going on we hope we will not have more than 1GB of data written to /home during the back-up.
It is important that the size of the logical volume snapshot is bigger than the potential additional data that will be added to the original logical volume. If you feel that you need more space make sure to make more free space on the volume.

Check that the snapshot is created:

STEP 5: Do the back-up

At this step just mount the new snapshot logical volume under /mnt and proceed with the back-up.
The back-up can be a simple copy to another disk, tape or network resource.

STEP 6: Clean-up

After the back-up is done we have to execute the clean-up.
Unmount the snapshot logical volume

Remove the snapshot:

Note that the changes that happened on the original logical volume during the back-up were recorded on the snapshot.
By removing the snapshot we are applying from the snapshot the changes to the original logical volume and free the space allocated by the snapshot.

All done: we did a consistent back-up of the /home while the system is running. At this point we can even revert the swap space to its old size.

Contribute to this site maintenance !

This is a self hosted site, on own hardware and Internet connection. The old, down to earth way 🙂. If you think that you found something useful here please contribute. Choose the form below (default 1 EUR) or donate using Bitcoin (default 0.0001 BTC) using the QR code. Thank you !



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.