Get the App
SLTechnology News&Howtos  ›  Database  › 

Recovery methods after erroneous deletion of Mongodb Database (two kinds)

Shulou Source: shulou.com Published: 2022-06-01 02:32:09 10月03日 Update

Method 1: restore through oplog

If you are deploying a MongoDB replication set, there is a glimmer of hope that you can recover the data as much as possible through oplog; every modification of the MongoDB replication set records an oplog, so when the database is mistakenly deleted, you can replay the existing oplog to "recover the data as much as possible". A user I met not long ago was very lucky. The database was created recently, and all the operations are still in oplog, so the user retrieved all the data deleted by mistake through oplog.

The process of recovering data through oplog is very simple, as long as the oplog collection is exported through mongodump and replayed through mongorestore's oplogReplay mode.

Step1: exporting oplog collections

Mongodump-d local-c oplog.rs-d-o backupdir

Step2: copy data from the oplog collection

Mkdir new_backupdircp backupdir/local/oplog.rs.bson new_backupdir/oplog.bson

Step3: playback oplog

Mongorestore-oplogReplay new_backupdir

Method 2: restore through backup set

If you do a full backup + incremental backup of the MongoDB, you can restore the data through the backup set and. Backups can take many forms, such as:

Through mongodump and other tools, copy the logical backup produced by the database, copy the physical backup file system generated by the dbpath directory, the snapshot generated by volume management, etc.

In fact, we can also see a problem here, that is, "Why do you still need to do data backup when you deploy a replication set with multiple nodes?" When you encounter the problem of mistakenly deleting the database, the dropDatabase command will also be synchronized to all standby nodes, causing the data of all nodes to be deleted.

Summary

The above is the recovery method after the Mongodb database is mistakenly deleted. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply you in time. Thank you very much for your support to the website!

Tags: Data backup database method can be passed through node as far as possible copy user problem front line command increment variety namely tool form snapshot data backup file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi vpn Huawei Shulou Technology