MongoDB Backup Script

Source: Internet
Author: User
Tags mongodb

#!/bin/bash
Sourcepath= '/mnt/mongodb/bin '
Targetpath= '/mnt/mongodb/back ' #备份目录
nowtime=$ (Date +%y%m%d)

Start ()
{
${sourcepath}/mongodump--host 127.0.0.1--port 20011-uadmin-p ' password '--authenticationdatabase admin--out ${targetpath}/ ${nowtime}
}
Execute ()
{
Start
If [$?-eq 0]
Then
echo "Back successfully!"
Else
echo "Back failure!"
Fi
}

if [!-D "${targetpath}/${nowtime}/"]
Then
mkdir ${targetpath}/${nowtime}
Fi
Execute
echo "============== back end ${nowtime} =============="

If [-D "${targetpath}/${nowtime}/"]
Then
Cd/mnt/mongodb/back
Tar-cvzf ${targetpath}/${nowtime}.tar.gz ${nowtime}
Fi
Execute
echo "============== back end ${nowtime} =============="

If [-D "${targetpath}/${nowtime}/"]
Then
rm-rf/mnt/mongodb/back/"${nowtime}"
Fi
find/mnt/mongodb/back/-type f-name "*.tar.gz"-mtime +6| Xargs rm-fr {}; #只保留6天的备份文件.

MongoDB Backup Script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.