Created
August 8, 2012 21:14
-
-
Save bcarpio/3298834 to your computer and use it in GitHub Desktop.
lvsnapshot.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE=`date +"%a"` | |
DVOLNAME=datalv | |
LVOLNAME=journallv | |
VOLGR=datavg | |
DVOLPATH=/dev/$VOLGR/$DVOLNAME | |
LVOLPATH=/dev/$VOLGR/$LVOLNAME | |
DSNAME=`echo ${DVOLNAME}_ss_${DATE} | tr '[A-Z]' '[a-z]'` | |
LSNAME=`echo ${LVOLNAME}_ss_${DATE} | tr '[A-Z]' '[a-z]'` | |
DSNAPSHOT=/dev/$VOLGR/$DSNAME | |
LSNAPSHOT=/dev/$VOLGR/$LSNAME | |
DSIZE="5GB" | |
LSIZE="2GB" | |
if [ -e $DSNAPSHOT ] | |
then | |
/bin/umount $DSNAPSHOT > /dev/null 2>&1 | |
/sbin/lvremove -f $DSNAPSHOT > /dev/null 2>&1 | |
fi | |
if [ -e $LSNAPSHOT ] | |
then | |
/bin/umount $LSNAPSHOT > /dev/null 2>&1 | |
/sbin/lvremove -f $DSNAPSHOT > /dev/null 2>&1 | |
fi | |
/sbin/lvcreate -L$DSIZE -s -n $DSNAPSHOT $DVOLPATH > /dev/null 2>&1 | |
if [ $? = 0 ] | |
then | |
echo "Snapshot $DSNAPSHOT Created" | |
else | |
echo "Snapshot $DSNAPSHOT Failed" | |
fi | |
/sbin/lvcreate -L$LSIZE -s -n $LSNAPSHOT $LVOLPATH > /dev/null 2>&1 | |
if [ $? = 0 ] | |
then | |
echo "Snapshot $LSNAPSHOT Created" | |
else | |
echo "Snapshot $LSNAPSHOT Failed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If your database and journal are on different filesystems, you need to run db.fsyncLock() before creating the snapshots to ensure a consistent backup. See the bottom of http://docs.mongodb.org/manual/tutorial/backup-with-filesystem-snapshots/