MongoDB Migration - Backup and Restore

Recently did a migration of my crawler database, so here record MongoDB backup and restore

MongoDB Data Backup

mongodump -h dbhost -d dbname -o dbdirectory
  • -h: MongoDB server address, e.g.: 127.0.0.1, if not changed generally is: 127.0.0.1:27017

  • -d: Database name to backup, e.g.: test

  • -o: Backup data storage location, e.g.: /home/root/xxx,

MongoDB Data Restore

mongorestore -h <hostname><:port> -d dbname <path>
  • –host <:port>, -h <:port>: MongoDB server address, default: localhost:27017

  • –db , -d : Database name to backup, e.g.: test

  • –drop: Delete existing data first, then restore data

  • : Specify backup file directory

  • –dir: Specify backup file directory, cannot specifyand –dir options simultaneously.

Article Link:

https://alili.tech/en/archive/7815p445rtf/

# Latest Articles