Sunday, 25 November 2012

Back Up Important Files With This Simple Batch File

Back Up Important Files With This Simple Batch File


A client once complained to me that the keyboard shortcut for displaying the Windows Desktop I had shown him, pressing the Windows key and the letter D, wasn’t working. When I asked him to demonstrate the problem, I noticed he
was actually hitting [Ctrl]D, the delete shortcut, instead. To make matters worse, he had done this several times from within Windows Explorer and from a local folder that contained several documents. Because the Display Delete Confirmation Dialog option had been deselected on his machine, he had no idea he was deleting files. Luckily the Recycle Bin was there to save him. But sometimes we're not so fortunate.

Situations like this really drive home the need to keep current backups. While many organizations back up the data stored on their network servers, the safety of desktop information is often left to the end user. It's been my experience that even the most cautious end user deletes an important file every now and then.

To help users safeguard their data, you should encourage them to store important files on the network and not their local machines. But in some cases, this isn't always possible (i.e., traveling laptop users). To provide backups for such users, I recommend copying documents from one location on the hard drive to another. To keep this process simple, I've developed a batch file to do the job. Combine this file with Windows' Scheduled Task feature, and you have an easy method for duplicating files automatically.

Create a mirror with this batch file
For this process, you'll set up a backup or mirror folder in a location other than the one usually used for storage. Then, you'll use the batch file to copy the documents to that new folder. You'll also use Windows' Scheduled Tasks feature to run the batch file each day.
1. First, you must determine which folder will be backed up. To keep things simple, in the following example I'll assume the main document folder is C:\My Documents (on Windows NT, 2000, and XP machines, you'll want to use the appropriate profile folder). You'll also need to copy Outlook's personal storage file—it's usually called Outlook.pst.
2. Create the mirror folder. (In this example, it's called D:\mirror.)
3. Use this sample code to build the batch file. Once you've done so, you'll need to copy it to an out-of-the-way location on the user's hard drive.

Xcopy has evolved
As you can see in the sample code, Xcopy32 introduces many useful switches that didn’t exist in its DOS predecessor. These are the most important ones:
· /d—This switch copies all source files that are newer than existing destination files. It allows you to update only files that have changed, making the process a lot faster.
· /c—This command-line option ignores errors. You don’t want one corrupted file to halt the automated copying.
· /s—This option copies directories and subdirectories.
· /r—This switch copies read-only files.
· /y—Use this switch to overwrite files without prompting. You don't want any user intervention to be required.
· /i—Use this option to automatically create new folders on destination.

The > d:\mirror\xcopy.log suffix creates a log file with all of XCopy’s messages, for later reference and troubleshooting. Using >> appends a file to an existing log rather than creating a new one.

Size matters
You'll want to customize this batch file to mirror information that's important to the user, including faxes, Outlook Express e-mail folders, and Office documents. Make sure, however, that it all fits in the destination drive. Even users who frequently clean their files can pile up redundant information. Consider using DOS wildcards to fine-tune this process to each user's needs.

Run your backup batch file automatically
To make sure your users' files are actually backed up, use Windows' Scheduled Tasks to schedule the batch file to run each day at a convenient hour. In Windows 98, Scheduled Tasks resides in the System Tray. Windows 2000 and XP hide this feature in the Control Panel.

Once you've opened the Scheduled Tasks window, double-click Add Scheduled Task to invoke the wizard. Click Next to move past the introductory screen. You'll then be asked to select the program you want to schedule. You'll need to browse for your newly created batch file, because Windows defaults to scheduling registered applications.
Figure A



Once you've chosen your batch file, select a frequency for the file to run, see Figure A.
Figure B



Next, you'll be prompted to select a time for the task to run, see Figure B.
Figure C



If prompted, make sure to provide a user name and password, see Figure C.
Figure D



Finally you'll be shown a summary of your newly scheduled task, as shown in Figure D. Click Finish and your backup batch file will be ready to go.

0 comments:

Post a Comment