记一次删库

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

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 <<




Fun with Image Maps and SVGs via benji February 20, 2024

Over the past few weeks I've been playing around with making some images on my website interactive. My "informatics" class in high school taught us some basic HTML. By basic I mean in notepad and writing everything by hand, saving to a...

Goblin Week 2024 via Helvetica Blanc January 26, 2024

It snuck up on me, but I managed to draw my little goblins to celebrate the week! I love my children - they're like awful Pikmin. I've uploaded the whole parade as a print, as well as individual prints for each goblin. There's something very fu…

How to trust gpg keys via Travis Shears Personal Site October 27, 2023

After moving some GPG keys to a new computer I kept getting these trust warnings. It is NOT certain that the key belongs to the person named in the user ID.If you * really * know what you are doing, you may answer the next question with yes. Use this key a…

Generated by openring from webring