Announcement

Collapse
No announcement yet.

Batch copy problem

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch copy problem

    Hello all!

    I`m kinda new to batch (Win2003) programming and I`m having an issue with my script...

    Script is designed to stop 4 services, copy SQL data do mapped drive, and then again start 4 services...

    OK, when logged on, task works perfectly, but when I log off task fails to COPY files..

    It does stop and start services, It does send me mail, but It won`t copy data..

    Below is the script:

    Code:
    @ECHO off
    if exist "log.txt" del "log.txt"
    
    echo                !!!KOPIRAM SQL BAZE PODATKOV!!! >>log.txt
    
    echo	********************************************************* >>log.txt
    echo	*	NE PREKINJAJ PROCESA, TO SO BACKUPI!!!		* >>log.txt
    echo	*							* >>log.txt
    echo	*   OKNO SE BO SAMODEJNO ZAPRLO, KO BO PROCES KONCAN	* >>log.txt	
    echo	*   SQL SERVER JE MED PROCESOM UGASNJEN - NE ZAGANJAJ!  * >>log.txt
    echo	********************************************************* >>log.txt
    
    echo Ustavljam servise >>log.txt
    
    sc stop SQLSERVERAGENT >>log.txt
    
    ping localhost -n 10
    
    sc stop MSSQLSERVER >>log.txt
    sc stop POPcon >>log.txt
    sc stop Email2DB >>log.txt
    
    ping localhost -n 20
    
    echo Servisi ustavljeni!! >>log.txt
    
    echo Kopiram SQL data! >>log.txt
    
    copy "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" X:\SQL_BACKUP >>log.txt
    
    echo Kopiranje koncano, ponovno zaganjam servise! >>log.txt
    
    sc start SQLSERVERAGENT >>log.txt
    
    ping localhost -n 10
    
    sc start MSSQLSERVER >>log.txt
    sc start POPcon >>log.txt
    sc start Email2DB >>log.txt
    
    ping localhost -n 5
    
    echo SQL service state: >>log.txt
    sc query mssqlserver | FIND "STATE" >>log.txt
    echo SQL agent service state: >>log.txt
    sc query SQLSERVERAGENT | FIND "STATE" >>log.txt
    echo POPcon service state: >>log.txt
    sc query popcon | FIND "STATE" >>log.txt
    echo EMAIL2DB service state: >>log.txt
    sc query email2db | FIND "STATE" >>log.txt
    echo All DONE! >>log.txt
    sendemail -f [email protected] -t [email protected] -u SQL Backup state -m Backup completed on VM-DC successfully! -s vm-exchange:25 -a log.txt
    What am I donig wrong here?

    P.S.

    ping function is used as a delay function

  • #2
    Re: Batch copy problem

    a few things you can try:

    maybe the pause(ping) is not long enough?
    instead of pausing try this: for each command
    start/w/b sc stop SQLSERVERAGENT
    (With Start /wait the batch continues when the command is finished)

    Or, maybe the destination path contains alreay files with the same name?
    instead of using copy try this:
    Set DriveX=\\unc\path here
    Xcopy /E /Y "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\" "%DriveX%\SQL_BACKUP\"

    (With XCOPY you also have the extra option to copy only newer files Xcopy /D /E Y)

    In your script you did not put quotes around the destination path!.
    (Note I did not use the mapped drive but the UNCpath here, you can give that a try too if the other suggestions didn't work)

    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Batch copy problem

      Hi!
      Thanks for reply!

      Well problem is, that as I run the script by double clicking it, everything works like a charm...

      It only fails when nobody is logged on server... It would just not copy files even though services are all stopped...

      Comment


      • #4
        Re: Batch copy problem

        That is a common problem with scheduled tasks.
        The job is executed 'Runas', It is using just that users 'profile' for its environment, and is not aware of any present drive mappings.
        And also make sure the job will be executed by a Domain Administrator plus password.

        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Batch copy problem

          aaaa so that would be the problem...

          Mapped drive!

          Will change the script and report it back...

          Thanks!

          Comment


          • #6
            Re: Batch copy problem

            yup, UNC paths intstead of mapped drive worked good!

            Thanks again!

            Comment

            Working...
            X