Skip to content

Instantly share code, notes, and snippets.

@bcarpio
Created August 8, 2012 21:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bcarpio/3298834 to your computer and use it in GitHub Desktop.
Save bcarpio/3298834 to your computer and use it in GitHub Desktop.
lvsnapshot.sh
#!/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
@camschaus
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment