Solved

Batch file help needed

Posted on 2006-11-14
5
213 Views
Last Modified: 2008-02-01
A friend gave me a batch file for me to configure and schedule to run my own backups, but it's not working.

Here is the original file:

@echo off
xcopy C:\Mydocu~1\*.* g:\backup\Mydocuments\*.* /k/r/y/c/h/e/f
xcopy C:\MyFile~1\*.* g:\backup\My Files\*.* /k/r/y/c/h/e/f
xcopy C:\Mypict~1\*.* g:\backup\Mypictures\*.* /k/r/y/c/h/e/f
xcopy C:\MyBusi~1\*.* g:\backup\MyBusinessInformation\*.* /k/r/y/c/h/e/f
xcopy C:\MyCHOf~1\*.* g:\backup\MyCHOfiles-inactive\*.* /k/r/y/c/h/e/f
xcopy C:\Docume~1\owner\*.* g:\backup\DocumentsAndSettings\owner\*.* /k/r/y/c/h/e/f
exit

First question: What do the switches mean (/k/r/y/c/h/e/f)? I've searched online, but haven't found answers.

Second related question: I'm using Windows XP and whenever I've customized this to work on my machine (substituting the correct names and paths), it either won't work (is this because one of the users I'm trying to back up has an "&" in the name?) or, if I bypass the "&" in the command, it only performs the first five backup operations, but not the rest.

Also, where can I go to learn about simple batch files and how to troubleshoot them?

Thanks for the help--I'd like to get this resolved today, if possible, which is why I'm giving it 500 points.

0
Comment
Question by:reckon
  • 2
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 450 total points
ID: 17940222
As for your first question: no need to search online. Open a command prompt, enter "xcopy /?", and you'll get a help on what the switches mean.
Two golden rules:
* Never use the short path (unless you've verified it with "dir /x"); there's no guarantee that a short name is always "<first six letters>~1", whereas the full name's there and always correct.
* Always use quotes around the path when copying.
So change your script to something like (guessing on the full names here, obviously)

xcopy "C:\My Documents\*.*" "g:\backup\Mydocuments\*.*" /k/r/y/c/h/e/f
xcopy "C:\My Files\*.*" "g:\backup\My Files\*.*" /k/r/y/c/h/e/f
xcopy "C:\My Pictures\*.*" "g:\backup\Mypictures\*.*" /k/r/y/c/h/e/f
xcopy "C:\My Business Information\*.*" "g:\backup\MyBusinessInformation\*.* /k/r/y/c/h/e/f
xcopy "C:\My CHO Files\*.*" "g:\backup\MyCHOfiles-inactive\*.*" /k/r/y/c/h/e/f
xcopy "C:\Documents and Settings\owner\*.*" "g:\backup\DocumentsAndSettings\owner\*.*" /k/r/y/c/h/e/f

And, yes, the ampersand is a special character. It should work if you use quotes, though.
Nice place to start with batch scripts: http://www.robvanderwoude.com/
0
 
LVL 38

Assisted Solution

by:Shift-3
Shift-3 earned 50 total points
ID: 17940299
Looks like most of what I was going to say has already been said.  Here's what's left:

Robocopy.exe from the Server 2003 Resource Kit Tools is more configurable and reliable than xcopy.  It can be downloaded here:
http://www.microsoft.com/downloads/details.aspx?familyid=9D467A69-57FF-4AE7-96EE-B18C4790CFFD

A good reference site for XP commands and syntax:
http://www.ss64.com/nt/index.html
0
 

Author Comment

by:reckon
ID: 17942196
The quotes and being able to spell out the complete path (rather than xxxxx~) are what was needed--thanks!

So if I wanted to backup my files to alternating directories so that no backup is overwritten until another backup exists, would the simplest solution be to have two batch files, each pointing to different backup directories and scheduled to run on alternating weeks?
0
 
LVL 83

Expert Comment

by:oBdA
ID: 17945758
That's probably the easiest solution for you at the moment, yes.
You could use the same script and pass a command line parameter in the tasks to define a target folder, but you might want to do that once you have aquired a bit more experience with batch scripts.
It would look something like that:

REM *** Target folder is passed as first argument in the command line, for example 'backupscript.cmd G:\Backup01':
REM *** Set variable TargetFolder to first argument, stripping potential quotes:
set TargetFolder=%~1
xcopy "C:\My Documents\*.*" "%TargetFolder%\Mydocuments\*.*" /k/r/y/c/h/e/f
xcopy "C:\My Files\*.*" "%TargetFolder%\My Files\*.*" /k/r/y/c/h/e/f
etc.
0
 

Author Comment

by:reckon
ID: 17946856
Thanks--
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now