Windows backup script


echo %computername% %date% %time% >> c:\bat\synclog.txt
for /f “Tokens=1-4 Delims=/ ” %%i in (‘date /t’) do set dt=%%i-%%j-%%k-%%l
for /f “Tokens=1” %%i in (‘time /t’) do set tm=-%%i
set tm=%tm::=-%
set dtt=%dt%%tm%

wbadmin start backup -include:c:  -backupTarget:e: -systemstate -allcritical -quiet >>log.txt
rem wbadmin start systemstatebackup -backuptarget:e: -quiet >>log.txt

echo %computername% %date% %time% > c:\bat\backlogemail.txt
dir c:\ >> c:\bat\backlogemail.txt
type log.txt >> c:\bat\backlogemail.txt
:::::::::::::: Lets set some variables ::::::::::::::
set subj=-s “dc4 backup”
set server=-server
set attachf=-attacht backlogemail.txt
set debug=-debug -log blat.log -timestamp
::::::::::::::::: Now we run Blat!  :::::::::::::::::
blat %0 -to %eMail% -f %efrom% %subj% %attachf% %server% %debug%

delete files from a directory and keep last 15 days

forfiles /P y:\backup2\sqlbackup /D -15 /C “cmd /c del @path”  >> c:\bat\deletelog.txt

copy and keep last 7 days

robocopy “C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup” D:\backup /MOV /MINAGE:7

rem delete extra log files

forfiles /P c:\bat\logs /D -30 /C “cmd /c del @path”  >> c:\bat\deletelog.txt