用dos命令备份和恢复sql server 数据库

这里是批处理命令-----备份的

delete
d:\restore\cw_ft.bak delete d:\restore\cw_sd.bak sqlcmd -i "bak.sql"

 

这是sqlcmd 备份的  
:connect .
BACKUP DATABASE cw_ft TO DISK = 'd:\restore\cw_ft.bak' WITH INIT go BACKUP DATABASE cw_sd TO DISK = 'd:\restore\cw_sd.bak' WITH INIT go

 

 

这是批处理---恢复的
sqlcmd -i "restore.sql"
这是sqlcmd    恢复的

:connect .
USE master GO ALTER DATABASE [cw_ft] SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO --查看是否还有用户连接 --SELECT * FROM sys.[sysprocesses] WHERE DB_NAME([dbid])='cw_ft' --GO ALTER DATABASE [cw_ft] SET MULTI_USER GO RESTORE DATABASE [cw_ft] FROM DISK = N'd:\restore\cw_ft.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10 go ALTER DATABASE [cw_sd] SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO --查看是否还有用户连接 --SELECT * FROM sys.[sysprocesses] WHERE DB_NAME([dbid])='cw_sd' --GO ALTER DATABASE [cw_sd] SET MULTI_USER GO RESTORE DATABASE [cw_sd] FROM DISK = N'd:\restore\cw_sd.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10 go

 

你可能感兴趣的:(用dos命令备份和恢复sql server 数据库)