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