MongoDB Backup
Backup is done using mongodump utility.
1.) Mongodump : This utility will backup up full mongodb in the current directory
[mongod@sikki4u1c backup]$ mongodump -u mongo-root -p passw0rd
2019-08-19T10:46:03.367+0000 writing admin.system.users to
2019-08-19T10:46:03.367+0000 done dumping admin.system.users (3 documents)
2019-08-19T10:46:03.367+0000 writing admin.system.version to
2019-08-19T10:46:03.368+0000 done dumping admin.system.version (2 documents)
2019-08-19T10:46:03.368+0000 writing movie.mycol to
2019-08-19T10:46:03.368+0000 writing demo.peeps to
2019-08-19T10:46:03.368+0000 writing movie.movie to
2019-08-19T10:46:03.369+0000 done dumping demo.peeps (1 document)
2019-08-19T10:46:03.369+0000 done dumping movie.mycol (3 documents)
2019-08-19T10:46:03.377+0000 done dumping movie.movie (1 document)
[mongod@sikki4u1c backup]$ ls -ltr
total 0
drwxrwxr-x. 5 mongod mongod 41 Aug 19 10:46 dump
[mongod@sikki4u1c backup]$ cd dump/
[mongod@sikki4u1c dump]$ ls -ltr
total 4
drwxrwxr-x. 2 mongod mongod 4096 Aug 19 10:46 admin
drwxrwxr-x. 2 mongod mongod 92 Aug 19 10:46 movie
drwxrwxr-x. 2 mongod mongod 49 Aug 19 10:46 demo
[mongod@sikki4u1c dump]$ pwd
/home/mongod/backup/dump
[mongod@sikki4u1c dump]$
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5.) Mongodump for single collection backup
[mongod@sikki4u1c dump]$ mongodump -u mongo-root -p passw0rd --host 127.0.0.1 --port 27017 --out /home/mongod/backup/dump --authenticationDatabase admin --db movie --collection mycol
2019-08-19T11:01:26.023+0000 writing movie.mycol to
2019-08-19T11:01:26.024+0000 done dumping movie.mycol (3 documents)
[mongod@sikki4u1c dump]$
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1.) Mongodump : This utility will backup up full mongodb in the current directory
[mongod@sikki4u1c backup]$ mongodump -u mongo-root -p passw0rd
2019-08-19T10:46:03.367+0000 writing admin.system.users to
2019-08-19T10:46:03.367+0000 done dumping admin.system.users (3 documents)
2019-08-19T10:46:03.367+0000 writing admin.system.version to
2019-08-19T10:46:03.368+0000 done dumping admin.system.version (2 documents)
2019-08-19T10:46:03.368+0000 writing movie.mycol to
2019-08-19T10:46:03.368+0000 writing demo.peeps to
2019-08-19T10:46:03.368+0000 writing movie.movie to
2019-08-19T10:46:03.369+0000 done dumping demo.peeps (1 document)
2019-08-19T10:46:03.369+0000 done dumping movie.mycol (3 documents)
2019-08-19T10:46:03.377+0000 done dumping movie.movie (1 document)
[mongod@sikki4u1c backup]$ ls -ltr
total 0
drwxrwxr-x. 5 mongod mongod 41 Aug 19 10:46 dump
[mongod@sikki4u1c backup]$ cd dump/
[mongod@sikki4u1c dump]$ ls -ltr
total 4
drwxrwxr-x. 2 mongod mongod 4096 Aug 19 10:46 admin
drwxrwxr-x. 2 mongod mongod 92 Aug 19 10:46 movie
drwxrwxr-x. 2 mongod mongod 49 Aug 19 10:46 demo
[mongod@sikki4u1c dump]$ pwd
/home/mongod/backup/dump
[mongod@sikki4u1c dump]$
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2.) mongodump - with more option and explicitly mention the output directory
[mongod@sikki4u1c backup]$ mongodump -u mongo-root -p passw0rd --host 127.0.0.1 --port 27017 --out /home/mongod/backup/dump
2019-08-19T10:50:39.928+0000 writing admin.system.users to
2019-08-19T10:50:39.928+0000 done dumping admin.system.users (3 documents)
2019-08-19T10:50:39.928+0000 writing admin.system.version to
2019-08-19T10:50:39.929+0000 done dumping admin.system.version (2 documents)
2019-08-19T10:50:39.929+0000 writing movie.mycol to
2019-08-19T10:50:39.929+0000 writing demo.peeps to
2019-08-19T10:50:39.929+0000 writing movie.movie to
2019-08-19T10:50:39.929+0000 done dumping movie.mycol (3 documents)
2019-08-19T10:50:39.930+0000 done dumping demo.peeps (1 document)
2019-08-19T10:50:39.938+0000 done dumping movie.movie (1 document)
[mongod@sikki4u1c backup]$
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.) MOngodump with oplog: tells mongodump to capture operations that occured during the backup process. this allows better point in time backup.
mongodump -u mongo-root -p passw0rd --host 127.0.0.1 --port 27017 --out /home/mongod/backup/dump --oplog
NOTE: --oplog works only for replica sets
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4.) MOngodump for specific database:
[mongod@sikki4u1c dump]$ mongodump -u mongo-root -p passw0rd --host 127.0.0.1 --port 27017 --out /home/mongod/backup/dump --authenticationDatabase admin --db movie
2019-08-19T10:59:35.393+0000 writing movie.mycol to
2019-08-19T10:59:35.393+0000 writing movie.movie to
2019-08-19T10:59:35.394+0000 done dumping movie.movie (1 document)
2019-08-19T10:59:35.394+0000 done dumping movie.mycol (3 documents)
[mongod@sikki4u1c dump]$
4.) MOngodump for specific database:
[mongod@sikki4u1c dump]$ mongodump -u mongo-root -p passw0rd --host 127.0.0.1 --port 27017 --out /home/mongod/backup/dump --authenticationDatabase admin --db movie
2019-08-19T10:59:35.393+0000 writing movie.mycol to
2019-08-19T10:59:35.393+0000 writing movie.movie to
2019-08-19T10:59:35.394+0000 done dumping movie.movie (1 document)
2019-08-19T10:59:35.394+0000 done dumping movie.mycol (3 documents)
[mongod@sikki4u1c dump]$
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5.) Mongodump for single collection backup
[mongod@sikki4u1c dump]$ mongodump -u mongo-root -p passw0rd --host 127.0.0.1 --port 27017 --out /home/mongod/backup/dump --authenticationDatabase admin --db movie --collection mycol
2019-08-19T11:01:26.023+0000 writing movie.mycol to
2019-08-19T11:01:26.024+0000 done dumping movie.mycol (3 documents)
[mongod@sikki4u1c dump]$
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6.) Mongodump for multiple collection backup
This is bit tricky:
[mongod@sikki4u1c dump]$ colls=(movie mycol)
[mongod@sikki4u1c dump]$ for c in ${colls[@]}
> do
> mongodump -u mongo-root -p passw0rd --host 127.0.0.1 --port 27017 --out /home/mongod/backup/dump --authenticationDatabase admin --db movie --collection $c
> done
2019-08-19T11:06:55.752+0000 writing movie.movie to
2019-08-19T11:06:55.753+0000 done dumping movie.movie (1 document)
2019-08-19T11:06:55.785+0000 writing movie.mycol to
2019-08-19T11:06:55.787+0000 done dumping movie.mycol (3 documents)
[mongod@sikki4u1c dump]$ ls -ltr
total 0
drwxrwxr-x. 2 mongod mongod 92 Aug 19 11:06 movie
[mongod@sikki4u1c dump]$ cd movie/
[mongod@sikki4u1c movie]$ ls
movie.bson movie.metadata.json mycol.bson mycol.metadata.json
[mongod@sikki4u1c movie]$ ls -ltr
total 16
-rw-rw-r--. 1 mongod mongod 125 Aug 19 11:06 movie.metadata.json
-rw-rw-r--. 1 mongod mongod 48 Aug 19 11:06 movie.bson
-rw-rw-r--. 1 mongod mongod 184 Aug 19 11:06 mycol.metadata.json
-rw-rw-r--. 1 mongod mongod 663 Aug 19 11:06 mycol.bson
[mongod@sikki4u1c movie]$
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home