Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

Help with a batch file on Windows 7

I have a batch file, which I want to use for automating some backups, and although it seems to follow correct syntax, it just hangs (freezes).  Here is the code:
@echo off
REM variables
set drive=K:\Archive\laptop 
set backupcmd=xcopy /d /e /h /i /r /y

echo ### Backing up myData...
%backupcmd% "C:\myData" "%drive%\myData"

echo Backup Complete!
@pause

Open in new window

I do have more code that I want to put into the file but it will essentially be following the same structure as this (just a bunch of xcopy commands).  I'm not sure why this isn't working...no error message is displayed; it just echos back "Backing up myData..." in the DOS window and then sits like that, not responding.
0
David L. Hansen
Asked:
David L. Hansen
  • 7
  • 5
  • 3
2 Solutions
 
Jeff PerryWindows AdministratorCommented:
Just to be sure. Are the drives all local to the machine running the script?
0
 
Steve KnightIT ConsultancyCommented:
Well there is no logical reason off hand.  I would suggest remove the @echo off command so you can see what it is doing,  Maybe you have inadvertently called the batch file xcopy.cmd or xcopy.bat or there is another one in the same dir, or your path that is?

Presumably it carries on if you don't xcopy.

Steve
0
 
Jeff PerryWindows AdministratorCommented:
I have tested your script locally on my pc only making changes for source and destination drive paths with no issues.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
David L. HansenProgrammer AnalystAuthor Commented:
For testing, I've called the batch file "BackupMyFiles.bat" and I'm running it directly from my desktop (no scheduler yet, I'm just executing it manually).

My K:\ drive is a network drive.

Perhaps it is a permissions issue (although my profile does have admin privileges)?
0
 
Steve KnightIT ConsultancyCommented:
Start a command prompt.  Type the commands in manually, or run the batch file without the @Echo off at the top.  Does it stop at the xcopy line still?

Put in your batch file:

xcopy /?
pause

Does that cause it to choke still?

Steve
0
 
David L. HansenProgrammer AnalystAuthor Commented:
From the command prompt I can successfully run xcopy, but only from a local drive to a local drive. When it comes to copying to any network drive it freezes.  Surprisingly, I can't even view them from the command prompt (eg. 'cd K:\' gives me nothing...it just stays at the current directory).
0
 
Steve KnightIT ConsultancyCommented:
Very odd.  Presumably Ok from within explorer, never seen that before?!  What about if you do either:

@echo off
net use y: \\server\share
y:
dir

or

@echo off
pushd \\server\share
dir
popd

Steve
0
 
Steve KnightIT ConsultancyCommented:
cd K:\ btw does not change the drive, you either need:

K:
cd \

or

cd /d K:\

or

pushd k:\
0
 
David L. HansenProgrammer AnalystAuthor Commented:
@echo off
net use y: \\server\share
y:
dir

Open in new window

worked just fine (as did the change-directory with the /d switch).
0
 
David L. HansenProgrammer AnalystAuthor Commented:
Think I need to always just use the full UNC??  I'll test that right now.
0
 
David L. HansenProgrammer AnalystAuthor Commented:
That was it.  I just have to use the full UNC and it works :)   Not sure why...
0
 
Jeff PerryWindows AdministratorCommented:
the cd command only changes the directory you have to switch to that drive by issuing the drive.

For instance in you cd K:\ it set the directory for K: to root if you then issue K: you will be placed in the root of K:

if you were to put

cd K:\Archive\laptop
set drive=K:

that should work.

Here is how my test script ended up.

@echo off
REM variables
cd Z:\Archive\laptop\iperf
set drive=Z:
set backupcmd=xcopy /d /e /h /i /r /y

echo ### Backing up myData...
%backupcmd% "C:\iperf" "%drive%"

echo Backup Complete!
@pause 

Open in new window


I had to put the entire archive path in my cd statement to get it to work.
0
 
Steve KnightIT ConsultancyCommented:
especially if you schedule this the drive mapping will not exist anyway unless you run it scheduled as a user AND that user is logged in AND the drive is mapped.

If you use net use y: .... you might also want to remove the drive first with

net use y. /delete

and also consider the pushd.  this sets the drive and path for you, and will map a temporary drive to the path if a unc, e.g.

pushd \\server\share
xcopy c:\mydir \backupdit
popd

popd puts the drive mapping and current dir back where it was.

Steve
0
 
David L. HansenProgrammer AnalystAuthor Commented:
Thanks for the tips dragon.
0
 
David L. HansenProgrammer AnalystAuthor Commented:
It is working just as it should. :)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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