With some help from Google, I think I answered a few of my own questions.
Is there a way to determine the size of the logical volume that a snapshot volume will be created from? Currently, the size of the snapshot volume is hard coded in my script. I would rather test for the size of the logical volume prior to creating the snapshot volume and then pass the size to my lvcreate command.
Reading the MAN pages a bit, I found that I could use the lvdisplay command with the -c parameter which would output all of the details about the logical volume in one string with colons between the fields. The size is the seventh field and is reported in KB. I then found that I could use the cut command to parse the fields by the colon delimeter. So I came up with the solution below.
$LVM_NAME_PATH is the name of the logical volume for which a snapshot volume will be created.
$LVM_SNAPSHOT_NAME is the name of the new snapshot volume that is to be created.
# Query size of Logical Volume
LVM_SIZE="`lvdisplay -c $LVM_NAME_PATH | cut -d':' -f7`K"
# Create Snapshot Logical Volume
lvcreate -L $LVM_SIZE -s -n $LVM_SNAPSHOT_NAME $LVM_NAME_PATH
I know how to test if directories exist in my bash script (Step 2 above). How can I test if the logical volume exists before performing the backup?
I wasn't so sure about this one, so I copied a previous example where I had scripted a check to see if a directory existed and then tested it on the logical volume name. The following appears to work.
# Verify Logical Volume Snapshot Exits
if [ ! -d $LVM_SNAPSHOT_NAME_PATH ]; then
echo "Error - The specified snapshot volume $LVM_SNAPSHOT_NAME_PATH could not be found or does not exist. Operation canceled."