⑴ sql2008数据库备份命令,和截断命令,能解释更清楚的有加分
sqlserver备份两种方式
1. 通过维护计划
2. 通过job运行命令
--差异备份
EXECUTE master.dbo.xp_create_subdir N'D:\pic\RE\TEST'
GO
BACKUP DATABASE [TEST] TO DISK = N'D:\pic\RE\TEST\TEST_backup_201101051801.bak'
WITH DIFFERENTIAL , NOFORMAT, NOINIT,
NAME = N'TEST_backup_20110105180152', SKIP, REWIND, NOUNLOAD, STATS = 10
go
--完整备份
BACKUP DATABASE [TEST] TO DISK = N'D:\pic\RE\TEST_backup_201101051802.bak'
WITH NOFORMAT, NOINIT,
NAME = N'TEST_backup_20110105180256', SKIP, REWIND, NOUNLOAD, STATS = 10
go
--强制还原
--REPLACE覆盖已存在数据库
RESTORE DATABASE TEST
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\TEST.BAK'
WITH MOVE 'TEST' TO 'D:\pic\TEST.mdf',
MOVE 'TEST_log' TO 'D:\pic\TEST_log.ldf',
STATS = 10, REPLACE
GO
--显示备份列表
RESTORE FILELISTONLY
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\TEST.BAK'
go
生成年月日的备份文件
declare @databasename nvarchar(50)
set @databasename = 'ExtDB'
DECLARE @strPath NVARCHAR(200)
set @strPath = convert(NVARCHAR(19),getdate(),120)
set @strPath = REPLACE(@strPath, ':' , '.')
set @strPath = 'E:\工作目录\bk\' + @databasename+@strPath + '.bak'
BACKUP DATABASE @databasename TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT