sqlserver的备份和恢复 命令非计划任务
作者:互联网
这里的备份恢复是指用命令
备份
BACKUP DATABASE [SnPrintZC] TO DISK = N'F:\sqlbackup\sp2' WITH NOFORMAT, NOINIT,
NAME = N'备份说明', SKIP, NOREWIND, NOUNLOAD, STATS = 10
SnPrintZC 数据库名 disk 备份路径绝对值
恢复
RESTORE DATABASE [SnPrintZC] FROM DISK = N'F:\sqlbackup\sp2' WITH FILE = 1, NOUNLOAD, STATS = 5
脱机
ALTER DATABASE [SnPrintZC] SET OFFLINE WITH ROLLBACK IMMEDIATE;
状态
select name,state_desc from sys.databases
查看进程
EXEC sp_who2
杀死
KILL 1
恢复
恢复的时候,先做脱机处理
1 先看数据库是否还有人用 EXEC sp_who2
2 如果有人用 杀死进程 KILL 1 (1 为 EXEC sp_who2中返回的结果中使用数据库的pid)
3 执行脱机 ALTER DATABASE [SnPrintZC] SET OFFLINE WITH ROLLBACK IMMEDIATE;
4 查看数据库是否脱机 select name,state_desc from sys.databases
5 执行恢复命令 RESTORE DATABASE [SnPrintZC] FROM DISK = N'F:\sqlbackup\sp2' WITH FILE = 1, NOUNLOAD, STATS = 5
标签:sp,DATABASE,备份,脱机,sqlserver,命令,DISK,SnPrintZC 来源: https://www.cnblogs.com/wang2650/p/14963126.html