简单实现Standby Sql Server数据库
2007-05-17 09:37:05 来源:WEB开发网核心提示: 过程p_delete_db_test_backup的源代码:if exists (select *from dbo.sysobjectswhere id = object_id(N'[dbo].[p_delete_db_test_backup]')and OBJECTPRO
过程p_delete_db_test_backup的源代码:
if exists (
select *
from dbo.sysobjects
where id = object_id(N'[dbo].[p_delete_db_test_backup]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_delete_db_test_backup]
GO
create PROCEDURE dbo.p_delete_db_test_backup
AS
DECLARE
@year1 varchar(4),
@month1 varchar(2),
@day1 varchar(2),
@sqlstr varchar(2000)
begin
--Get year & month &day fromat of the day before yesterday
SET @year1 = substring(convert(varchar,datepart(yyyy,getdate()-2)),1,4)
SET @month1 =substring(convert(varchar,datepart(mm,getdate()-2)),1,2)
SET @day1=substring(convert(varchar,datepart(dd,getdate()-2)),1,2)
if len(@month1)<2 set @month1 = '0' + @month1
if len(@day1)<2 set @day1 = '0' + @day1
set @sqlstr='del F:ackup_datadb_testdb_test_db_'+@year1+@month1+@day1+'*.bak'
select @sqlstr
exec master..xp_cmdshell @sqlstr
set @sqlstr='del F:ackup_datadb_testdb_test_tlog_'+@year1+@month1+@day1+'*.trn'
select @sqlstr
exec master..xp_cmdshell @sqlstr
end
四、结束语
这里介绍的简单实现Standby Sql Server数据库方法在我的工作环境也是运行良好的。
它没有主从服务器之间明显的依赖关系,没有复杂的配置,只要我们定好备份和恢复时间计划表,就可以简单实现实时备份数据库的目的了。
赞助商链接