Link to home
Start Free TrialLog in
Avatar of pcrequest
pcrequestFlag for United States of America

asked on

error code 31 on batch file with psexec - ntback list of computers

Can't get my batch file to successfully run.  I'm getting error code 31 from psexec v1.94.  What I am doing is running a batch file that goes out and backs up all the computers i've designated in a text file, one at a time to a target share in a ws2003 domain.  I'm running the batch file as a domain admin.  Ran fine on a test environment.  I can psexec cmd to the computers and run other commands like ipconfig, etc.  Triple checked my paths.  I tried a simpler way and got same error 31:
>psexec \\INTENDEDCLIENT ntbackup backup C: /f "\\TARGETSERVER\backup\INTENDEDCLIENT.bkf"

PsExec v1.94 - Execute processes remotely
Copyright (C) 2001-2008 Mark Russinovich
Sysinternals - www.sysinternals.com

ntbackup exited on INTENDEDCLIENT with error code 31.

My code snippet is a single line in a .bat file.  All XP Pro SP2 machines.  I've accomplished this in the past doing the computers one by one.
for /F %%a in (c:\backup\machines.txt) do psexec \\%%a ntbackup backup C: /f "\\TARGETSERVER\backup\%%a.bkf" /SNAP:on 2>>C:\backup\ntbackuplog.txt

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, the exit code 31 is an NTBackup exit code, not from PSExec itself.  Have a look at the NTBackup log files on those remote computers and see if that gives you more info.

Regards,

Rob.
Avatar of pcrequest

ASKER

backup log says:

Backup Status
  The operation was not performed because the specified media cannot be found.
----------------------
 Event viewer:


Event Type: Error
Event Source: NTBackup
Event Category: None
Event ID: 8017
Date:  5/14/2008
Time:  1:14:01 AM
User:  N/A
Computer: [INTENDEDCLIENT1]
Description:
NTBackup error: 'The operation failed. Consult the Backup Report for more details.'
 
I verified I can write to the target machine's folder as the user I'm running the batch as, from an afflicted computer.  I can verify the ntbackup process runs under the same user
Hi, I don't use NTBackup, but after reading these:
http://technet.microsoft.com/en-us/magazine/cc160782.aspx
http://support.microsoft.com/kb/814583

I would suspect that you may need to add a couple more switches...try this:
for /F %%a in (c:\backup\machines.txt) do psexec \\%%a ntbackup backup C: /f "\\TARGETSERVER\backup\%%a.bkf" /SNAP:on /FU /M normal /UM 2>>C:\backup\ntbackuplog.txt

You might to double check that the command actually runs locally first, by just running
ntbackup backup C: /f "\\TARGETSERVER\backup\%hostname%.bkf" /SNAP:on /FU /M normal /UM 2

on that machine.

Regards,

Rob.
I figured out if I inlclude the psexec username switch -u then the error go away. Strange because it wasn't needed in my VM lab environment--similar domain.  Also odd because I'm running the batch under the same user context as specified in the -u deal.
Solved.  
If anyone can explain why, they get the points.  Thanks all.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I may post a related, new question regarding how to backup all harddrives in an automated fashion.  right now i have to supply a drive letter- only way i know how to do it. might be limitation of ntbackup. thanks for the explaination.
No problem.  Just a heads up on your new question....you could use VBScript to detect all local drive letters of a computer:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
    Wscript.Echo objDisk.DeviceID
Next

then just add that to the command line as needed...and have VBScript execute that command:

strCommand = "ntbackup backup " & strDriveLetters & " /f ""\\TARGETSERVER\backup\%%a.bkf"" /SNAP:on 2>>C:\backup\ntbackuplog.txt"
Set objShell = CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True

Regards,

Rob.