Ms Sql Server 基本管理脚本(2)

 /*

 *创建备份设备
 */
--添加备份设备
sp_addumpdevice 'disk', 'northwind_backup', 'f:\northwd.bak'
 
--删除备份设备
sp_dropdevice 'northwind_backup'
 
--查看备份设备
sp_helpdevice
 
/*
 *修改数据库还原模型
 */
--完全还原
alter database northwind 
set recovery full
 
--简单还原
alter database northwind
set recovery simple
 
--大容量日志还原
alter database northwind
set recovery bulk_logged
 
/*
 *完全备份
 */
--备份
backup database northwind to northwind_backup
--还原
restore database northwind from northwind_backup
 
/*
 *差异备份
 */
--备份
backup database northwind to northwind_backup
backup database northwind to northwind_backup
with differential
--还原
restore database northwind 
from northwind_backup with norecovery
restore database northwind from northwind_backup
with file=2, recovery
 
/*
 *事务日志备份
 */
--备份
backup database northwind to northwind_backup
backup log northwind to northwind_backup
--还原
restore database northwind from northwind_backup with norecovery
restore log northwind from northwind_backup with norecovery
--还原到某个即时点
restore log northwind from northwind_backup with recovery, stopat 'Jue 14, 2006 12:00 AM'
 
/*
 *文件和文件组备份
 */
--备份:
backup database mydb file =‘mydbfile1’filegroup = ‘primary’to mydb_backup1
backup database mydb file =‘mydbfile2’filegroup = ‘primary’to mydb_backup2
backup database mydb file =‘mydbfile3’filegroup = ‘mygroup’to mydb_backup3
backup database mydb file =‘mydbfile4’filegroup = ‘mygroup’to mydb_backup4
--还原:
restore database mydb file =‘mydbfile1’filegroup = ‘primary’to mydb_backup1
restore database mydb file =‘mydbfile2’filegroup = ‘primary’to mydb_backup2
restore database mydb file =‘mydbfile3’filegroup = ‘mygroup’to mydb_backup3
restore database mydb file =‘mydbfile4’filegroup = ‘mygroup’to mydb_backup4
 

你可能感兴趣的:(Ms Sql Server 基本管理脚本(2))