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?
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.
With some help from Google, I think I answered a few of my own questions.
$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.
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.
|All times are GMT +2. The time now is 16:30.|
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.