Linux下先确认输入rman时,执行是那个bash
find / -name rman (根目录下rman名称的文件)
su -oracle
echo $PATH
vi ./.bash_profile (调整顺序为 PATH=$PATH:$HOME/bin)
确认为归档模式
sqlplus /nolog
conn /as sysdba
archive log list
alter system set log_archive_start=true scope=spfile; (设置自动归档)
[oracle@CentOS6 ~]$ rman nocatalog
RMAN> connect target /(或者RMAN> connect target sys/samis.com@poli)
RMAN> list backupset;
RMAN> backup database;(全备份)
----------------------------------------------------------------
[oracle@CentOS6 ~]$ cd /u01/oracle/oradata/poli/
[oracle@CentOS6 ~]$ strings control01.ctl (查看控制文件内容)
RMAN> backup incremental level=0 database; (0级备份)
RMAN> backup incremental level 1 database; (1级备份)
RMAN> list backupset;
----------------------------------------------------------------
备份归档日记archivelog
RMAN> backup database plus archivelog delete input;(备份了所有文件,参数/控制/数据/归档,并删除已备份的归档日记文件)
RMAN> show all;
RMAN> report schema; (查看表空间)
RMAN> backup tablespace tbs01
备份控制文件,两种方式:
RMAN> backup current controlfile (单独备份)
RMAN> backup database include current controlfile (备份数据库的时候包含控制文件)
备份集: backupset
镜像备份:image copies
RMAN> report schema; (查看表空间对应的编号)
RMAN> copy datafile 5 to '/u01/oracle/oradata/poli/tbs01.dbf';
RMAN> list copy; (查看镜像备份)
----------------------------------------------------------------
单命令
RMAN> backup database;
批命令
RMAN> run {
allocate channel cha1 type disk;
backup format "/u01/rmanbak/full_%t"
tag full_backup_bak
database;
release channel cha1;
}
%t:备份集时间戳
%T:年月日格式(YYYYMMDD)
%d:数据库的名称
%D:位于该月中的天数(DD)
%M:位于该月中的月份(MM)
----------------------------------------------------------------
自动备份:备份脚本+crontab
创建脚本
[oracle@CentOS6 ~]$ vi bakl0
RMAN> run {
allocate channel c1 type disk;
backup incremental level 0
format "/u01/rmanbak/inc0_%u_%T"
tag monday_inc0
database;
release channel cha1;
}
[oracle@CentOS6 ~]$ cp bakl0 bakl1
[oracle@CentOS6 ~]$ cp bakl0 bakl2
[oracle@CentOS6 ~]$ vi bakl1
[root@CentOS6 ~]$ crontab -e -u oracle
45 23 * * 0 rman target / msglog=/u01/rmanbak/bakl0.log cmdfile=/u01/rmanbak/script/bakl0 (从右到左,星期/月/日/时/分 23:45分)
45 23 * * 1 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
45 23 * * 2 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
45 23 * * 3 rman target / msglog=/u01/rmanbak/bakl1.log cmdfile=/u01/rmanbak/script/bakl1 (1级)
45 23 * * 4 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2 (2级)
45 23 * * 5 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
45 23 * * 6 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
----------------------------------------------------------------
# connected to target database: POLI (DBID=3742422830)
RMAN> rman target / (记下dbid,以后恢复spfile或者controlfile时候需要)
RMAN> configure controlfile autobackup on; (自动备份controlfile)
RMAN> show all;
RMAN> list backup;
RMAN> delete backupset 24; (删除备份编号)
推荐阅读:
RMAN 配置归档日志删除策略
Oracle基础教程之通过RMAN复制数据库
RMAN备份策略制定参考内容
RMAN备份学习笔记
Oracle数据库备份加密 RMAN加密