Taking a Backup Using Snapshots (from “LVM HOWTO” Ch.13)

Pubblicato il Pubblicato in System administrator

1. Create the snapshot volume

​There is a little over 500 Megabytes of free space in the “ops” volume group, so we will use all of it to allocate space for the snapshot logical volume. A snapshot volume can be as large or a small as you like but it must be large enough to hold all the changes that are likely to happen to the original volume during the lifetime of the snapshot. So here, allowing 500 megabytes of changes to the database volume which should be plenty.

# lvcreate -L592M -s -n dbbackup /dev/ops/databases
lvcreate — WARNING: the snapshot must be disabled if it gets full
lvcreate — INFO: using default snapshot chunk size of 64 KB for “/dev/ops/dbbackup” lvcreate — doing automatic backup of “ops”
lvcreate — logical volume “/dev/ops/dbbackup” successfully created

Full snapshot are automatically disabled

​If the snapshot logical volume becomes full it will be dropped (become unusable) so it is vitally important to allocate enough space. The amount of space necessary is dependent on the usage of the snapshot, so there is no set recipe to follow for this. If the snapshot size equals the origin size, it will never overflow.

2. Mount the snapshot volume

​We can now create a mount-point and mount the volume

# mkdir /mnt/ops/dbbackup
# mount /dev/ops/dbbackup /mnt/ops/dbbackup
mount: block device /dev/ops/dbbackup is write-protected, mounting read-only

​If you are using XFS as the filesystem you will need to add the nouuidoption to the mount command: ​# mount /dev/ops/dbbackup /mnt/ops/dbbackup -onouuid,ro

3. Do the backup

http://www.tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html 1/2

3/26/2014 Taking a Backup Using Snapshots ​I assume you will have a more sophisticated backup strategy than this!

# tar -cf /dev/rmt0 /mnt/ops/dbbackup
tar: Removing leading `/’ from member names

4. Remove the snapshot

​When the backup has finished you can now unmount the volume and remove it from the system. Y ou should remove snapshot volume when you have finished with them because they take a copy of all data written to the original volume and this can hurt performance.

# umount /mnt/ops/dbbackup
# lvremove /dev/ops/dbbackup
lvremove — do you really want to remove “/dev/ops/dbbackup”? [y/n]: y lvremove — doing automatic backup of volume group “ops”

lvremove — logical volume “/dev/ops/dbbackup” successfully removed