Book Home Perl for System AdministrationSearch this book

Chapter 2. Filesystems


Perl to the Rescue
Filesystem Differences
Walking or Traversing the Filesystem
Walking the Filesystem Using the File::Find Module
Manipulating Disk Quotas
Querying Filesystem Usage
Module Information for This Chapter
References for More Information

2.1. Perl to the Rescue

Laptops fall in slow motion. Or at least that's the way it looked when the laptop I was using to write this book fell off a table onto a hardwood floor. The machine was still in one piece and running when I picked it up. As I checked the laptop to see if anything was damaged, I noticed it started to run slower and slower. Not only that, but the laptop began to make sporadic and disturbing humming-buzzing sounds during disk access. Figuring the software slowdown was caused by a software problem, I shut the laptop down. It did not go gently into the night, refusing to shut down cleanly. This was a bad sign.

Even worse was its reluctance to boot again. It would begin the Windows NT booting process and then fail with a "file not found" error. By now it was clear that the fall had caused some serious physical damage to the hard drive. The heads had probably skidded over the hard drive platter surface, destroying files and directory entries in their wake. Now the question was, "Did any of my files survive? Did the files for this book survive?"

I first tried booting to Linux, the other operating system installed on the laptop. Linux booted fine, an encouraging sign. The files for this book, however, resided on the Windows NT NTFS partition that did not boot. Using Martin von Löwis's Linux NTFS driver, available at (now shipping with the Linux 2.2 kernels), I mounted the partition and was greeted with what looked like all of my files intact.

My attempts to copy these files off that partition would proceed fine for a while until I reached a certain file. At that point the drive would make those ominous sounds again and the backup would fail. It was clear that if I wanted to rescue my data I was going to have to skip all the damaged files on the disk. The program I was using ( gnutar) had the ability to skip a list of files, but here was the problem: which files? There were over sixteen thousand files on this filesystem at time of impact. How was I going to figure out which files were damaged and which were fine? Clearly running gnutar again and again was not a reasonable strategy. This was a job for Perl!

I'll show you the code I used to solve this problem a little later on in this chapter. For that code to make sense, we'll first need to place it into context by looking at filesystems in general and how we operate on them using Perl.

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.