Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


Batch file problem

  • Please log in to reply
3 replies to this topic

#1 cjayed


  • Members
  • 3 posts
  • Local time:01:22 AM

Posted 30 March 2010 - 02:21 PM

I created a backupfile.bat to run from my user's Windows Scheduler. So far I've put the bat file on 35 computers and intend to add it to at least another 30-40 (o/s are a mix of xp and 2000). The bat file is supposed to backup to a network server, five Lotus Notes email files (ex. bookmarks, id files, ini files) including a large file that can be up to 5gb or more. The scheduled times for the backups have been randomly selected. The backup process using the Windows Scheduler and the backupfile.bat files seems to work ..for the most part ..pretty good. There have been a few that just wouldn't run and so I would change the scheduled time and then they would run. The backupfile.bat file includes a statement to connect to the server: net use Y: \\theServer\backupDir and a statement to disconnect: net use Y: /delete /YES. I also have it write to a log file each time it xcopies one of the five files. So...my BIG problem is ... sometimes four of the files will be copied just fine and the fifth one, which is that big one up to 5 or more gb (Lotus archive file) will not be copied (and the log file shows nothing copied). I don't know if it's just too big of a drain on resources at some point somewhere or what (any ideas?), because the next day it might copy the big file just fine. However, when it chooses not to copy that big file, it for some reason DELETES the big file that was there from the previous successful copy...AND this is a very bad thing. Very glad I noticed this before I needed to restore that file for someone and it wasn't there. My intent IS (and my code should be) to replace the old files with the new files BUT not if the new file is NOT going to be copied. Here is my code:

And thank you in advance for any help...or advice...or tips ;-)

[codebox]@echo off
::Save path where the Lotus files are located.
:: Files are directly under C:
SET LotusDir=c:\lotus\notes
SET LotusDataDir=C:\lotus\notes\data
SET LotusArchiveDir=C:\lotus\notes\data\Archive
::Connects mapping session
net use Y: /delete /YES
net use Y: \\theServer\backupDir
::Create Folder for User
::Save path where files will be backed up to
SET vArchive=Y:\%USERNAME%\
::Only want to keep one day's logs so delete log file each time
@ECHO Y | DEL %vArchive%%LotusBackupsLog.txt
::Save path where log file will go for redirects below
SET TheLog=%vArchive%%LotusBackupsLog.txt
ECHO ~ bookmark.nsf ~ >>%TheLog%
XCOPY %LotusDataDir%\bookmark.nsf %vArchive%/Y/Q >>%TheLog%
ECHO %TIME% >>%TheLog%
ECHO ~ id files ~ >>%TheLog%
XCOPY %LotusDataDir%\*.id %vArchive%/Y/Q >>%TheLog%
ECHO ~ notes.ini ~ >>%TheLog%
XCOPY %LotusDir%\notes.ini %vArchive%/Y/Q >>%TheLog%
ECHO ~ names.nsf ~ >>%TheLog%
XCOPY %LotusDataDir%\names.nsf %vArchive%/Y/Q >>%TheLog%
echo Backing up your Lotus files. You can minimize and continue working while it's running.
echo When its done running it will close on its own.
ECHO ~ archive file ~ >>%TheLog%
XCOPY %LotusArchiveDir%\*.nsf %vArchive%/Y/Q >>%TheLog%
ECHO ~ Finish time %TIME% ~>>%TheLog%
::Disconnects mapping session>>%TheLog%
net use Y: /delete /YES[/codebox]

BC AdBot (Login to Remove)


#2 PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • Gender:Male
  • Local time:04:22 AM

Posted 30 March 2010 - 06:13 PM

Hello cjayed.

You could first rename the old backup file and try to the copy new file into the archive.
If sucessful, delete the old backup file.
Otherwise, write to the log that it failed and restore the backup file.

A couple tips for batch files in general that may help

If you are performing multiple commands where you are directing output into one stream, you can do this:
	ECHO Hello
	ECHO World
	ECHO Deleting Temp.txt . . .
	del Temp.txt
) >> log.txt 2>>&1
In a program like yours, you will probably want to include the error stream too. You can do that using the "2>&1" above. Notice that Log.txt will shows Temp.txt not found.

This will show messages like "1 Files(s) copied" or "File not found: ???" and can help with debugging.

@ECHO Y | DEL %vArchive%%LotusBackupsLog.txt
Can be replaced with del /q [...]

With Regards,
The Panda

#3 Romeo29


    Learning To Bleep

  • Members
  • 3,194 posts
  • Gender:Not Telling
  • Location:
  • Local time:03:22 AM

Posted 30 March 2010 - 11:53 PM

xcopy breaks when you are copying a large number of files or files with very large size. Instead of xcopy, you should use robocopy.exe from Microsoft.
You can get robocopy from Win 2003 Resoure Toolkit.

#4 cjayed

  • Topic Starter

  • Members
  • 3 posts
  • Local time:01:22 AM

Posted 16 April 2010 - 11:21 AM

Thank you for all your responses and tips. I am going to look into Robocopy when I get a chance. In the meantime, using the Z switch seems to be working pretty good.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users