尚未备份数据库 "****" 的日志尾部
执行存储过程脚本:
//---------------------------------------------------------
备份:
CREATE PROCEDURE adv_procedurebackup
@backtype int,--备份的类型
@backdbname varchar(20)='db_advertise',
@backtaskname varchar(50)='unknown',
@backpathname varchar(100),--备份的名称
@backsuffix varchar(10)='cbak'
AS
IF @backtype=0
BEGIN
BACKUP DATABASE @backdbname to disk=@backpathname
INSERT INTO t_databasebackup (databasebackup_type,databasebackup_pathname,databasebackup_datetime) values(@backtype,@backpathname,getdate())
END
ELSE
BEGIN
DECLARE @pathname varchar(150)
DECLARE @now datetime
DECLARE @time varchar(10)
SELECT @now=getdate()
SELECT @time=convert(VARCHAR(10),@now,108)
IF RIGHT(@backpathname,1) <> '\' BEGIN select @backpathname=@backpathname+'\' END
SELECT @pathname = @backpathname+convert(VARCHAR(20),@now,112)+left(@time,2)+substring(@time,4,2)+substring(@time,7,2)+'.'+@backsuffix
BACKUP DATABASE @backdbname to disk=@pathname
INSERT INTO t_databasebackup (databasebackup_type,databasebackup_jobname,databasebackup_pathname,databasebackup_datetime) values(@backtype,@backtaskname,@pathname,@now)
END
GO恢复:
CREATE PROCEDURE adv_procedurerestore
@backdbname varchar(20)='db_advertise',
@newtime varchar(40),--备份的时间
@newdbpath varchar(200),--备份数据库的路径
@backpathname varchar(100)--备份的名称
AS
DECLARE @dbname varchar(250)
DECLARE @dblogname varchar(250)
DECLARE @dbfilename varchar(250)
DECLARE @dblogfilename varchar(250)
SELECT @dbname = @backdbname
SELECT @dblogname = @backdbname+'_log'
SELECT @dbfilename = @newdbpath+'\'+@dbname+'_'+@newtime+'.mdf'
SELECT @dblogfilename = @newdbpath+'\'+@dblogname+'_'+@newtime+'.ldf'
RESTORE DATABASE @backdbname FROM DISK=@backpathname WITH MOVE @dbname TO @dbfilename,MOVE @dblogname TO @dblogfilename,NORECOVERY, REPLACE
GOSQL Server 2000,备份和恢复数据库 正常,
SQL Server 2005,的就报错了,尚未备份数据库 "****" 的日志尾部。如果该日志包含您不希望丢失的工作,请使用 BACKUP LOG WITH NORECOVERY 备份该日志。请使用 RESTORE 语句的 WITH REPLACE 或 WITH STOPAT 子句来只覆盖该日志的内容。
------解决方案--------------------
晕倒~ 楼上的显示有问题,
restore database xxx from disk='xxx' with replace