How does a file get “corrupted” and how can I prevent it?

733 views

How does a file get “corrupted” and how can I prevent it?

In: Technology

5 Answers

Anonymous 0 Comments

A file can be corrupted in any number of ways. The simplest way is that the contents of the file is wrong. Maybe the file got truncated, so it’s shorter than it should be. Maybe the values in the file are wrong, thus rendering the contents nonsense to the program that uses that file.

Worse, the filesystem can be corrupted. Your drive is just a device with a means of setting and reading bits. A filesystem is software and data that manages your files, tracking file name, location, size, timestamps, etc. THAT can get corrupted, rendering the file effectively unrecoverable; even if the file contents are still on the drive and just fine, it doesn’t matter if the filesystem loses track of the pieces.

Corruption can happen by the program that uses the file, if the program has a bug. Corruption can happen by other programs doing something wrong, or perhaps a program misguided by a naive user. Corruption can happen due to hardware failures. Corruption can happen due to interference, RF noise, solar flares, etc.

How can you prevent it? You can’t. You can reduce the chances of corruption. You can possibly even recover from some kinds of corruption with the right preparation. Prevention is going to be your first defense. Backup your data. Properly. You can always buy a new computer, new software. You can’t buy back your only unique copy of un-reproducible, irreplaceable data.

The second thing you can do is use technologies that help reduce instances of corruption. EEC memory is one example (though iCore and I believe Ryzen both don’t use the EEC features even though some motherboards can use the memory). RAID-6 is another example. This doesn’t just write bits to your drive, it encodes it, so that if there is corruption due to hardware or solar flares, they can be detected and possibly even recovered. RAID-6 uses multiple drives, can can even withstand 2 drive failures at the same time. (RAID does not constitute a backup solution. No, not even RAID-1.) If you’re really curious about this, I’ll just name drop Ubuntu and BRTFS.

The third thing you can do is – don’t do anything stupid. If you’re going to run `rm -rf *`, make sure you’re not in the root directory. Test what you’re going to do, if it’s irreversible, before you do it. Read your manuals. Know what you’re doing.

You are viewing 1 out of 5 answers, click here to view all answers.