应客户需求,对数据库进行备份,数据库每天备份,备份到两个路径下,之前试过备份一次,出现一定的报错
以下为数据库的日常备份脚本
run
{
Allocate channel c1 type disk;
Allocate channel c2 type disk;
crosscheck archivelog all;
delete noprompt archivelog until time 'sysdate-3';
delete noprompt expired archivelog all;
report obsolete;
delete noprompt obsolete;
backup filesperset=3 format='D:\rman\%T_%d_%s_%p.bus','D:\7dayrman\%T_%d_%s_%p.bus' as compressed backupset database;
backup filesperset=10 format='D:\rman\%T_%d_%s_%p.arc','D:\7dayrman\%T_%d_%s_%p.bus' as compressed backupset archivelog all;
backup format='D:\rman\%T_%d_%s_%p.ctl','D:\7dayrman\%T_%d_%s_%p.bus' current controlfile;
Release channel c1;
Release channel c2;
}
#查看rman配置
show all;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\rman', 'D:\7dayrman';
#修改为,此处备份的路径
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\2019-5-13';
#开始备份
run
{
Allocate channel c1 type disk;
Allocate channel c2 type disk;
backup filesperset=3 format='D:\2019-5-13\%T_%d_%s_%p.bus' as compressed backupset database;
backup filesperset=10 format='D:\2019-5-13\%T_%d_%s_%p.arc' as compressed backupset archivelog all;
backup format='D:\2019-5-13\%T_%d_%s_%p.ctl' current controlfile;
Release channel c1;
Release channel c2;
}
#出现报错
RMAN-20039: 设置双工模式时格式中需要有 %c
#根据报错修改RMAN配置为
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\2019-5-13\%T_%d_%s_%p_%c';
#并修改备份脚本
run
{
Allocate channel c1 type disk;
Allocate channel c2 type disk;
backup filesperset=3 format='D:\2019-5-13\%T_%d_%s_%p_%c.bus' as compressed backupset database;
backup filesperset=10 format='D:\2019-5-13\%T_%d_%s_%p_%c.arc' as compressed backupset archivelog all;
backup format='D:\2019-5-13\%T_%d_%s_%p_%c.ctl' current controlfile;
Release channel c1;
Release channel c2;
}
#查看备份情况
alter session set NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss';
set line 200 pages 1000
select start_time,end_time,output_device_type,status,elapsed_seconds,compression_ratio,OUTPUT_BYTES/1024/1024/1024 GB
from v$rman_backup_job_details order by start_time;
#修改RMAN的配置
show all
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\rman', 'D:\7dayrman';
#后续发现备份目录下备份有两份,仔细研究发现rman还有以下配置
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
#正确的备份思路应该是修改RMAN配置为
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\2019-5-13';
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
#备份完成后再修改为
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\rman', 'D:\7dayrman';
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 2;