My Blog

My WordPress Blog

Matt Davies Stockton Provides Details About How Python Code Can Save Your Corrupted Hard Drive

Corrupted Hard Drive

374 Views

Introduction

According to Matt Davies Stockton, most people have moved on to the cloud or some other type of backup solution. However, there are still niche cases, where you can’t move the data from the local machine. That’s why it’s frustrating when the hard drive on that device gets corrupted. Let’s check out how you can save the data from that hard drive with Python.

The Details

1. You run out of conventional options

The market is full of conventional options that help with data recovery. Popular apps like Disk Drill and Mini Tool Power Data Recovery are professional data recovery solutions that can help you recover your data in most cases. However, you may run into some niche problems that require some other kind of solution.

For instance, if your disk is full of random unreadable sectors, it may interrupt the automatic backup attempted by disk recovery tools by randomly un mounting whenever the tool uses more resources than usual. In these cases, the only solution is to copy individual files and filter them out by scanning them for IO errors. However, doing that manually for 500 GB of data is going to make you age very quickly. Fortunately, this process can be automated with Python.

2. Replicate the directory tree on i Cloud

Start by choosing a subset of folders to backup. For every folder you found in that group, you make a sibling in the i Cloud directory. While you do this, you’ll need to keep a list of each file with their entire paths saved as well. You can use the “shutil.copytree()” method, or “os.walk()” to make things easier for you.

With a corrupted drive, the python script is going to take a while to scan everything and make a file list along with a directory tree. However, it’s better than the drive being randomly unmounted and interrupting the entire backup process.

3. Copy each file to the sibling location in i Cloud

When you’ve made a directory tree and a list of all individual files with their full paths, you have the perfect ingredients to create a backup while filtering out the corrupted data. Start by loading the file list and use flags arrays to track recovery progress. This is very useful when you don’t know the errors you’re trying to look for.

Now you need to try/except every file while updating the flag array with successes and caught exceptions. You need to account for large files that may take too long to copy and slow down the entire process. That’s where a Time Out Exception() comes in.

Finally, for the actual backup loop, you may not know the exceptions you’re looking for. Apart from looking for the typical IO Error, File Not Found Error would help you keep the process going when a particular file is not found, or the disk randomly un mounts and remounts.

Conclusion

Matt Davies Stockton suggests that you use Python when you run out of conventional options for data recovery. Python allows for automation that may allow you to tackle your niche problem and help you recover as much data from the corrupted drive as possible.

Leave a Reply

Your email address will not be published. Required fields are marked *