数据库备份实例/**
**数据库备份实例
**朱二 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 –每一个小时
原创文章,作者:306829225,如若转载,请注明出处:https://blog.ytso.com/233886.html