Mostrando las entradas con la etiqueta xcopy. Mostrar todas las entradas
Mostrando las entradas con la etiqueta xcopy. Mostrar todas las entradas

28 de enero de 2011

Respaldar en Windows con XCOPY

Necesité ejecutar un respaldo en una Tarea programada de Windows, usando XCOPY. He aquí el script.

@echo off

REM http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
REM /y Do not ask about overwritting
REM /q quit
REM /s copy subdirectories
REM /i create source directory
REM /e copy empty directories
REM /k retain read only attribute
REM /r copy read only files
REM /h copy hidden and system files
REM /exclude:filename1[+[filename2]][+[filename3]] : Specifies a list of files containing strings.

set SOURCEDIR=%1

set DATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

xcopy %SOURCEDIR% %SOURCEDIR%-%DATETIME% /i /s /e /k /r /h >> %SOURCEDIR%-%DATETIME%.log 2>&1

if errorlevel 5 goto diskerror
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 goto exit

:lowmemory
echo Insufficient memory to copy files or invalid drive or command-line syntax. >> %SOURCEDIR%-%DATETIME%.log
goto exit

:abort
echo You pressed CTRL+C to end the copy operation. >> %SOURCEDIR%-%DATETIME%.log
goto exit

:diskerror
echo Disk error. >> %SOURCEDIR%-%DATETIME%.log
goto exit

:exit