记一次删库

当它真的发生了,你才知道你写的运维脚本都是狗屎。

PRE:
我的服务器上运行着一个nodebb论坛(node + nongodb)。

我使用了一个脚本备份数据库:

/usr/bin/mongodump -u user -p pwd --authenticationDatabase=forum -d forum
tar -zcvf dump/${backup_date}.tar.gz dump/forum --remove-files
find dump/ -mtime +3 | xargs rm -f
echo $(date +"%F %H:%M:%S") Backup successfully ! >> log.backup

它的基本功能是:每天备份一次数据库,打包。备份文件保留三天,超出三天的自动删除。

我的服务器已经将近两年没重启了,各种东西都乱七八糟,于是我一时没管住自己,reboot。

重启以后我才意识到,忘记手动备份mongo的数据了,但其实也没啥,反正我这论坛也没什么人,导入昨天的备份就好了。

但是当我打开备份目录的时候,傻了,因为这里面只有20年6月的三个备份,于是赶紧打开cron的log,发现这一年以来cron一直在划水,根本没执行过我的脚本(WTFFF?)

我心想,反正论坛也没什么人,丢一年数据也无所谓,所以我就尝试导入数据。而导入数据过程中由于一些typo没能成功,我怀疑是不是这几个备份出了问题。于是我翻出一个2019年2月的上古备份,回滚了一下数据库,成功了。

我发现之前回滚失败,不是备份文件的问题,而是我命令没给对,于是我又回去试图回滚到20年6月,然而当我打开dump文件夹的时候,又傻了。

划水了一年的cron,就在刚才,突然tm启动,把20年的3个备份文件删了(毕竟已经一年了)。所以我手里就只剩下了19年初的备份,回到了解放前。

fml

Apr 6, 2021


[+] click to leave a comment [+]
the comment system on this blog works via email. The button
below will generate a mailto: link based on this page's url 
and invoke your email client - please edit the comment there!

[optional] even better, encrypt the email with my public key

- don't modify the subject field
- specify a nickname, otherwise your comment will be shown as   
  anonymous
- your email address will not be disclosed
- you agree that the comment is to be made public.
- to take down a comment, send the request via email.

>> SEND COMMENT <<




Voice? via Blog on luis.zip January 12, 2024

Who is the voice inside my head? I have a voice in my mind. I’m hearing it now. It dictates what I write. Sometimes when I think about something, it speaks to me as if it were not me, as if it were not a product of the imagination that belongs to my domain…

2023 in Books via Wesley's Notebook January 7, 2024

recently ~ august23 via Sindre Kjelsrud September 5, 2023

what i've been doing during the month of august.

Generated by openring from webring