1.

Solve : Setup of log file for batch script?

Answer»

Hi,

I've been trying to setup a script to make a back up on my personal server on a daily basis. I've got the main features working but I'd LIKE to be able to create a log of the entire output of the script. This is the script that I have:

echo off
cls
:: variables
set drive=C:\Backup
set backupcmd=xcopy /e /y /i
set folder=%date:~7,2%

echo Backup Folder Maintenance
RMDIR /S /Q "C:\backup\%folder%"
echo Backup Folder Maintenance Complete

echo Webserver Allain Backup
%backupcmd% "C:\xampp\htdocs\allain" "%drive%\%folder%\Allain Website"
echo Webserver Allain Backup Complete

echo Minecraft Server Backup
%backupcmd% "C:\Minecraft" "%drive%\%folder%\Minecraft"
echo Minecraft Server Backup Complete

echo Backup Complete!

backup.bat >> c:\backup\%folder%\log.txt

@PAUSE



The log gets written (SOMEWHAT) but the batch file doesn't copy the minecraft folder and gets stuck in a loop were it writes the log file over and over (I think it's looping but I don't know at what point). This is a partial copy of the batch file when running:

Minecraft Server Backup Complete
Backup Complete!
C:\backup\25\log.txt - The VOLUME for a file has been externally altered so that
the opened file is no LONGER valid.
C:\backup\25\log.txt - The process cannot access the file because it is being us
ed by another process.
The process cannot access the file because it is being used by another process.
C:\backup\25\log.txt - The process cannot access the file because it is being us
ed by another process.
The process cannot access the file because it is being used by another process.
C:\backup\25\log.txt - The process cannot access the file because it is being us
ed by another process.


At this point it never get to the pause and I need to manually close the console window.

Thank you in advance for your help!

Phil


This might work - you were running the batch file (backup.bat) a second time to echo to a log file, and then the script removes the location where the log file was.

The changes the location for the log file as well as a few other points.

Code: [Select]@echo off
cls
:: variables
set drive=C:\Backup
set backupcmd=xcopy /e /y /i
set folder=%date:~7,2%

(
echo Backup Folder Maintenance
if exist "C:\backup\%folder%\" RMDIR /S /Q "C:\backup\%folder%\"
echo Backup Folder Maintenance Complete

echo Webserver Allain Backup
%backupcmd% "C:\xampp\htdocs\allain\*.*" "%drive%\%folder%\Allain Website\"
echo Webserver Allain Backup Complete

echo Minecraft Server Backup
%backupcmd% "C:\Minecraft\*.*" "%drive%\%folder%\Minecraft\"
echo Minecraft Server Backup Complete

echo Backup Complete!
)> c:\backup\%folder%_log.txt 2>&1

pauseThank you so much foxidrive, my first Batch script is working perfectly!



Discussion

No Comment Found