Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > HOWTO-Related Questions

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 28th February 2009, 19:59
atjensen11 atjensen11 is offline
Senior Member
 
Join Date: Dec 2007
Posts: 199
Thanks: 9
Thanked 6 Times in 6 Posts
Default Scripting LVM Snapshot Backups

I have a pretty simple, but tested and validated (unfortunately) backup script that I wrote. I am currenlty running the same script on each physical machine. Each machine backing up to a different external HD.

However, now that the new server I built is using Xen with LVM, I am rebuilding most of my physical machines as Xen virtual machines. So I believe I can simplify my backups by just taking snapshots of each LV for the virtual machines on the Dom0. I can then use my existing script to TAR that LV snapshot.

So I found this tutorial which is exactly what I want to do. I followed the tutorial and it works great for my situation. I would now like to automate it through a bash script so that I can create a cron job that runs in the middle of the night to perform the backups.

My question becomes, when I delete a LV (i.e. the snapshot volume was I am done with it), the user must enter y or n at the command line to confirm. How would I write my script to handle this extra confirmation step?
Reply With Quote
Sponsored Links
  #2  
Old 1st March 2009, 14:40
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,711
Thanks: 1,899
Thanked 2,702 Times in 2,545 Posts
Default

Code:
lvremove -f /dev/server1/rootsnapshot
(see man lvremove)
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
The Following User Says Thank You to falko For This Useful Post:
atjensen11 (7th March 2009)
  #3  
Old 7th March 2009, 18:47
atjensen11 atjensen11 is offline
Senior Member
 
Join Date: Dec 2007
Posts: 199
Thanks: 9
Thanked 6 Times in 6 Posts
Default

Thanks Falko. The -f command line parameter helped get past the confirmation dialog that would appear when issuing the lvremove command.

My script works really good right now. I am moving all of my physical servers to a Xen setup using LVM. I plan on using the script to iterate through the logical volumes and perform the backup on each one.

These are the steps right now that the backup script performs:

1. Create a snapshot logical volume
2. Verify the directory where the TAR file will be stored exists
3. Mount the snapshot logical volume to a temp location
4. Perform the backup using TAR
5. Unmount the snapshot logical volume at the temp location
6. Remove (delete) the snapshot logical volume
7. Send a confirmation email

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?

Can I simplify the script by not mounting/unmounting the snapshot logical volume (Steps 3 & 5 above)?

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.

Thanks.

Last edited by atjensen11; 7th March 2009 at 18:50.
Reply With Quote
  #4  
Old 8th March 2009, 01:55
atjensen11 atjensen11 is offline
Senior Member
 
Join Date: Dec 2007
Posts: 199
Thanks: 9
Thanked 6 Times in 6 Posts
Default

With some help from Google, I think I answered a few of my own questions.

Quote:
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.

Code:
# 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
Quote:
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.

Code:
# 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."
        exit 1
fi
Reply With Quote
  #5  
Old 12th April 2009, 13:44
Hans Hans is offline
Moderator
 
Join Date: Dec 2005
Location: Montfoort, The Netherlands
Posts: 2,256
Thanks: 210
Thanked 648 Times in 294 Posts
Send a message via Skype™ to Hans
 
Smile xenbackup script

I've found i nice article and script as well to create backups of xen domains here.

The final xenbackup script can be downloaded here.

The final version of the xenbackup has also:
- Added basic functionality to use LVM snapshots
- Added NTFS mounting support

xenbackup has been tested on Debian, with some small modifications, it should work on other Linux distro's as well.
__________________
Hans

BB-Hosting | Quality Web Hosting since 2005
Reply With Quote
The Following User Says Thank You to Hans For This Useful Post:
falko (13th April 2009)
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu 8.04 LTS - RAID 1 + LVM + XEN atjensen11 HOWTO-Related Questions 1 20th January 2009 20:35
Unable to repair/re-install ubunt svr ubuntu 8.04/8.10 on RAID 5 LVM lucy_t Installation/Configuration 5 19th December 2008 20:59
debian, lvm, raid, grub, custom kernel koi Installation/Configuration 4 3rd November 2007 10:39
rsync incremental snapshot backups gabrix HOWTO-Related Questions 13 11th December 2006 22:29
Xen: Smp & Lvm zokahn HOWTO-Related Questions 5 27th January 2006 10:28


All times are GMT +2. The time now is 00:47.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.