Tuesday, October 28, 2008

Back up files that have been changed or modified today


@echo off
:: Default to tokens 1 to 3.
SET UnivDateTokens=1-3

:: Determine the first token.
FOR /F "tokens=1 delims=.:/-, " %%A IN ('DATE /T') DO SET UnivDatePart1=%%A

:: If the first token is a letter then use tokens 2 to 4 instead.
IF "%UnivDatePart1:~0,1%" GTR "9" SET UnivDateTokens=2-4

:: Extract the current date and put it into the yy, mm, dd variables depending upon the system date format.
FOR /F "tokens=%UnivDateTokens% delims=.:/-, " %%A in ('DATE /T') DO (
FOR /F "skip=1 tokens=2-4 delims=/-,()." %%D IN ('ECHO.^|DATE') DO (
SET %%D=%%A
SET %%E=%%B
SET %%F=%%C
SET UnivDatePart1=
SET UnivDateTokens=
)
)

:: Create a shortcut to the current date/time in CCYYMMDD format.
SET TodaysDateTime=%MM%-%DD%-%YY%

:: variables
set drive=C:\BackTmp
set backupcmd=xcopy /s /c /d:%TodaysDateTime% /e /h /i /r /y

:: echo ### Backing up My Documents...
:: %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

:: echo ### Backing up Favorites...
:: %backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

:: echo ### Backing up email and address book (Outlook Express)...
:: %backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"
:: %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"

:: echo ### Backing up email and contacts (MS Outlook)...
:: %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

:: echo ### Backing up the Registry...
:: if not exist "%drive%\Registry" mkdir "%drive%\Registry"
:: if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
:: regedit /e "%drive%\Registry\regbackup.reg"

:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."

%backupcmd% "%USERPROFILE%\Desktop\test_replace" "%drive%\test"

echo Backup Complete!
@pause

No comments: