背景
rman,听这名字,好像有点真的男人意思。这玩意其实也简单,只是老忘,作为一个oracle dba爱好者,怎么少了rman呢,这个好像是oracle体系的最后一环,把它掌握了,就完成oracle的闭环了。我是这么认为的。下面是我整理的知识点,其实主要是就是备份,一个文件,定时执行;一个是恢复,两个命令而已。
内容
- 每周日1点数据库全备
- 每天8点备份归档
[ora11204
- 全备脚本:vi backup.sh
#!/bin/bash
#ENV
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
#backup RMAN
if [ ! -d "$1" ]; then
echo "You have input no dir for $1"
exit 1
fi
echo "=================================================================================" >>${1}/backup_full.log
echo "Begin backup at : `date`" >> ${1}/backup_full.log
rman target / <<EOF >> ${1}/backup_full.log
run {
CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
backup as compressed backupset database format '${1}/FULLBAK_%d_%T_%s_%p.DBFILE';
backup current controlfile format '${1}/%d.%s.%p.%T.CTL';
backup spfile format '${1}/%d.%s.%p.%T.SPFILE';
crosscheck backup;
crosscheck copy;
sql "alter system archive log current";
backup as COMPRESSED backupset archivelog all not backed up format '${1}/%d.%s.%p.%T.ARC';
crosscheck archivelog all;
delete noprompt archivelog all completed before 'sysdate-10';
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF
echo "End backup at : `date`" >>${1}/backup_full.log
echo "Begin scp at : `date`" >>${1}/backup_full.log
scp ${1}/*`date +%Y%m%d`* oracle@192.168.1.61:/tmp/
echo "End scp at : `date`" >>${1}/backup_full.log
echo "=================================================================================" >>${1}/backup_full.log
exit 0
- 归档备份脚本:vi backuparch.sh
这里只是去掉全备的命令,其他保留。
#!/bin/bash
#ENV
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
#backup RMAN
if [ ! -d "$1" ]; then
echo "You have input no dir for $1"
exit 1
fi
echo "=================================================================================" >>${1}/backup_arch.log
echo "Begin backup at : `date`" >> ${1}/backup_arch.log
rman target / <<EOF >> ${1}/backup_arch.log
run {
CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
backup current controlfile format '${1}/%d.%s.%p.%T.CTL';
backup spfile format '${1}/%d.%s.%p.%T.SPFILE';
crosscheck backup;
crosscheck copy;
sql "alter system archive log current";
backup as COMPRESSED backupset archivelog all not backed up format '${1}/%d.%s.%p.%T.ARC';
crosscheck archivelog all;
delete noprompt archivelog all completed before 'sysdate-10';
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF
echo "End backup at : `date`" >>${1}/backup_arch.log
echo "Begin scp at : `date`" >>${1}/backup_arch.log
scp ${1}/*`date +%Y%m%d`*.{CTL,SPFILE,ARC} oracle@192.168.1.61:/tmp/
echo "End scp at : `date`" >>${1}/backup_arch.log
echo "=================================================================================" >>${1}/backup_arch.log
exit 0
参数文件:
$ strings ORCL.24.1.20180619.SPFILE
[oracle@jystdrac1 orcl]$ pwd
/u01/oradata/orcl
[oracle@jystdrac1 orcl]$ vi pfile.ora
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/oradata/orcl/control01.ctl','/u01/oradata/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_dest_1='LOCATION=/u01/arch'
*.memory_target=1234173952
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
SQL> startup nomount pfile='/u01/oradata/orcl/pfile.ora';
ORACLE instance started.
控制文件:
RMAN> restore controlfile from '/tmp/ORCL.23.1.20180619.CTL';
RMAN> alter database mount;
RMAN> catalog start with '/tmp/';
RMAN> crosscheck backup;
转储文件并恢复到指定时间点:
RMAN> restore database;
RMAN> sql "alter session set nls_date_format=''yyyy-mm-dd hh24:mi:ss''";
RMAN> recover database until time '2018-06-19 17:50:00';
--先只读打开确认数据是否符合要求
SQL> alter database open read only;
--确认没问题后重新以resetlogs方式打开
SQL> create spfile from pfile='/u01/oradata/orcl/pfile.ora';
SQL> startup mount
SQL> alter database open resetlogs;