for SQL Server DB。

set DBList=Account Bill Contest Log Message
for %%a IN (%DBList%) DO (
    CALL RestoreScript.bat %%a
)
-----------------------------------------------------
RestoreScript.bat

set BackupDir=D:\DBBackup
set DBName=%1
set DBHost=192.168.1.1,1433
set DBPath=D:\SQL_DATA
set BackupTimeStr=2012-6-8
set BackupFile=%BackupDir%\%DBName%_%BackupTimeStr%.bak

IF "%DBName%" NEQ "" goto ExecuteBackup
    echo 未指定資料庫名稱
    pause
    exit 0

:ExecuteBackup
echo === 還原 %DBName% 資料庫
echo ---------------------------------------------------------------------------

echo 執行從 %BackupDir% 還原
@echo sqlcmd -U flyfox -P flyfox -S %DBHost% -Q "RESTORE DATABASE [%DBName%] FROM DISK=N'%BackupFile%' WITH REPLACE, MOVE '%DBName%' TO '%DBPath%\%DBName%.mdf', MOVE '%DBName%_log' TO '%DBPath%\%DBName%_log.LDF'"

@sqlcmd -U flyfox -P flyfox -S %DBHost% -Q "RESTORE DATABASE [%DBName%] FROM DISK=N'%BackupFile%' WITH REPLACE, MOVE '%DBName%' TO '%DBPath%\%DBName%.mdf', MOVE '%DBName%_log' TO '%DBPath%\%DBName%_log.LDF'"

flyfox 發表在 痞客邦 PIXNET 留言(0) 人氣()