Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Setup of log file for batch script  (Read 9922 times)

0 Members and 1 Guest are viewing this topic.

ppice

    Topic Starter


    Newbie

    Thanked: 1
    • Experience: Experienced
    • OS: Other
    Setup of log file for batch script
    « on: December 25, 2012, 07:34:15 PM »
    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



    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Setup of log file for batch script
    « Reply #1 on: December 25, 2012, 07:46:38 PM »
    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

    pause

    ppice

      Topic Starter


      Newbie

      Thanked: 1
      • Experience: Experienced
      • OS: Other
      Re: Setup of log file for batch script
      « Reply #2 on: December 25, 2012, 09:01:14 PM »
      Thank you so much foxidrive, my first Batch script is working perfectly!