• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

Help on a batch file

hi there,

I would like to have a batch file or VB script that will do full and incremental copy of My network drive Z to E (local drive). The Z drive have multiple folders and sub folders. I will create a Job task on the computer to run the full backup once every 2weeks and the incremental will run daily.

I would like copy to overwrite the last week copy to avoid running ot of space n the local drive.

Thanks, Habib
0
Habib Z
Asked:
Habib Z
  • 3
  • 2
  • 2
  • +3
3 Solutions
 
ChickensaurCommented:
I believe the Xcopy command will be of use for you.  It's an extremely powerful copy tool for MS-DOS.  I'm including a link to all the flags needed.

http://www.computerhope.com/xcopyhlp.htm
0
 
Michael OrtegaSales & Systems EngineerCommented:
How are you then going to audit backup success/failure of that data? I would recommend looking at 3rd party applications to do your backups.

A couple mainstream names would be Symantec BackupExec and Acronis. There are several flavors of backup applications so you'd want to choose the one that best matches your environment.

MO
0
 
Habib ZNetwork AnalystAuthor Commented:
No I really do not care about the audit. I just want the job run.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
Habib ZNetwork AnalystAuthor Commented:
I agree X copy is the commad but the switches are confusing to me
 
0
 
ChickensaurCommented:
What switch do you need help with?
0
 
Steve KnightIT ConsultancyCommented:
Hav you thought of just using the built in ntbackup.exe?  You can schedule it to run a full or incremental backup daily, weekly, each friday, second friday of the month etc.... it's not the flashest backup program in the world, but it does do the job.  You end up with all the files in one large ".bkf" file which you use ntbackup to restore from.

If you do want files then if you want a full and incrementals then try something like:

full backup:
xcopy C:\sourcedir\*.* d:\destdir /s /e /h /r /q /o /y

For your incrementals at a simple level you could run them to a folder each, e.g.

xcopy C:\sourcedir\*.* d:\destdir\day1 /s /e /h /r /q /o /y /m

Th /m on the end backs up only files that have been changed (or at least those that got marked for archive.. which SHOULD be the same). It then clears the archive bit so that file doesn't get backed up again until it is modified again.

You can wrap the copy.. or use robocopy which is more powerful in a batch file and start setting directory names for destination based on the date perhaps, or keep so many old backups.  lots of possibilities, depens what you want to do.

e.g. here is one script of mine that does a simple backup of some files and keeps so many of the backup files:

http://scripts.dragon-it.co.uk/links/batch-versioning-backup

You can have it send you an email perhaps if it fails:

http://scripts.dragon-it.co.uk/links/email-from-batch

You can get a simple date for using as a foldername using code such as this:

set TODAYDATE=%date:~7,2%-%date:~4,2%-%date:~10,4%
if "%date:~2,1%"=="/" set TODAYDATE=%date:~3,2%-%date:~0,2%-%date:~6,4%

See my article here for more ways with date based folders etc.
http://www.experts-exchange.com/articles/OS/Microsoft_Operating_Systems/MS_DOS/Using-dates-in-batch-files-scripts.html
0
 
yogi4lifeCommented:
Hi

You should have a serious look at ROBOCOPY - much more suited to such challenges than XCOPY. It has been made by Microsoft and you find more infomation here:

   Wikipedia: http://en.wikipedia.org/wiki/Robocopy

   Windows front-ends (GUIs) for ROBOCOPY:

   Microsoft TechNet - ROBOCOPY GUI:   http://technet.microsoft.com/en-us/magazine/2006.11.utilityspotlight.aspx

    RichCopy:  http://technet.microsoft.com/en-us/magazine/2009.04.utilityspotlight.aspx

     "This simple tool was written by a Microsoft engineer named Derk Benisch, and all it really did was
     create a graphical interface for the very popular Robocopy command-line utility, which provided
     file copying capabilities far beyond what was built into Windows" - TechNet Magazine

0
 
BillDLCommented:
Hello Habib

You have received some excellent suggestions.  Let me just add one other option you may wish to consider.  I use Karen Kenworthy's free "Replicator" program:
http://www.karenware.com/powertools/ptreplicator.asp

You can use it in a few different ways after creating your different "jobs" in the program interface:

1. Allow it to run as a startup program, minimized and using its own scheduler
OR
2. Stop the timer and Exit the program, then later call it from the command line using the "job" name as the parameter.

Creating the separate "jobs" is easy enough and the program's help file explains all the options well enough for you to decide which settings to choose.  One setting is very important to choose carefully though, and that is the "Replicate Folder and File Deletions?" setting.  IF you enable this, the program keeps the source and destinations' contents synchronised, and will DELETE contents in the DESTINATION IF they have been deleted from the SOURCE since the last backup!  DO NOT tick this box for your purposes.  You are not syncing folders or drives.

The default behaviour of this program is to temporarily rename the file in the Destination Folder BEFORE a new copy is created there.  If the new copy is made successfully, the old copy is then deleted.  However, if the copy process fails for any reason, the old file will be restored by giving it back its original name.  This program default is a good safety buffer, but can use up extra space while processing.

There is, however, a job setting that overrides this default behaviour whereby the existing contents in the Destination are deleted BEFORE the copy begins.  The setting is (intuitively) entitled : "Delete Old Copy Before Creating New".  It is a potentially dangerous option to enable.  If hard drive space should become an issue enough that you would consider enabling this option, then you need a larger capacity destination drive rather than compromising like this.

Instead of enabling the "Delete Old Copy Before Creating New" setting for your weekly full backup, a better option would be to RENAME the existing folder in the destination and then delete it IF the Replicator program ran the job successfully.  This could be achieved by simple batch commands like testing the program's exit code and perhaps comparing the source and destination folders.

Apart from the above two warnings, the other settings are fine for doing an incremental update to the destination OR a full replacement in the destination.

When you create a named "job" the name and settings for that job are written to or appended to the file (on Windows XP):

"C:\Documents and Settings\<YourUserName>\Local Settings\Application Data\Karen's Power Tools\Replicator\Jobs.txt"

As long as you know the name of each job you can call them like this from the command line:

"C:\Program Files\Karen's Power Tools\Replicator\PTReplicator.exe" "Name_Of_Job"

If you were executing one job after another from a batch file it may be necessary to launch "PTReplicator.exe" with the START command like this:

start /wait "C:\Program Files\Karen's Power Tools\Replicator\PTReplicator.exe" "Name_Of_Job"

Otherwise you can just set the schedule for each job within the Replicator program and leave the program to autostart with Windows minimized to the System Tray awaiting the call.

The Windows Task Scheduler should accept the command lines for separate tasks and you wouldn't need a batch file or the Start /wait command.  That may be the safer option (ie. a Windows Service) than relying on a standard program startup.

You might as well test out the program to see if it does what you need, but I suggest using it on test folders/drives first.  It is only free for NON-commercial purposes, but it's only $25 a seat for 3 to 9 seats if used commercially.

Bill
0
 
Habib ZNetwork AnalystAuthor Commented:
Excellent suggestions. Thank you.
0
 
BillDLCommented:
Thank you Habib
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now