MongoDB Sixth article ~ Automatic backup script for MongoDB

Source: Internet
Author: User
Tags mongodb

A brief introduction: Today happened to write a backup script about MongoDB, share the next

Two-Frontier: This script applies to single-instance and replica sets, not for Shard clusters

Three contents:

#!/bin/sh

User=
password=
port=
ip= '/sbin/ifconfig eth0 | grep ' inet addr ' | Cut-d:-f2 | awk ' {print '} ' | Cut-d '. '-f ' 3,4 '
date1= ' Date +%y%m%d%h '
date2= ' Date +%y%m '
Backupdir1= "/backup/mongodb/$DATE 2/"
Backupdir2= $IP "_" $DATE 1 "_" $port


If [-D $backupdir 1];then
echo "Dir exist"
Else
Mkdir-p $backupdir 1
Fi
CD $backupdir 1
mkdir $backupdir 2

Mongodump-u$user-p$password--port= $port--oplog--authenticationdatabase admin-o $backupdir 2

Tar czf $backupdir 2.tar.gz $backupdir 2
RM-FR $backupdir 2
Sync;sync
Sleep 2

Four points of attention:

Data changes during backup are recorded in Oplog mode, similar in principle to xtrabackup

Nothing to say these days more busy, write less haha

MongoDB Sixth article ~ Automatic backup script for MongoDB

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.