sábado, 6 de agosto de 2011

Unix and the Hole Hawg

In his article "The Hole Hawg of Operating systems", Neal Stephenson compares Unix to an industrial-strength drill, which is "too powerful and too expensive for the homeowner", that is "like the genie of the ancient fairy tales, who carries out his master's instructions literally and precisely and with unlimited power, often with disastrous, unforeseen consequences".

Our reader Paul F. commanded the "Unix genie" to look for log files older than 90 days and erase them. Just a simple "find" command:


find / -name *log* -atime 90 -exec rm -rf {} \;


This command looks for files or directories that would contain "log" in their names, that haven't been accessed in 90 days, and applies the command "rm -rf" on each of them. Files will be erased, and directories will have each of its files erased recursively before being removed themselves.

Our reader issued this command as part of his routine in the night shift, so he did this and went to sleep, without knowing the consequences. When the day shift came to the office and started work, all hell broke loose.

It turns out that the server where the command was executed, was a database server, which happens to have very important files that have "log" in their names: the redo logs. And the command, which started its search for something-log files in the root directory, found those files and utterly destroyed them. The database server uses these files to log its actions before updating the data files and recover from possible errors. When these files don't exist, the database can't operate at all. And if the database can't operate, the users can't operate.

And when the users arrived in the morning and tried to use their precious database, they got errors instead of their data. So they called their boss. Their boss called his boss, and that boss called the vice president of operations, who demanded the head of whoever was responsible for paralyzing the company.

Actually, Paul F. didn't paralyze the company -only a few users were involved- and the vice president of operations was told that the database server involved was not a critical server, was only a backup server and the actual data was safe elsewhere. So the head of Paul F. was spared after all. And it started a good discussion about disaster recovery should this ever happen in a real server.

Morale of the story: never, EVER do finds with the rm command starting in the root directory, for it will have unforeseen consequences.

No hay comentarios:

Publicar un comentario