MongoDB backup and recovery (mongorerstore)

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

MongoDB backup and recovery (mongorerstore)
MongoDB Data Backup

In Mongodb, we use the mongodump command to back up MongoDB data. This command can export all data to a specified directory.

The mongodump command can be used to specify the exported data-level transfer server.

Syntax

The mongodump Command Script syntax is as follows:

>mongodump -h dbhost -d dbname -o dbdirectory
  • -H:

    The server address where MongDB is located, such as 127.0.0.1. Of course, you can also specify the port number 127.0.0.1: 27017.

  • -D:

    Database instance to be backed up, for example: test

  • -O:

    The storage location of the backup data, for example, c: \ data \ dump. Of course, this directory must be created in advance. After the backup is complete, the system automatically creates a test directory under the dump directory, this directory stores the backup data of the database instance.

Instance

Start your mongod Service locally with 27017. Open the Command Prompt window, enter the bin directory of the MongoDB installation directory, and enter the command mongodump:

>mongodump

After the preceding command is executed, the client connects to the MongoDB service with the ip address 127.0.0.1 and port 27017, and backs up all the data to the bin/dump/directory. The command output result is as follows:

The mongodump command has the following optional parameters:

Syntax Description Instance
Mongodump -- host HOST_NAME -- port PORT_NUMBER This command backs up all MongoDB data Mongodump -- host w3cschool. cc -- port 27017
Mongodump -- dbpath DB_PATH -- out BACKUP_DIRECTORY   Mongodump -- dbpath/data/db/-- out/data/backup/
Mongodump -- collection COLLECTION -- db DB_NAME This command backs up the set of specified databases. Mongodump -- collection mycol -- db test
MongoDB data recovery

Mongodb uses the mongorerstore command to restore the backup data.

Syntax

The script syntax of the mongorestore command is as follows:

>mongorestore -h dbhost -d dbname --directoryperdb dbdirectory
  • -H:

    Address of the MongoDB Server

  • -D:

    The database instance to be restored, such as test. Of course, this name can also be different from that during backup, such as test2.

  • -- Directoryperdb:

    The location where the backup data is located, for example, c: \ data \ dump \ test. Why should I add another test instead of dump during Backup? Check the prompt for yourself!

  • -- Drop:

    When restoring, delete the current data first, and then restore the backup data. That is to say, after the restoration, all the data added and modified after the backup will be deleted. Use it with caution!

Run the following command:

>mongorestore

The output result is as follows:

For more MongoDB tutorials, see the following:

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

MongoDB beginners must read (both concepts and practices)

MongoDB Installation Guide for Ubunu 14.04

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

Nagios monitoring MongoDB sharded cluster service practice

Build MongoDB Service Based on CentOS 6.5 Operating System

MongoDB details: click here
MongoDB: click here

This article permanently updates the link address:

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.