[Oracle] 使用rman进行备份(全量、增量)


本文总阅读量

0、修改rman默认配置参数

1
2
3
4
CONFIGURE RETENTION POLICY TO REDUNDANCY 3; # 冗余三份
CONFIGURE BACKUP OPTIMIZATION ON; #开启备份自动优化
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK; #归档日志删除策略,备份过两次可以删除
CONFIGURE CONTROLFILE AUTOBACKUP ON; #控制文件自动备份

1、数据库备份完之后,不删除归档,不删除多余备份

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
### sh rman_backup.sh ORACLE_SID(实例名)
export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=${ORACLE_HOME}
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
backuptime=`date +"%Y%m%d-%H%M%S"`
backuppath=/tmp/backuporacle
if [ ! -d ${backuppath} ];then
sudo mkdir -p ${backuppath}
else
:
fi

$ORACLE_HOME/bin/rman target / log=${backuppath}/full_backup_${backuptime}.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
sql 'alter system archive log current';
backup as compressed backupset full database format '/tmp/backuporacle/db_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all format '/tmp/backuporacle/arch_%d_%T_%s_%p.bak';
backup current controlfile format '/tmp/backuporacle/ctl_%d_%T_%s_%p.bak';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}

exit

EOF

2、数据库备份完之后,直接删除归档(备份达到两次的归档不会再被备份,删除归档时会被删除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
### sh rman_backup.sh ORACLE_SID(实例名)
export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=${ORACLE_HOME}
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
backuptime=`date +"%Y%m%d-%H%M%S"`
backuppath=/tmp/backuporacle
if [ ! -d ${backuppath} ];then
sudo mkdir -p ${backuppath}
else
:
fi

$ORACLE_HOME/bin/rman target / log=${backuppath}/full_backup_${backuptime}.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
sql 'alter system archive log current';
backup as compressed backupset full database format '/tmp/backuporacle/db_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all format '/tmp/backuporacle/arch_%d_%T_%s_%p.bak' delete all input;
backup current controlfile format '/tmp/backuporacle/ctl_%d_%T_%s_%p.bak';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}

exit

EOF

3、根据冗余策略,删除多余的备份、删除多余的归档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
### sh rman_backup.sh ORACLE_SID(实例名)
export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=${ORACLE_HOME}
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
backuptime=`date +"%Y%m%d-%H%M%S"`
backuppath=/tmp/backuporacle
if [ ! -d ${backuppath} ];then
sudo mkdir -p ${backuppath}
else
:
fi

$ORACLE_HOME/bin/rman target / log=${backuppath}/full_backup_${backuptime}.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
sql 'alter system archive log current';
backup as compressed backupset full database format '/tmp/backuporacle/db_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all format '/tmp/backuporacle/arch_%d_%T_%s_%p.bak' delete all input;
backup current controlfile format '/tmp/backuporacle/ctl_%d_%T_%s_%p.bak';
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}

exit

EOF

4、增量备份数据库

4.1、level 0 增量数据库备份

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
### sh rman_backup.sh ORACLE_SID(实例名)
export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=${ORACLE_HOME}
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
backuptime=`date +"%Y%m%d-%H%M%S"`
backuppath=/tmp/backuporacle
if [ ! -d ${backuppath} ];then
sudo mkdir -p ${backuppath}
else
:
fi

$ORACLE_HOME/bin/rman target / log=${backuppath}/full_backup_${backuptime}.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
sql 'alter system archive log current';
BACKUP INCREMENTAL LEVEL 0 DATABASE FORMAT '/tmp/backuporacle/db_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all format '/tmp/backuporacle/arch_%d_%T_%s_%p.bak' delete all input;
backup current controlfile format '/tmp/backuporacle/ctl_%d_%T_%s_%p.bak';
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}

exit

EOF

4.2、level 1 差异增量备份数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
### sh rman_backup.sh ORACLE_SID(实例名)
export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=${ORACLE_HOME}
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
backuptime=`date +"%Y%m%d-%H%M%S"`
backuppath=/tmp/backuporacle
if [ ! -d ${backuppath} ];then
sudo mkdir -p ${backuppath}
else
:
fi

$ORACLE_HOME/bin/rman target / log=${backuppath}/full_backup_${backuptime}.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
sql 'alter system archive log current';
BACKUP INCREMENTAL LEVEL 1 DATABASE FORMAT '/tmp/backuporacle/db_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all format '/tmp/backuporacle/arch_%d_%T_%s_%p.bak' delete all input;
backup current controlfile format '/tmp/backuporacle/ctl_%d_%T_%s_%p.bak';
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}

exit

EOF

4.3、level 1 累积增量备份数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
### sh rman_backup.sh ORACLE_SID(实例名)
export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=${ORACLE_HOME}
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
backuptime=`date +"%Y%m%d-%H%M%S"`
backuppath=/tmp/backuporacle
if [ ! -d ${backuppath} ];then
sudo mkdir -p ${backuppath}
else
:
fi

$ORACLE_HOME/bin/rman target / log=${backuppath}/full_backup_${backuptime}.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
sql 'alter system archive log current';
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE FORMAT '/tmp/backuporacle/db_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all format '/tmp/backuporacle/arch_%d_%T_%s_%p.bak' delete all input;
backup current controlfile format '/tmp/backuporacle/ctl_%d_%T_%s_%p.bak';
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}

exit

EOF

4.4、可以查看增量备份的的数据大小,如果增量备份文件超过了20%,建议使用全量备份

1
2
3
4
5
6
SELECT   FILE#, INCREMENTAL_LEVEL, COMPLETION_TIME,
BLOCKS, DATAFILE_BLOCKS
FROM V$BACKUP_DATAFILE
WHERE INCREMENTAL_LEVEL > 0
AND BLOCKS / DATAFILE_BLOCKS > .2
ORDER BY COMPLETION_TIME;
目录
  1. 1. 0、修改rman默认配置参数
  2. 2. 1、数据库备份完之后,不删除归档,不删除多余备份
  3. 3. 2、数据库备份完之后,直接删除归档(备份达到两次的归档不会再被备份,删除归档时会被删除
  4. 4. 3、根据冗余策略,删除多余的备份、删除多余的归档
  5. 5. 4、增量备份数据库
    1. 5.1. 4.1、level 0 增量数据库备份
    2. 5.2. 4.2、level 1 差异增量备份数据库
    3. 5.3. 4.3、level 1 累积增量备份数据库
    4. 5.4. 4.4、可以查看增量备份的的数据大小,如果增量备份文件超过了20%,建议使用全量备份

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog