Wednesday, May 19, 2010

Linux LVM Snapshot

LVM Snapshot use smaller logic volume to represent the whole data on the large logic volume and only save the data writing to the original LV when the snapshot LV is mounted. The snapshot LV will be automatically unmount when it is full. Thus the size of the snapshot LV must be larger than the possible data may changed during the time of the snapshot LV mount on the system.It is usfull when execute some script on the live system. For exmple back a database drive when the database still running.

To create a snapshot LV use following command:
# lvcreate -L10G -s -n snapshotName /dev/volgroupName/LVname

To mount a snapshot LV use following command:
# mkdir /mnt/locationName/snapshotLVName
# mount /dev/volgroupName/snapshotLVName /mnt/locationName/snapshotLVName
To backup a LV
tar -pczf /backups/root.tar.gz /mnt/locationName/snapshotLVName


To remove a snapshot LV use following command:

# umount
/mnt/locationName/LVName
# lvremove /dev/ops/dbbackup

No comments: