solidsnake
Solid State Member
- Messages
- 18
- Location
- uk
Hi could any one check the script and maybe find answer to this. As I still have out the date problem since the script translates my date to -12-2014 and losing the day somewhere.
@ECHO OFF
SETLOCAL
REM Get date in format YYYY-MM-DD (assumes the locale is the United States)
FOR /F “tokens=1,2,3,4 delims=/ †%%A IN (‘Date /T') DO SET NowDate=%%D-%%B-%%C
REM Build a list of databases to backup
SET DBList=%SystemDrive%SQLDBList.txt
SqlCmd -E -S MyServer -h-1 -W -Q “SET NoCount ON; SELECT Name FROM master.dbo.sysDatabases WHERE [Name] NOT IN (‘master','model','msdb','tempdb')†> “%DBList%â€
REM Backup each database, prepending the date to the filename
FOR /F “tokens=*†%%I IN (%DBList%) DO (
ECHO Backing up database: %%I
SqlCmd -E -S MyServer -Q “BACKUP DATABASE [%%I] TO Disk='D:Backup%NowDate%_%%I.bak'â€
ECHO.
)
REM Clean up the temp file
IF EXIST “%DBList%†DEL /F /Q “%DBList%â€
ENDLOCAL
@ECHO OFF
SETLOCAL
REM Get date in format YYYY-MM-DD (assumes the locale is the United States)
FOR /F “tokens=1,2,3,4 delims=/ †%%A IN (‘Date /T') DO SET NowDate=%%D-%%B-%%C
REM Build a list of databases to backup
SET DBList=%SystemDrive%SQLDBList.txt
SqlCmd -E -S MyServer -h-1 -W -Q “SET NoCount ON; SELECT Name FROM master.dbo.sysDatabases WHERE [Name] NOT IN (‘master','model','msdb','tempdb')†> “%DBList%â€
REM Backup each database, prepending the date to the filename
FOR /F “tokens=*†%%I IN (%DBList%) DO (
ECHO Backing up database: %%I
SqlCmd -E -S MyServer -Q “BACKUP DATABASE [%%I] TO Disk='D:Backup%NowDate%_%%I.bak'â€
ECHO.
)
REM Clean up the temp file
IF EXIST “%DBList%†DEL /F /Q “%DBList%â€
ENDLOCAL