我们意外地删除了目录rm -rf /data/db
,它是我们的MongoDB路径,由于extundelete,我们恢复了它并得到了目录/data/db
。
下面是目录中的文件,这些文件是在MongoDB version 3.4下生成的。
文件夹diagnostic.data
:
文件夹journal
:
方式运行单神
a)我们运行了mongod --port 27017 --dbpath /data/db --bind_ip_all
和mongo
,并且期望有一个用户定义的数据库wecaXX
,But,它没有出现。
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
在Robo3T中
( b)然后我尝试运行mongod --port 27017 --dbpath /data/db --bind_ip_all --repair
。结果是:
2019-03-25T14:10:02.170+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] MongoDB starting : pid=23018 port=27017 dbpath=/data/db 64-bit host=iZj6c0pipuxk17pb7pbaw0Z
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] db version v4.0.7
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] git version: 1b82c812a9c0bbf6dc79d5400de9ea99e6ffa025
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] allocator: tcmalloc
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] modules: none
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] build environment:
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] distmod: ubuntu1604
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] distarch: x86_64
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] target_arch: x86_64
2019-03-25T14:10:02.191+0800 I CONTROL [initandlisten] options: { net: { bindIpAll: true, port: 27017 }, repair: true, storage: { dbPath: "/data/db" } }
2019-03-25T14:10:02.191+0800 W STORAGE [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2019-03-25T14:10:02.194+0800 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-03-25T14:10:02.194+0800 W STORAGE [initandlisten] Recovering data from the last clean checkpoint.
2019-03-25T14:10:02.194+0800 I STORAGE [initandlisten]
2019-03-25T14:10:02.194+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-03-25T14:10:02.194+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-03-25T14:10:02.194+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=256M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-03-25T14:10:02.818+0800 E STORAGE [initandlisten] WiredTiger error (17) [1553494202:818725][23018:0x7f6119074a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1553494202:818725][23018:0x7f6119074a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-03-25T14:10:02.818+0800 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.1
2019-03-25T14:10:03.832+0800 I STORAGE [initandlisten] WiredTiger message [1553494203:832267][23018:0x7f6119074a40], txn-recover: Main recovery loop: starting at 4/11366912 to 5/256
2019-03-25T14:10:03.832+0800 I STORAGE [initandlisten] WiredTiger message [1553494203:832674][23018:0x7f6119074a40], txn-recover: Recovering log 4 through 5
2019-03-25T14:10:03.898+0800 I STORAGE [initandlisten] WiredTiger message [1553494203:898252][23018:0x7f6119074a40], txn-recover: Recovering log 5 through 5
2019-03-25T14:10:03.964+0800 I STORAGE [initandlisten] WiredTiger message [1553494203:964880][23018:0x7f6119074a40], txn-recover: Set global recovery timestamp: 0
2019-03-25T14:10:03.998+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-03-25T14:10:03.999+0800 E STORAGE [initandlisten] WiredTiger error (17) [1553494203:999855][23018:0x7f6119074a40], WT_SESSION.create: __posix_open_file, 715: /data/db/_mdb_catalog.wt: handle-open: open: File exists Raw: [1553494203:999855][23018:0x7f6119074a40], WT_SESSION.create: __posix_open_file, 715: /data/db/_mdb_catalog.wt: handle-open: open: File exists
2019-03-25T14:10:04.000+0800 I STORAGE [initandlisten] WiredTiger message unexpected file _mdb_catalog.wt found, renamed to _mdb_catalog.wt.1
2019-03-25T14:10:04.015+0800 I CONTROL [initandlisten]
2019-03-25T14:10:04.015+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-03-25T14:10:04.015+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-03-25T14:10:04.015+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-03-25T14:10:04.015+0800 I CONTROL [initandlisten]
2019-03-25T14:10:04.015+0800 I CONTROL [initandlisten]
2019-03-25T14:10:04.015+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 3824 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
2019-03-25T14:10:04.020+0800 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: 47d8713d-ac61-4081-83bf-60209ad60a7d
2019-03-25T14:10:04.034+0800 W ASIO [initandlisten] No TransportLayer configured during NetworkInterface startup
2019-03-25T14:10:04.036+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 4.0
2019-03-25T14:10:04.036+0800 I STORAGE [initandlisten] repairDatabase admin
2019-03-25T14:10:04.037+0800 I STORAGE [initandlisten] Repairing collection admin.system.version
2019-03-25T14:10:04.040+0800 I STORAGE [initandlisten] Verify succeeded on uri table:collection-0-4352287918877967674. Not salvaging.
2019-03-25T14:10:04.048+0800 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { _id: 1 }, name: "_id_", ns: "admin.system.version" }
2019-03-25T14:10:04.048+0800 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2019-03-25T14:10:04.055+0800 I STORAGE [initandlisten] finished checking dbs
2019-03-25T14:10:04.055+0800 I STORAGE [initandlisten] WiredTigerKVEngine shutting down
2019-03-25T14:10:04.056+0800 I STORAGE [initandlisten] Shutting down session sweeper thread
2019-03-25T14:10:04.057+0800 I STORAGE [initandlisten] Finished shutting down session sweeper thread
2019-03-25T14:10:04.140+0800 I STORAGE [initandlisten] shutdown: removing fs lock...
2019-03-25T14:10:04.140+0800 I CONTROL [initandlisten] now exiting
2019-03-25T14:10:04.140+0800 I CONTROL [initandlisten] shutting down with code:0
c)修复后,我重新运行mongod --port 27017 --dbpath /data/db --bind_ip_all
,它仍然显示nothing (结果与步骤a相同)。
因为这不像我所期望的那样有效,所以我开始寻找其他可能帮助我的工具或方法。下面是链接从损坏的WiredTiger安装中恢复MongoDB集合,它介绍了如何使用WiredTiger恢复集合。我决定试一试。
我创建了一个文件夹db_backup
并将所有文件放入其中。我在db_backup
.I下创建了一个文件夹wiredtiger-3.0.0
,在文件夹D24
中安装了wiredtiger
:
( a)来挽救集合
root@iZj6c0pipuxk17pb7pbaw0Z:/data/db_backup/# cd ./wiredtiger-3.0.0
root@iZj6c0pipuxk17pb7pbaw0Z:/data/db_backup/wiredtiger-3.0.0# ./wt -v -h ../db_for_wt -C "extensions=[./ext/compressors/snappy/.libs/libwiredtiger_snappy.so]" -R salvage collection-23--360946650994865928.wt
WT_SESSION.salvage 100
基于上面的文章,这意味着我们已经成功地挽救了这个收藏品。
发生
( b)转储集合
root@iZj6c0pipuxk17pb7pbaw0Z:/data/db_backup/wiredtiger-3.0.0# ./wt -v -h ../../db_backup -C "extensions=[./ext/compressors/snappy/.libs/libwiredtiger_snappy.so]" -R dump -f ../collection.dump collection-23--360946650994865928
lt-wt: cursor open(table:collection-23--360946650994865928) failed: No such file or directory
注意,上面的命令实际上是在没有.wt
的情况下结束的。
我检查了我的目录参数,没有发现错误。在图片中,文件collection-23--360946650994865928.wt
is就在这里。
刚刚恢复了collection-23--360946650994865928.wt
的快照。
我们可以在里面看到一些英文或中文字符。而这些数据确实来自于数据库wecaXX
的一个集合。
( 1)现在,我不得不放弃收藏。有人知道这是怎么回事吗?
2) collection-23--360946650994865928.wt
包含我们最重要的数据。如果我们不能恢复整个数据库,从该文件中提取数据仍然是非常有用的。但是,如果我们手动复制粘贴,并不是所有的字符都写得很好,它们仍然需要解密。有人知道怎么做吗?
3)是否可能没有恢复/data/db
下的所有文件(或所有文件的整个正文)?
Any评论或答复将不胜感激!!
发布于 2019-03-25 11:22:33
根据Robo3T的屏幕截图,其中只显示系统数据库(即admin
& local
)。连接的主机上没有任何用户定义的数据库可用。
尽管您在mongodb版本下生成的文件是3.4 & MongoDB db版本的起始值为v4.0.7。
我会在某个地方猜测您已经松了您的用户创建的数据库。
假设如果用户数据库将出现在那里,那么在与Robo3T-1.2工具进行主机连接之后,用户数据库就会自动出现。
例如,当Robo3T-1.1的屏幕快照出现在我的环境中时。
为了进行验证,您也可以使用mongo进行检查,在连接mongo之后,可以检查命令,如show dbs;
它会像那样
> show dbs
DynamicsAX 0.006GB
ERP 0.086GB
admin 0.000GB
blog 0.000GB
config 0.000GB
enron 0.207GB
local 0.000GB
mflix 0.060GB
test 0.001GB
注意:-现在,在进行任何火箭科学之前,您必须先获取数据目录的mongodump。
正如您提到的这里屏幕截图一样,数据库恢复是用户定义的数据库。
根据您的错误单根错误日志
root@iZj6c0pipuxk17pb7pbaw0Z:/data/db_backup/wiredtiger-3.0.0# ./wt -v -h ../../db_backup -C "extensions=[./ext/compressors/snappy/.libs/libwiredtiger_snappy.so]" -R dump -f ../collection.dump collection-23--360946650994865928
lt-wt: cursor open(table:collection-23--360946650994865928) failed: No such file or directory
它不可能成功。
注意:如果您使用的是MongoDB < 3.2的版本,因为3.2是在WiredTiger 2.7的基础上构建的,那么mongodump就会失败。
After编辑OP问题
现在,我在扔掉收藏品的时候被困住了。我有什么问题吗?
是的,因为mongodump
没有成功。
在收集--23--360946650994865928.wt,我们真的有完整的数据吗?即使无法恢复数据库,也可以从这些*.wt文件中提取数据吗?
由于这里已经更新了community wiki
,所以*.wt
是WiredTiger存储引擎使用的二进制数据文件。单个文件不能作为独立备份使用。如果要获取MongoDB dbPath的文件副本备份,则需要使用支持的文件复制备份方法。包含所有文件。
https://dba.stackexchange.com/questions/233005
复制相似问题