复制代码 代码如下:
数据库备份实例/**
**数据库备份实例
**朱二 2004年5月
**备份策略:
**数据库名:test
**备份文件的路径e:\backup
**每个星期天凌晨1点做一次完全备份,为保险起见,备份到两个同样的完全备份文件test_full_a.bak和test_full_b.bak
**每天1点(除了星期天)做一次差异备份,分别备份到两个文件test_df_a.bak和test_df_b.bak(采用附加到原备份的方式)
**每一个小时做一次事务日志备份,分别备份到两个文件test_log_a.bak和test_log_b.bak(采用附加到原备份的方式)
**/
–第一 完全备份部分
–新增作业
exec sp_add_job @job_name = ‘完全备份’
–新增作业步骤1,把数据库备份到test_full_backup_a.bak
exec sp_add_jobstep @job_name = ‘完全备份’,
@step_name = ‘setp1’,
@subsystem = ‘tsql’,
@command = ‘backup database test to disk=”e:\backup\test_full_a.bak” with init’,
@on_fail_action=3, –失败后转到下一步
@on_success_action=3,– 成功后转到下一步
@retry_attempts = 5,
@retry_interval = 5
–新增作业步骤2,把数据库备份到test_full_b.bak
exec sp_add_jobstep @job_name = ‘完全备份’,
@step_name = ‘setp2’,
@subsystem = ‘tsql’,
@command = ‘backup database test to disk=”e:\backup\test_full_b.bak” with init’,
@retry_attempts = 5,
@retry_interval = 5
–调度
exec sp_add_jobschedule @job_name = ‘完全备份’,
@name = ‘schedule_1’,
@freq_type = 8, — 按周
@freq_interval = 1, –每星期天执行
@freq_recurrence_factor=1,
@active_start_time = 10000 –开始时间: 凌晨1点
–第二 差异备份部分
–新增作业
exec sp_add_job @job_name = ‘差异备份’
–新增作业步骤1,把数据库备份到test_df_a.bak
exec sp_add_jobstep @job_name = ‘差异备份’,
@step_name = ‘setp1’,
@subsystem = ‘tsql’,
@command = ‘backup database test to disk=”e:\backup\test_df_a.bak” with differential’,
@on_fail_action=3, –失败后转到下一步
@on_success_action=3,– 成功后转到下一步
@retry_attempts = 5,
@retry_interval = 5
–新增作业步骤2,把数据库备份到test_df_b.bak
exec sp_add_jobstep @job_name = ‘差异备份’,
@step_name = ‘setp2’,
@subsystem = ‘tsql’,
@command = ‘backup database test to disk=”e:\backup\test_df_b.bak” with differential’,
@retry_attempts = 5,
@retry_interval = 5
–调度
exec sp_add_jobschedule @job_name = ‘差异备份’,
@name = ‘schedule_1’,
@freq_type = 8, — 按周
@freq_interval = 126, –星期一至星期六
@freq_recurrence_factor=1,
@active_start_time = 10000 –开始时间: 凌晨1点
–第二 事务备份部分
–新增作业
exec sp_add_job @job_name = ‘事务备份’
–新增作业步骤1,把数据库备份到test_log_a.bak
exec sp_add_jobstep @job_name = ‘事务备份’,
@step_name = ‘setp1’,
@subsystem = ‘tsql’,
@command = ‘backup log test to disk=”e:\backup\test_log_a.bak”’,
@on_fail_action=3, –失败后转到下一步
@on_success_action=3,– 成功后转到下一步
@retry_attempts = 5,
@retry_interval = 5
–新增作业步骤2,把数据库备份到test_log_b.bak
exec sp_add_jobstep @job_name = ‘事务备份’,
@step_name = ‘setp2’,
@subsystem = ‘tsql’,
@command = ‘backup log test to disk=”e:\backup\test_log_b.bak”’,
@retry_attempts = 5,
@retry_interval = 5
–调度
exec sp_add_jobschedule @job_name = ‘事务备份’,
@name = ‘schedule_1’,
@freq_type = 4, — 按天
@freq_interval=1,–每一天
@freq_subday_type=8, –按小时
@freq_subday_interval=1 –每一个小时