In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what is the method of backing up, restoring and migrating MongoDB database, which can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
Mongodump is a utility provided by mongodb for creating database backups. This is a very useful utility to consider backing up a real-time server database very effectively. For database restore, use the mongorestore command.
1. Back up the mongodb database (mongodump)
There are several ways to back up an MongoDB database. Use the mongodump command to perform all database backups, a single collection backup, or a single database backup.
Back up a single database
Use this command to back up only a single database (named mydb). A backup will be created in the / backup/db/ directory.
$mongodump-db mydb-out / backup / db /
-db-name of the database to be backed up
-out-Database backup location. This creates a folder with the database name.
You can specify the host, port, user name and password for the remote database connection backup, as shown below.
Mongodump-- host 10.0.1.7-- port 27017-- username admin-- password somepassword-- db mydb-- out / backup / db /
Back up all databases
To back up all databases, simply press the following command to run. Here / data / db / is the location of your mongodb data directory and / backup / db is the location of the backup directory.
$mongodump-out / backup / db /
You can specify a host and port for the remote database.
Back up a single collection
This command backs up a single collection from the database. The backup file will be created in the dump / mydb / directory.
$mongodump-collection mycollection-db mydb-out / backup / db /
2. Use mongorestore to restore MongoDB database
Mongorestore is a command-line tool for restoring mongodb database backups. Here / data / db / is the location of your mongodb data directory and / backup / db is the location of the backup directory.
$mongorestore-db mydb-drop / backup / db / mydb
-drop-if it already exists, the database will be deleted.
Simply move the backup file to a remote server and run the same command there to restore the backup.
3. MongoDB backup Shell script
You can easily schedule the following script in the scheduler to back up the database on a regular basis. Create the following files
$vi / backup/mongo-backup.sh
Add the following to the file. Update the database hostname, database name, user name and password accordingly.
#! / bin/sh TODAY= `date +% d% b% Y`BACKUP _ DIR=/backup/db mkdir-p ${BACKUP_DIR} / ${TODAY} mongodump-h-d-u-p-out ${BACKUP_DIR} / ${TODAY} /
Now configure it in crontab to run every day.
02 * / backup/mongo-backup.sh Thank you for reading this article carefully. I hope the editor will share the methods of backing up, restoring and migrating MongoDB database. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.