Sometimes writing a script entails more than writing and testing code that performs a certain task. When a script is to perform a major IT undertaking such as data migration, you need to write a script that not only performs the task but also minimizes associated risks and downtime.
For example, my company had a file server with a shared 250GB RAID 5 array that was quickly filling up with users' files, despite ongoing efforts to remove old and obsolete files. To meet the increasing memory needs, the company purchased new disks. The IT server team installed the new disks and configured them into a 500GB RAID 5 array, which the team connected to the same file server.
I had to write a script that migrated the six top-level folders while retaining the complicated NTFS file and folder permissions. I worked with the server team that maintains the server to determine the script's requirements. We determined that the script needed to
- Copy the entire file and folder structure from the old array to the new array while maintaining NTFS permissions
- Create a detailed log of the migration results for each top-level folder
- Verify the results of the copy operation
- Determine how long the system would need to be offline for the data migration so that we could develop a strategy to minimize downtime for users
- Permit graceful fallback if hardware failed or other unforeseen circumstances arose
RobocopyDataMigration.bat is the script I created. You can find RobocopyDataMigration.bat in the Code Library on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com). This month and next, I'll describe how the script works and how you can adapt it for your environment.
Copying the Data
To copy the file and folder structure, RobocopyDataMigration.bat uses Robocopy 1.96. You can find Robocopy 1.96 in the Microsoft Windows 2000 Resource Kit or the Microsoft Windows NT Server 4.0 Resource Kit, Supplement 4. The pathname for the resource kit's folder depends on which version you install. RobocopyDataMigration.bat uses the default NT pathname of C:\ntreskit. The default pathname for the Win2K resource kit is C:\program files\resource kit. If you install the Win2K resource kit, though, I recommend you install it in a folder with no spaces in the name, similar to the NT default location. Using a name with spaces in a batch command can create problems when the command executes. In the past, many administrators used the workaround of enclosing such commands in double quotes. In Win2K, this workaround produces inconsistent results. Furthermore, nesting a command enclosed in double quotes within a For command can produce inconsistent results in both Win2K and NT.
Robocopy is a powerful and useful utility because of its many options, or switches. To customize RobocopyDataMigration.bat to your environment, you need to learn about these switches. To obtain a short description of them, you can run the command
Robocopy /???
at the command line to view the online Help file. (The Help switch depends on the Robocopy version. Robocopy 1.96 uses the /??? switch, but earlier versions might use a different switch.) The 22-page document robocopy.doc explains each switch in detail. (Although robocopy.doc might show 1.95 as the version number, the installed version is actually 1.96.)