Backup LVM file system with SELinux context
Backup is one of the most crucial operations for providing availability of the computer system. Although writing backup scripts is an easy task, there are few points with LVM and SELinux which are described below.
LVM is a logical volume manager for the Linux kernel. One of the key features of LVM is generating snapshots for logical volumes. This allows the administrator to create a new block device which presents an exact copy of a logical volume, frozen at some point in time. It is very useful for backups - we can make backups without stopping volumes. Snapshots can be created with 'lvcreate' command with '-s' option.
SELinux is an implementation of a flexible mandatory access control architecture in the Linux operating system. It uses file labelling with special security context. During a usual file archiving this context could be lost, so the administrator should use special archivers like 'star'.
So, the administrator should use following procedure for archiving LVM volumes with SELinux enabled:
- Create a snapshot of required volume.
- Mount this snapshot.
- Make star-archive of the snapshot to required location.
- Unmount the snapshot.
- Delete the snapshot.
A sample script is below:
#!/bin/sh /sbin/lvcreate -L5G -s -n homesnapshot /dev/VolGroup00/home mount /dev/VolGroup00/homesnapshot /mnt/homesnapshot star -xattr -H=exustar -v -c -f /media/work/backups/home.star /mnt/homesnapshot/ umount /mnt/homesnapshot /sbin/lvremove -f /dev/VolGroup00/homesnapshot
Have fun with backups!