oracle11gRAC环境使用RMAN备份方案(ASM)_fin

来源:互联网 发布:数据库中的游标是什么 编辑:程序博客网 时间:2024/06/07 18:31

 

更改归档日志路径

archive log list

show parameter db_recover

alter system set log_archive_dest_1='location=+DATA';

 alter system switch logfile;

初始:

[oracle@zx ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Oct 1618:20:57 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: zx (DBID=2731354802)

 

RMAN> show all;

using target database control file instead of recovery catalog

RMAN configuration parameters for database with db_unique_name oadb are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

CONFIGURE BACKUP OPTIMIZATION OFF; # default

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; #default

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; #default

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default

CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT'OPTIMIZE FOR LOAD TRUE ; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO'/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_zx1.f'; # default

 

开始设置备份策略

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

RMAN>CONFIGURE BACKUP OPTIMIZATION ON;

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

RMAN>CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO'+DATA/backup/rman_bak/%F';

RMAN>CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TOBACKUPSET;

修改后的

RMAN> show all;

RMAN configuration parameters for database with db_unique_name OADBare:

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

CONFIGURE BACKUP OPTIMIZATION ON;

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '+DATA/backup/rman_bak/%F';

CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default

CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT'OPTIMIZE FOR LOAD TRUE ; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO'/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_oadb2.f'; # default

开启块跟踪

[oracle@zx ~]$ sqlplus / as sysdba

SQL>alter database enable block change tracking using file'/home/oracle/backup/rman_bak/block_track.log';

查看

SQL>col filename for a50

SQL> select * from v$block_change_tracking;

STATUS     FILENAME                                         BYTES

---------- ------------------------------------------------------------

ENABLED   +RCY1/zx/changetracking/ctf.298.861133721        11599872

*****************************************************************************

 

修改控制文件保存的时间

控制文件保存的时间由参数CONTROL_FILE_RECORD_KEEP_TIME决定,默认值是7天。 我们可以改成0到365之间的任意值。

当RMAN 采用nocatalog模式进行备份时,就会有一个问题。 当我们使用catalog模式的时候,RMAN 备份的信息都会存放到catalog目录里。 如果没有使用catalog目录,那么RMAN备份的信息就会保存到控制文件里。 RMAN 的这些备份信息对恢复来说非常重要,如果没有这些信息,是无法使用RMAN 进行恢复的。 所以,如果采用nocatalog模式,我们要主备备份控制文件,同时,要将控制文件记录的保存时间设置为不小于选中数据库备份的周期,否则就可能在备份介质上有数据库备份,但是控制文件不存在与备份相关的备份记录,在这种情况下,将无法恢复这些较早的文件。

SQL> select name,value from v$parameter wherename='control_file_record_keep_time';

NAME                          VALUE

------------------------------ -------------------------------------------------

control_file_record_keep_time   7

SQL> alter system set control_file_record_keep_time=30;

系统已更改。

SQL> show parameter control_file_record_keep_time

NAME                                TYPE        VALUE

------------------------------------ -----------------------------------------

control_file_record_keep_time       integer     20

 

增量备份

只备份从上次备份发生变化的块。

1)增量备份首先做全备:

0,1,2,3,4,5

2)增量备份的好处是加快备份时间。

3)oracle增量备份有两种:1.差异增量备份 2.累计增量备份

4)0级备份就是全被,做其他级别的备份前必须有0级,否则系统会做0级备份。

5)差异增量备份:backup incremental level 0format

        只要等于或小于自己的级别,前面的备份就可以作为备份的起点。

日  一  二  三  四  五  六  日

0   2   2  1   2   2    2   0

全  一  一  三  一  一  一  全

周一周二只备份一天就行了,但周三需要把周一二三的都备一遍,因为它级别比前面的备份低,周四就只备一天就行了,周日又要做全备了。

比如周三早晨挂了,需要周日周一周二才能恢复到周三早晨,但如果周四早晨就只需要周日,周三就能恢复。周六挂需要周日,周三,周四,周五四个备份集。

6)累计增量备份:backup incremental level 0cumulative format

只看备份级别比自己低的。

日  一  二  三  四  五  六  日

0   2   2  1   2   2   2   0

全  一  二  三  一  二  三  全

周日全备,周一备份一天的,周二备份2天的。周三备份周一二三的。

周四只备份一天的,周五备份两天的,周六备份3天的。周日全备。

假如周三恢复,需要0级别和一个到周二 的备份就行了。恢复更快。

周六挂需要周日,周三,周五三个备份集。

*************************************************************************

OA数据库使用差异增量备份

日  一  二  三  四  五  六  日

0   2   2  1   2   2   2   0

全  一  一  三  一  一  一  全

周日全备,周一周二只备份一天就行了,但周三需要把周一二三的都备一遍,因为它级别比前面的备份低,周四周五周六就只备一天就行了,周日又要做全备了。

编辑备份脚本 

脚本存放位置/home/oracle/scripts/rman/bin/   

日志存放位置/home/oracle/scripts/rman/log/

备份存放位置+DATA/backup/rman_bak/

 

热备0级脚本

[oracle@zx bin]$ cat rman0.sh

#!/bin/bash

export ORACLE_SID=oadb1

export ORACLE_BASE=/u01/app/oracle

exportORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

export PATH=$ORACLE_HOME/bin

rman target /<< EOF

run{

sql'alter system switchlogfile';

allocate channel c1 typedisk;

allocate channel c2 typedisk;

crosscheck archivelog all;

backup as compressedbackupset incremental level 0 format '+DATA/backup/rman_bak/%d_%T_%U_0.bak'database plus archivelog;

delete noprompt obsolete;

}

quit;

EOF

热备1级脚本

[oracle@zx bin]$ cat rman1.sh

#!/bin/bash

export ORACLE_SID=oadb1

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

export PATH=$ORACLE_HOME/bin

rman target / << EOF

run{

sql'alter system switch logfile';

allocate channel c1 type disk;

allocate channel c2 type disk;

crosscheck archivelog all;

backup as compressed backupset incremental level 1 format '+DATA/backup/rman_bak/%d_%T_%U_1.bak' database plusarchivelog;

delete noprompt obsolete;

}

quit;

EOF

 

热备2级脚本

[oracle@zx bin]$ cat rman2.sh

#!/bin/bash

export ORACLE_SID=oadb1

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

export PATH=$ORACLE_HOME/bin

rman target / << EOF

run{

sql'alter system switch logfile';

allocate channel c1 type disk;

allocate channel c2 type disk;

crosscheck archivelog all;

backup as compressed backupset incremental level 2 format '+DATA/backup/rman_bak/%d_%T_%U_2.bak'database plus archivelog;

delete noprompt obsolete;

}

quit;

EOF

设置权限

[oracle@zx bin]$ chmod -R 777 rman0.sh

[oracle@zx bin]$ chmod -R 777 rman1.sh

[oracle@zx bin]$ chmod -R 777 rman2.sh

[oracle@zx bin]$ ll

total 12

-rwxrwxrwx 1 oracle oinstall 468 Oct 21 17:03 rman0.sh

-rwxrwxrwx 1 oracle oinstall 468 Oct 21 17:05 rman1.sh

-rwxrwxrwx 1 oracle oinstall 468 Oct 21 17:06 rman2.sh

配置作业

一个crontab文件中包含有六个字段:

分钟 0-59

小时 0-23

月中的第几天 1-31

月份 1 - 12

星期几 0 - 6, with 0 = Sunday

 

配置

[oracle@zx ~]$ crontab -e

查看

[oracle@zx ~]$ crontab -l

0 2 * * 0 sh/home/oracle/scripts/rman/bin/rman0.sh >> /home/oracle/scripts/rman/log/backup0.log 2>&1 

0 2 * * 3 sh /home/oracle/scripts/rman/bin/rman1.sh  >> /home/oracle/scripts/rman/log/backup1.log 2>&1

0 2 * * 1,2,4,5,6 sh/home/oracle/scripts/rman/bin/rman2.sh >> /home/oracle/scripts/rman/log/backup2.log 2>&1

日志变大可清空

[oracle@zx ~]$ cat /dev/null > /home/oracle/scripts/rman/log/backup0.log

[oracle@zx ~]$ cat /dev/null >/home/oracle/scripts/rman/log/backup1.log

[oracle@zx ~]$ cat /dev/null >/home/oracle/scripts/rman/log/backup2.log

[oracle@zx ~]$ ll /home/oracle/scripts/rman/log

total 432

-rwxrwxrwx    1 oracle   dba               0 Jul 15 16:12 backup0.log

-rwxrwxrwx    1 oracle   dba               0 Jul 15 16:12 backup1.log

-rwxrwxrwx    1 oracle   dba               0 Jul 15 16:12 backup2.log

------------------------------------------------------------------------------------------------------------

RMAN-03009: failure of backup command on c1 channel at 10/02/201613:23:50

ORA-19504: failed to create file "+DATA/backup/rman_bak/oadb_20161002_03rhbq35_1_1_0.bak"

ORA-17502: ksfdcre:4 Failed to create file+DATA/backup/rman_bak/oadb_20161002_03rhbq35_1_1_0.bak

ORA-15173: entry 'backup' does not exist in directory '/'

 

0 0
原创粉丝点击