Mongodump 归档记录计数
我正在开发一个需要防弹的文档备份解决方案。我每周都会运行备份,并且能够在实际转储之前进行试运行,以确定要转储的文档数量。所以,我有一个目标数字。
问题是,当我实际运行 mongodump 时,它将所有输出写入控制台,而不是写入标准输出。因此,我无法捕获变量的输出,找到它转储的文档数量,并与我的目标数量进行比较。
我也查看过,但没有看到任何方法可以使用 mongorestore 来获取文件中的记录计数。
不, wc -l 不起作用。
所以,这就是我在 mongodump 期间看到写入控制台的内容:
2022-03-03T22:25:15.069+0000 writing mydb.records to archive '/opt/weekly/records_2022-02-13'
2022-03-03T22:25:17.529+0000 mydb.records 101
2022-03-03T22:25:22.510+0000 mydb.records 1675
2022-03-03T22:25:22.513+0000 done dumping mydb.records (1675 documents)
上面的内容将输出到控制台,我无法从我的脚本中捕获它(即 varname=$(mongodumpcommandhere) ),也无法重定向输出到 .log 文件,然后清理内容。
那么,任何 mongo 专家都知道我怎样才能做我想做的事吗?当然,我已经检查了 mongodump 命令的退出状态,只是想加倍努力并排列文档计数。
我可以安装一个空白数据库并加载转储并计算文档数量,但这似乎有点遥远,只是为了获取转储中的文档数量。寻找一些不那么暴力的东西。
哦,这是一个处理所有逻辑的 bash 脚本。
I'm working on a document backup solution that needs to be bulletproof. Im running my backup each week, and Im able to do a dryrun before the actual dump to determine how many documents I am going to dump. So, I have a target number.
Issue is, when I actually RUN the mongodump, it writes all output to the CONSOLE, not to stdout. So I cant capture the output to a variable, find the number of documents it dumped, and compare to my target number.
Ive also looked and dont see any way to use mongorestore to get a record count in the file after the fact.
And no, wc -l doesnt work.
So, this is what I see written to console during the mongodump:
2022-03-03T22:25:15.069+0000 writing mydb.records to archive '/opt/weekly/records_2022-02-13'
2022-03-03T22:25:17.529+0000 mydb.records 101
2022-03-03T22:25:22.510+0000 mydb.records 1675
2022-03-03T22:25:22.513+0000 done dumping mydb.records (1675 documents)
The above is going to console, and Im not able to capture it from within my script (i.e. varname=$(mongodumpcommandhere) ), nor am I able to redirect the output to a .log file and then scrub the contents.
So, any mongo experts out there know how I can do what I want? Sure, Im already checking the exit status of the mongodump command, just trying to go the extra mile and line up the document count as well.
I could install a blank DB and load the dump and count the documents, but that seems like a little far to go just to get the number of documents in a dump. Looking for something a little less brute force.
Oh, and this is a bash script handling all of the logic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mongodumpcommandhere
可能正在写入标准错误而不是标准输出。如果是这样的话就可以了。如果它不起作用,则可能意味着该命令正在直接写入终端。这是一件坏事,但有一些方法可以克服它。
mongodumpcommandhere
may be writing to standard error instead of standard output. If that is the casewill work. If it doesn't work it probably means that the command is writing directly to the terminal. That's a bad thing to do, but there are ways to capture it.