?
Solved

Robocopy & batch file question

Posted on 2006-07-21
12
Medium Priority
?
6,826 Views
Last Modified: 2009-12-16
i run nightly backups using robocopy.  my batch script works fine... stuff gets copied as it should...

except one item stopped working (it was working fine for a few weeks and then recently just stopped working).  it's very weird.  let me describe the batch file to give a clearer picture.
the batch file has several different things to back up... so it will back up folder X and then folder Y ... blah blah.  when it gets to the folder in question (we'll call it folder Z), the batch file just stops.  the log shows no error.  the last thing in the log is the successful backup for folder Y.  if there are other items in the batch file after folder Z, they don't get backed up...  it's as if the batch file terminates when it encounters the command to backup folder Z.

so i copied the segment of the batch file dealing with folder Z to a separate batch file and initiated it.  it ran fine.

i also moved the command for backing up folder Z so it was in a different order in the original batch file.  the original batch file still terminates when it encounters the folder Z backup command.

here is the portion of the batch file which deals with "folder Z"
Rem Backup to duplicate database
net use y: \\qm_it\Mas90_on_qm_it /user:Owner qm_it
robocopy x:\DBServer\Mon \\qm_it\Mas90_on_qm_it /MIR /r:1 /w:1 >> c:\log\thu.txt
net use y: /delete



here is the full contents of the batch script:
Rem Backup Tserver
robocopy f:\data x:\Tserver\Data /MIR /r:1 /w:1 > c:\log\thu.txt

Rem Backup DBServer
robocopy \\Qmvandbserver\MAS200\MAS90 X:\DBServer\thu /MIR /r:1 /w:1 >> c:\log\thu.txt

Rem Backup Citrix
robocopy \\Citrix\CitrixQ x:\Citrix /MIR /r:1 /w:1 >> c:\log\thu.txt

::Rem Backup ACT Database
::This is handled by ACT Scheduler

Rem Backup to duplicate database
net use y: \\qm_it\Mas90_on_qm_it /user:Owner qm_it
robocopy x:\DBServer\Mon \\qm_it\Mas90_on_qm_it /MIR /r:1 /w:1 >> c:\log\thu.txt
net use y: /delete

Rem Backup Marketing External Drive
robocopy "\\D8F0FC61\Marketing Driven" x:\Marketing /MIR /r:1 /w:1 >> c:\log\thu.txt

****
any ideas on what could be happening?
0
Comment
Question by:zephyr_hex (Megan)
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
12 Comments
 
LVL 24

Expert Comment

by:Kenneniah
ID: 17156427
How is this batch file being run?
If scheduled, does it run when you manually execute it?

At a quick glance, it looks like it might be trying to connect to the same resource with 2 different usernames, which Windows won't let you do.
net use y: \\qm_it\Mas90_on_qm_it /user:Owner qm_it       -> using username of Owner
robocopy x:\DBServer\Mon \\qm_it\Mas90_on_qm_it /MIR /r:1 /w:1 >> c:\log\thu.txt      -> since using UNC path instead of Y: it will use the current logged on user.
Why are you mapping the drive with the first command if you aren't using the drive letter (Y:) in the robocopy command?

0
 
LVL 44

Author Comment

by:zephyr_hex (Megan)
ID: 17157711
the backup batch runs as a scheduled task.

i don't know if the complete batch runs when i manually execute it.  i am trying to avoid that because it would mean i'd have to sit and wait while it copies stuff.

this part does execute successfully when it's run in its own batch file:
Rem Backup to duplicate database
net use y: \\qm_it\Mas90_on_qm_it /user:Owner qm_it
robocopy x:\DBServer\Mon \\qm_it\Mas90_on_qm_it /MIR /r:1 /w:1 >> c:\log\thu.txt
net use y: /delete


that is a good point about using "y" since i've mounted the drive and assigned a letter.  i will modify tonight's automated batch to use the drive letter instead of the path.
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 17161947
you have assigned special permissions to this Y: resource, some USER permissions.  Robocopy is NOT a user, it runs as a system service (MS style), therefore, it is NOT adopting the permissions you assigned to the Y drive, and cannot access the resource.  You need to make the permissions for that resource GLOBAL for the sake of the backup -- all users, ALL SERVICES.  It is called "everyone".
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 44

Author Comment

by:zephyr_hex (Megan)
ID: 17168764
the permissions on the folder is Everyone, for both sharing and security.

i also changed the batch files to refer to y: instead of \\

this is weird.  my batch file for saturday did not run completely.  robocopy shows the entry just prior to "folder Z" as completed, and that's the end of the log...

but my sunday batch file has "folder Z" as the first item to get backed up... and it completed.  the other items in the batch file completed as well.

i don't get it.  if it were a permission or sharing issue, it wouldn't work either way.  i would prefer not to just have "folder Z" listed first because if the batch has its problem where it doesn't complete, that means nothing got backed up that night.... it would be nice to figure out why it's doing this so i can fix the problem.
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 17173021
" robocopy shows the entry just prior to "folder Z" as completed, and that's the end of the log...
but my sunday batch file has "folder Z" as the first item to get backed up"

Well isnt it clear that the next batch file is taking up where the last one failed?  Sounds like the scheduling of these batch files maybe too complex for you to debug?  Since you have only given fragments of them here, I would suggest that the problem is in the batch files failing for some reason, the batch list sitting in the cue, and then taking up the next day.  

A typical cause could be that your scheduler is too brief a time interval for the first job to complete.  So if the second part is scheduled to start before the first part is completed, the second part simply will fail and NOT start, until the next day.  You need to get into your entire scheduling history, and make sure that each batch has 2x the time it should take to complete before the next batch begins, for safety margin.
0
 
LVL 44

Author Comment

by:zephyr_hex (Megan)
ID: 17176867
the scheduler is set for 6 hours.  these backups run in less than an hour.  only 1 batch file is scheduled per night so there are no conflicts.

the batch files aren't picking up where the last one failed.  i guess i didn't explain... i have 1 batch file for mon-fri, one for sat and one for sun ... because different stuff gets backed up on the weekend.
the mon-fri batch is the one i posted above... the one that's dying off when it gets to the "folder Z" backup.

the sat batch file actually has the folder Z backup as the first item in the batch file.  it ran fine.

the sunday batch file has the folder Z backup further down so other things get backed up first... but those "other things" are different from the mon-fri script so it's not like something just before the folder Z backup is causing robocopy to hang.  robocopy is finishing on the items prior to the folder Z backup according to the log.

what could cause it to run ok on one day (when it's first in the list) and not run ok on another day (when it's not the first thing)?
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 17178772
as I siad earlier, either permissions getting lost by the original batch file, or an error in the batch file which is not apparrent from the snippet.  You have to look at all of the file before the error to find out what is happening.
0
 
LVL 44

Author Comment

by:zephyr_hex (Megan)
ID: 17188792
there is no error.
the log that the batch file produces shows successful backups of everything prior to folder Z
the log just stops instead of moving on to folder Z.  robocopy isn't even putting the header into the log..

each time robocopy is executed, it writes the following to the log:
----------------------------------------------------------------------
ROBOCOPY v 1.96  :  Robust File Copy for Windows NT
----------------------------------------------------------------------

and then gives some other details.

the last thing robocopy has in the log is this:
---------------------------------------------------------------------

            Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :      1973         0      1973         0         0         0
    Files :     50194        10     50184         0         0         0
    Bytes :99389.956 g   77.97 m106049.880 g         0         0         0
    Times :   0:00:24   0:00:04                       0:00:00   0:00:20

    Speed :            18894729 bps.
    Speed :            1081.165 mb/min.

    Ended : Tue Jul 25 22:07:35 2006


which is a successful completion of the command before the backup of folder Z.  if it were a folder permission issue, i would see something like the following:
----------------------------------------------------------------------
ROBOCOPY v 1.96  :  Robust File Copy for Windows NT
----------------------------------------------------------------------

  Started : Sun Jul 02 22:00:27 2006

   Source : \\server\BEARINGS\
     Dest : x:\PG\BEARINGS\
    Files : *.*
  Options : *.* /S /E /PURGE /MIR /R:1 /W:1
ERROR 1326 (0x0000052E) Accessing Source Directory \\server\BEARINGS\
Logon failure: unknown user name or bad password.

Waiting 1 seconds... Retrying...
ERROR 1326 (0x0000052E) Accessing Source Directory \\server\BEARINGS\
Logon failure: unknown user name or bad password.


ERROR: RETRY LIMIT EXCEEDED.

ERROR 1326 (0x0000052E) Accessing Source Directory \\server\BEARINGS\
Logon failure: unknown user name or bad password.
***************
but i'm not seeing that.  it shows nothing at all after the end of the prior item in the batch file.

my batch files are identical in the way they are set up to execute.  the only difference is the order of the items in the batch file (what order the items get backed up).  as i said, folder Z seems to work fine when it is the first item.  it does not work when it is something other than first.  since robocopy isn't even printing the header for the folder Z backup, it leads me to think that there may be an issue with mounting the drive...as if the command to mount the drive isn't returning so that the batch file continues to execute.  but why this is only an issue when folder Z is not the first item stumps me.

by the way.... i have posted the entire batch file above.  it's not just a snippet.

0
 
LVL 44

Author Comment

by:zephyr_hex (Megan)
ID: 17194178
ok, i figured out the problem.  i output the mount command to a log file so i could see what was going on.  here it is:

y: has a remembered connection to \\server\ISO9001. Do you
want to overwrite the remembered connection? (Y/N) [Y]:


in the batch files, i mount some drives to Y and then do the backup.  i then delete the mount.

how do i get around the "remembered connection"?  i assume i need to either mount or unmount in a different way.
0
 
LVL 24

Accepted Solution

by:
Kenneniah earned 2000 total points
ID: 17195401
Hmm, the "net use y: /delete" should be taking care of that. Although I don't see "\\server\ISO9001" in your batch file.
Is Y: being mapped by another script and then not getting deleted?

Either way, in all our scripts, we use the /delete option before tying to map just to make sure the drive letter isn't in use.
So maybe just add a line to your batch file to look like...

net use y: /delete
net use y: \\qm_it\Mas90_on_qm_it /user:Owner qm_it
robocopy x:\DBServer\Mon y: /MIR /r:1 /w:1 >> c:\log\thu.txt
net use y: /delete
0
 
LVL 44

Author Comment

by:zephyr_hex (Megan)
ID: 17224918
oh ok... good idea.  i'll try that in tonight's script.

(the \\server\ISO9001 gets backed up on saturday only.  what's weird is that i have 3 or 4 other drives that get mounted to y: *before* the folder z attempts to mount ... and all of those are working fine.  maybe that erorr is just from that one night... and on other nights it will show some other drive is already using y:.)
0
 
LVL 44

Author Comment

by:zephyr_hex (Megan)
ID: 17235299
putting the net use y: /delete before the mount of y worked.

i guess for some reason the other batch file is not always unmounting the drive even though i have the /delete command specified.
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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