标题: 【求助】DOS下实现数据库自动还原(需要增加一些代码)
[打印本页]
作者: creda
时间: 2009-1-7 17:08
标题: 【求助】DOS下实现数据库自动还原(需要增加一些代码)
@ECHO off
REM restore Database Script Log Files
SET dbbak_dir=d:\test\full back\
SET logbak_dir=d:\test\log\
if not exist %logbak_dir% mkdir %logbak_dir%
此次需要求助的代码
监控d:\test\full back\ 文件夹和d:\test\log\文件夹 这两个文件夹中文件的更新情况,如果出现新增文件,就将文件名(不包含扩展名)作为值赋给下面代码中标为红色的变量F_filename和L_filename
REM restore Database Name
SET A_Database_Name=test
SET A_DATE=%date:~0,4%
SET
F_filename=
SET
L_filename=
此处求助代码
如果F_filename和L_filename等于amino_db_%date:~0,4%0040或amino_db_%date:~0,4%1240 就执行restore处代码,或者输出字符“无!”
REM restore
ECHO use master >%dbbak_dir%FULL_restore_test.sql
rem ECHO SP_ADDUMPDEVICE 'DISK',>>%dbbak_dir%FULL_restore_test.sql
rem ECHO '%F_filename%', >>%dbbak_dir%FULL_restore_test.sql
rem ECHO '%dbbak_dir%%F_filename%.bak'; >>%dbbak_dir%FULL_restore_Amino.sql
rem ECHO go >>%dbbak_dir%FULL_restore_test.sql
ECHO restore DATABASE %A_Database_Name% >>%dbbak_dir%FULL_restore_test.sql
ECHO from DISK = '%dbbak_dir%%F_filename%.bak' >>%dbbak_dir%FULL_restore_test.sql
echo with move 'test_Data' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\test_data.mdf',>>%dbbak_dir%FULL_restore_test.sql
echo move 'test_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\test_log.ldf',>>%dbbak_dir%FULL_restore_test.sql
ECHO norecovery >>%dbbak_dir%FULL_restore_test.sql
rem ECHO SP_ADDUMPDEVICE 'DISK',>>%dbbak_dir%FULL_restore_test.sql
rem ECHO '%F_filename', >>%dbbak_dir%FULL_restore_test.sql
rem ECHO '%dbbak_dir%%L_filename.trn'; >>%dbbak_dir%FULL_restore_test.sql
rem ECHO go >>%dbbak_dir%FULL_restore_test.sql
ECHO restore log %A_Database_Name% >>%dbbak_dir%FULL_restore_test.sql
ECHO from DISK = '%dbbak_dir%%L_filename.trn' >>%dbbak_dir%FULL_restore_test.sql
ECHO go >>%dbbak_dir%FULL_restore_test.sql
ECHO .
REM isql.exe path
SET iSQL_PATH=C:\Program Files\Microsoft SQL Server\80\Tools\Binn\
REM Database user name and password
SET DBUser=user
SET DBpassword=1111111
ECHO restore DATABASE
"%iSQL_PATH%isqlw.exe" -d %A_Database_Name% -U %DBUser% -P %DBpassword% -i "%dbbak_dir%FULL_restore_Amino.sql" -o "%dbbak_dir%result_Amino.txt"
echo .
REM delete file
move /y %dbbak_dir%FULL_restore_test.sql %logbak_dir%
move /y %dbbak_dir%result_test.txt %logbak_dir%
echo .
[
Last edited by creda on 2009-1-7 at 17:18 ]
作者: creda
时间: 2009-1-8 17:59
居然没人理会