Jump to content

Issue Basic Batch Backup Script

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
lickfrog

lickfrog

    Newbie

  • Members
  • Pip
  • 3 posts
I've written a basic bat backup script but I seem to have an issue with the xcopy command. My intention was to create backup solution for a specific application database that will import the Database path form the windows registry and copy the contents of the database stored at imported location to an external drive but for some reason its generating an error on the xcopy command. Any suggestions would be greatly appreciated, Thanks!

Current Code:
@echo off

:: variables

set drive=Y:\_BACKUP\DATA

set backup=c:\progra~1\APPDIR\DATA\*.*


FOR /F "tokens=2*" %%A IN ('REG QUERY "HKLM\SOFTWARE\Application\General" /v PATH') DO SET path=%%B

echo path=%path%

goto 001


:001

if exist %drive%\Backup.001 goto 002

echo ### Backing up directory...

xcopy /s /c /d /e /h /i /r /k /y "%path%" "%drive%\Backup.001"

echo Backup Complete!

time /t

date /t

pause

goto end


:002

if exist %drive%\Backup.002 goto 003

echo ### Backing up directory...

xcopy /s /c /d /e /h /i /r /k /y "%path%" "%drive%\Backup.002"

echo Backup Complete!

time /t

date /t

pause

goto end


:003

if exist %drive%\Backup.003 goto 004

echo ### Backing up directory...

xcopy /s /c /d /e /h /i /r /k /y "%path%" "%drive%\Backup.003"

echo Backup Complete!

time /t

date /t

pause

goto end


:004

if exist %drive%\Backup.004 goto 005

echo ### Backing up directory...

xcopy /s /c /d /e /h /i /r /k /y "%path%" "%drive%\Backup.004"

echo Backup Complete!

time /t

date /t

pause

goto end


:005

if exist %drive%\Backup.005 goto 006

echo ### Backing up directory...

xcopy /s /c /d /e /h /i /r /k /y "%path%" "%drive%\Backup.005"

echo Backup Complete!

time /t

date /t

pause

goto end


:006

if exist "%drive%\Temp.005" rd /s /q "%drive%\Temp.005"

rename "%drive%\Backup.005" "Temp.005"

rename "%drive%\Backup.004" "Backup.005"

rename "%drive%\Backup.003" "Backup.004"

rename "%drive%\Backup.002" "Backup.003"

rename "%drive%\Backup.001" "Backup.002"

echo ### Backing up directory...

xcopy /s /c /d /e /h /i /r /k /y "%path%" "%drive%\Backup.001"

echo Backup.005 was renamed to Temp.005!

echo Temp.005 will be deleted at next backup!

echo.

echo.

echo Backup Complete!

time /t

date /t

pause



:end

Error/generated output:
path=C:\Program Files\APPDIR\DATA\

### Backing up directory...

'xcopy' is not recognized as an internal or external command, operable program or batch file.

Backup Complete!

<Actual Time>

<Actual Date>

Press any key to continue...


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Open a command prompt and type xcopy. It may not exist in your OS.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
lickfrog

lickfrog

    Newbie

  • Members
  • Pip
  • 3 posts
Actually both the xcopy and the FOR commands work without issue when used separately but when used together in this format I get the above error.