mongodb uses mongodump for data backup and restore

MongoDB data backup

In Mongodb we use the mongodump command to backup MongoDB data. This command can export all data to the specified directory.

The mongodump command can specify the server where the exported data is dumped by parameters.

grammar

The mongodump command script syntax is as follows:

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

    The server address where MongDB is located, for example: 127.0.0.1, of course, you can also specify the port number: 127.0.0.1:27017

  • -d:

    The database instance that needs to be backed up, for example: test

  • -O:

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

MongoDB data recovery

mongodb uses the mongorestore command to restore backed up data.

grammar

The mongorestore command script syntax is as follows:

>mongorestore -h <hostname><:port> -d dbname <path>


    • --host <:port>, -h <:port>:

        The address of the server where MongoDB is located, the default is: localhost:27017

    • --db , -d :

        The database instance that needs to be restored, for example: test, of course, this name can also be different from the backup, such as test2

    • --drop:

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

    • <path>:

        The last parameter of mongorestore sets the location of the backup data, for example: c:\data\dump\test.

        You cannot specify the <path> and --dir options at the same time, --dir can also set the backup directory.

    • --to you:

        Specify the backup directory

        You cannot specify the <path> and --dir options at the same time.


    Guess you like

    Origin http://43.154.161.224:23101/article/api/json?id=324973382&siteId=291194637