A tutorial on backing up and restoring MongoDB data in Windows or Linux systems _mongodb

Source: Internet
Author: User
Tags mongodb mongodb server server port mongodump mongorestore

MongoDB database backup and recovery under Windows

I can tell the data back to the C:\data\dump directory, first create this path. And then go under the Bin directory of MongoDB.

Mine is:

C:\Program Files\mongodb\bin

The backup script is:

Backup
mongodump-h 127.0.0.1:27017-d test-o c:\data\dump

The recovery script is:

Restore
 mongorestore-h 127.0.0.1:27017-d test--directoryperdb c:\data\dump\test

Explain the command you used.

    • -h:mongodb server Address
    • -D: database instance that needs to be recovered, for example: Test, of course, this name can also be different from the backup time, such as Test2
    • -O: Backup data storage location, such as: C:\data\dump, of course, the directory needs to be established in advance, after the backup is completed, the system automatically set up a test directory in the Dump directory, which contains the database instance of the backup data.
    • --directoryperdb: Where to back up your data, for example: C:\data\dump\test, why do you want to add a test instead of a backup dump, and read the prompts yourself?
    • --drop: When you restore, delete the current data, and then restore the backed-up data. That is, after the recovery, after the backup to add modified data will be deleted, carefully use Oh!

Original explanation:

 -V [--verbose] is more verbose (include multiple times for more verbosity e.g.-VVVVV) --version Print the program's version and Exit-h [--host] arg MONGO host to connect to (<s ET name>/s1,s2 for sets)--port ARG server port.
                    Can also use--host hostname:port--ipv6 enable IPV6 support (disabled by  default)-u [--username] arg username-p [--password] arg password--authenticationdatabase ARG user source (defaults to dbname)--authenticationmechanism Arg (=MONGODB-CR) authentication Mechanism--dbpath arg directly access Mongod database files in the given path, instead o
                    F connecting to a Mongod server-needs to lock's data directory, so cannot
           be used if a mongod is currently         Accessing the same path--DIRECTORYPERDB each db are in a separate directly (Releva NT only if dbpath specified)--journal enable journaling (relevant only if DBPath Speci fied)-d [--DB] arg database to use-c [--collection] arg collection to use (some commands)--obj  Check Validate object before inserting (default)--noobjcheck don ' t validate object before inserting--filter arg filter to apply before inserting--drop drop each Colle Ction before import--oplogreplay replay oplog for Point-in-time restore--oploglimit arg include Oplog entries before the provided Timestamp (seconds[:ordinal)) during the Oplog R Eplay; The ordinal value is optional--keepindexversion don ' t upgrade indexes to newest version-- Nooptionsrestore         Don ' t restore collection options--noindexrestore don ' t restore indexes--w ARG (=0) Mini
 Mum number of replicas per write

Linux below MongoDB database backup and Recovery

Linux below we can create an automatic backup script, you can set a timed task, or you can manually back up. I backed it up manually.

First create an SH command, I put it underneath the home.

vim/home/mongobeifen.sh

Enter the following:

#!/bin/bash
shijie= ' date +%y%m%d%h '
backmongodbfile=mongodb$shijie.tar.gz
cd/home/mongodbback/
/usr/local/mongo/bin/mongodump-h 127.0.0.1--port 27017-u mongo-p 123456-d my_mongodb-o my_mongodb_dump/
tar czf $backmongodbFile my_mongodb_dump/
RM my_mongodb_dump-rf 

Explain:

The folder that holds the backup is/home/mongodbback/

-U is the database name user name-P is the password-D is the database name specific and window almost, you can look at the above Windows explanation.

When you back up, just run it.

./mongobeifen.sh  

It's OK.

Database recovery:

 
 

Point to each file

Copy Code code as follows:

/usr/local/mongo/bin/mongorestore-h 127.0.0.1--port 27017--Drop--directoryperdb My_mongodb_dump/my_mongodb

Point to a directory
If you have a problem, you can try the window's wording:

Copy Code code as follows:

/usr/local/mongo/bin/mongorestore-h 127.0.0.1:27017-d test--drop--directoryperdb My_mongodb_dump/my_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.