Sachin Sharma
Thank you for visiting http://sachinssharma.blogspot.com/ X a c h i n
 

What's News?


Only a Sith deals in absolutes. I will do what I must.
- Obi Wan Kanobi
- StarWars III - Revenge of the Sith

 

Using Task Scheduler and JavaScript for Backup

Maintaining critical data in the digital world is a huge responsibility. More than a hard-drive crash or other problems with the hardware, a simple human error makes data more prone to loss. Once gone, especially from a file server, you can then sit and wish if you had just taken a backup. A huge organization may have expensive data backup solutions but in a SOHO environment, there is an easy and reliable method to backup data.

All you need is an extra hard-drive proportional to the amount of backup you need. After installing the hard-drive, either on the file server or on another location within the network, it is time to take one complete backup. Copy the drives to individual folders in the backup hard-drive. Once you take the first backup, you can setup a schedule and instruct your computer to take a sort-of differential backup everyday during after-hours. Just set this up and enjoy up-to-date backup without any worries.

Here is the process:

The process uses DOS’ “Xcopy” command from a script for the actual backup. First, copy and paste the following Windows Script to a new file named “Backup.wsf”

<job id="main">
<script language="JScript">
function AddQuotes (sText)
{
return "\"" + sText + "\"";
}

function XcopyFromTo (sSrc, sDest, sModified)
{
// Construct the copy string
var sCmd = "xcopy " + AddQuotes (sSrc) + " " +
AddQuotes (sDest) + " /D:" + sModified +
" /E /H /C /Y /R /Q";

// Create the shell object
var shell = WScript.CreateObject ("WScript.Shell");
var wshExec = shell.Exec (sCmd);

while (wshExec.Status == 0)
WScript.Sleep (5000);
}
</script>

<script language="JScript">
// Get the current date
var dt = new Date ();
var sDateFmt = (dt.getMonth () + 1) + "-" +
dt.getDate () + "-" + dt.getYear ();

XcopyFromTo ("H:\\*.*", "G:\\Products 1\\*.*", sDateFmt);
XcopyFromTo ("I:\\*.*", "G:\\Products 2\\*.*", sDateFmt);
</script>
</job>

In the above code, “XcopyFromTo” is the function that takes the backup. For every folder you want to copy, add an “XcopyFromTo” statement and specify the source and destination folders as the first two parameters. I have already added two such function calls as an example. The first function call copies all folders and files from the ‘H’ drive to G:\Products. The second function call copies all folders and files from the ‘I’ drive to G:\Products 2. In both cases, the function copies only those files and folders modified after the current date. When the script runs, it first takes the current date and formats it in the variable “sDateFmt”. You can use this variable in “XcopyFromTo”.

Thus, you have an effective and inexpensive solution to backing up data regularly.
 
Saturday, June 24, 2006 at 1:54 PM. Comments: 0.
Details
Post/View comments
 
 
 
 
 

This page is powered by Blogger. Isn't yours?

 
Copyright © Sachin Sharma. All rights reserved.