Skip to content

Instantly share code, notes, and snippets.

@henter
Created September 19, 2013 19:37
Show Gist options
  • Save henter/6628729 to your computer and use it in GitHub Desktop.
Save henter/6628729 to your computer and use it in GitHub Desktop.
备份mongodb
#!/bin/bash
# from http://cnodejs.org/topic/510b4923df9e9fcc58f74c44
nowtime=`date +%Y-%m-%d`
echo "============= backup start ${nowtime}============="
parentpath=/opt/mongodbbackup
cd ${parentpath}
start()
{
/usr/bin/mongodump -h 127.0.0.1 -d dbname -o ${parentpath}/${nowtime}
tar czf ${parentpath}/${nowtime}.tar.gz ${parentpath}/${nowtime}/
rm -rf ${parentpath}/${nowtime}/
}
execute()
{
start
if [ $? -eq 0 ]
then
echo "back successfully!"
else
echo "back failure!"
fi
}
if [ ! -d ${parentpath}/${nowtime} ]
then
mkdir ${parentpath}/${nowtime}/
fi
execute
echo "============= backup end ${nowtime}============="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment