bash脚本意外删除了数据库,请进行救援 [英] Deleted database accidentally by a bash script, rescue please
问题描述
我的开发人员犯了一个严重的错误,我们在服务器中找不到任何人的mongo数据库。
My developer committed a huge mistake and we cannot find our mongo database anyone in the server. Rescue please!!!
他已登录服务器,并将以下shell保存在〜/ crontab / mongod_back.sh $ c $下c>:
He logged into the server, and saved the following shell under ~/crontab/mongod_back.sh
:
然后他运行 ./ mongod_back.sh
,然后有很多权限被拒绝
,然后他做了 Ctrl + C
。然后服务器自动关闭。
And then he run ./mongod_back.sh
, then there were lots of permission denied
, then he did Ctrl+C
. Then the server shut down automatically.
他尝试重新启动服务器,然后出现grub错误:
He tried to restart the server, then he got an grub error:
然后他与AliCloud联系,工程师将磁盘连接到另一台工作服务器,以便他可以检查磁盘。然后,他意识到一些文件夹已经消失了,其中包括 / data /
mongodb所在的位置!!!
He then contacted AliCloud, the engineer connected the disk to another working server, so that he could check the disk. Then, he realized that some folders have gone, including /data/
where the mongodb is!!!
1)我们只是不了解bash如何破坏磁盘,包括 / data /
;
1) We just don't understand how the bash could destroy the disk including /data/
;
2)当然,是否可以取回 / data /
?
2) And of course, is it possible to get the /data/
back?
PS :他之前没有对磁盘进行快照。
PS: he did not take a snapshot of the disk before.
推荐答案
问题1
Question 1
1 )我们只是不了解bash如何破坏包括/ data /;的磁盘;
1) We just don't understand how the bash could destroy the disk including /data/;
原因: $ OUT_DIR
未设置
在 bash
和 sh
注释写为#注释
,而不是 //注释
。
以下行将具有以下效果
Reason: $OUT_DIR
was unset
In bash
and sh
comments are written as # comment
, not // comment
.
The following line will have the following effects
someVariable=someValue // not a comment
- 将
someValue
分配给变量someVariable
,但仅适用于那一行。在该行之后变量将返回其旧值,在这种情况下为空。 - 执行命令
/ /不是注释
,即程序//
,其参数为not
,a
和评论
。由于//
只是一个目录(与/
相同),这将导致错误消息,仅此而已。 / li>
- Assign
someValue
to variablesomeVariable
, but only for that one line. After that line the variable will go back to its old value, which is null in this case. - Execute the "command"
// not a comment
, that is the program//
with the parametersnot
,a
, andcomment
. Since//
is just a directory (the same as/
) this will cause an error message and nothing more.
现在,这种行为可能看起来很奇怪,但是您可能已经在诸如
IFS =读取-r行
或LC_ALL = C sort
。Right now this behavior might seem strange, but you may have already used it in well known idioms like
IFS= read -r line
orLC_ALL=C sort
.查看脚本以下几行可能会导致问题:
Looking at your script the following lines probably caused the problem:
OUT_DIR=/data/backup/mongodb/tmp // ... ... rm -rf $OUT_DIR/*
很抱歉带这个对您来说,但是您基本上执行了
rm -rf / *
,因为$ OUT_DIR
扩展为空字符串。I'm sorry to bring this to you, but you basically executed
rm -rf /*
since$OUT_DIR
expanded to the empty string.即使没有
$ OUT_DIR
不要清空效果可能相同,因为在rm $之后有一个
//
评论 c $ c>。考虑命令Even if
$OUT_DIR
wasn't empty the effect could have been the same since there is a//
"comment" afterrm
. Consider the commandrm -rf some // thing
这应该删除三个文件/目录
some
,//
和事物
。如前所述,//
与/
是同一目录。This is supposed to delete the three files/directories
some
,//
, andthing
. As already pointed out//
is the same directory as/
.但是,在Linux上
rm
的大多数实现对此有防范措施,不会删除/
很容易。在Ubuntu上,您会收到以下警告(不要在家中尝试。如果您的rm
不同,会很烂。)However, most implementations of
rm
on Linux have a guard for this case and won't delete/
so easily. On Ubuntu you will get the following warning (don't try this at home. Would suck if yourrm
differs.)$ rm -rf // rm: it is dangerous to operate recursively on '//' (same as '/') rm: use --no-preserve-root to override this failsafe
问题2
Question 2
2)当然,是否有可能取回/ data /?
2) And of cause, is it possible to get the /data/ back?
对于StackOverflow,这是没有主题的。但是,您可以找到很多 答案 到 此 问题 上 其他 stackexchange 站点。
This is off-topic for StackOverflow. However, you can find many answers to this question on other stackexchange sites.
您可以尝试使用恢复工具,但是不能保证您可以恢复数据。没有备份。
There are recovery tools you can try, but there is no guarantee that you can restore your data if you don't have a backup.
这篇关于bash脚本意外删除了数据库,请进行救援的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Assign