Oracle-Rman数据备份

时间:2021-02-23
本文章向大家介绍Oracle-Rman数据备份,主要包括Oracle-Rman数据备份使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1、Linux系统下备份

开启归档日志

linux 启动归档日志
    SQL> SHUTDOWN IMMEDIATE;
    SQL> STARTUP MOUNT;
    mkdir -p /u01/arch
    SQL> alter system set log_archive_dest_1='location=/u01/arch';
    SQL> alter database archivelog;
    SQL> alter database open;
    SQL> archive log list;
View Code

bak0.sh  增量每天一次备份

#!/bin/bash
source ~/.bash_profile
/u01/oracle/product/11.2.0/db_1/bin/rman target / nocatalog log /orabak/logs/bak0_`date +%Y%m%d`.log  <<EOF
run{
crosscheck backup;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
backup as compressed backupset database format '/orabak/db0_%d_%T_%U.bak' plus archivelog format '/orabak/ar0_%d_%T_%U.bak';
backup current controlfile format '/orabak/control0_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
delete archivelog all completed before 'sysdate - 1';
release channel c1; 
}
EOF
exit
View Code

bak1.sh  每周一次全备

#!/bin/bash
source ~/.bash_profile
/u01/oracle/product/11.2.0/db_1/bin/rman target / nocatalog log /orabak/logs/bak1_`date +%Y%m%d`.log  <<EOF
run{
crosscheck backup;
delete obsolete;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
allocate channel c6 device type disk;
allocate channel c7 device type disk;
allocate channel c8 device type disk;
backup as compressed backupset incremental level 1 database format '/orabak/db1_%d_%T_%U.bak';
sql 'alter system archive log current';  
backup as compressed backupset archivelog all format '/orabak/ar1_%d_%T_%U.bak'  delete all input;
backup current controlfile format '/orabak/control1_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete archivelog all completed before 'sysdate - 1';
delete noprompt expired backup device type disk;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}
EOF
exit
View Code

2、window系统下备份

开启归档日志

win 启动归档日志
    SQL> SHUTDOWN IMMEDIATE;
    SQL> STARTUP MOUNT;
    SQL> alter system set log_archive_dest_1='location=E:\rman_bak';
    SQL> alter database archivelog;
    SQL> alter database open;
    SQL> archive log list;
View Code

bak0.txt  增量每天一次备份

run{
crosscheck backup;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
backup as compressed backupset database format 'E:\orabak\db0_%d_%T_%U.bak' plus archivelog format 'E:\orabak\ar0_%d_%T_%U.bak';
backup current controlfile format 'E:\orabak\control0_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
delete archivelog all completed before 'sysdate - 1';
release channel c1; 
}
exit
View Code

bak01.bat  启动备份

View Code

 bak11.txt  每周一次全备

run{
crosscheck backup;
delete obsolete;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
allocate channel c6 device type disk;
allocate channel c7 device type disk;
allocate channel c8 device type disk;
backup as compressed backupset incremental level 1 database format 'E:\orabak\db1_%d_%T_%U.bak';
sql 'alter system archive log current';  
backup as compressed backupset archivelog all format 'E:\orabak\ar1_%d_%T_%U.bak'  delete all input;
backup current controlfile format 'E:\orabak\control1_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete archivelog all completed before 'sysdate - 1';
delete noprompt expired backup device type disk;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}
exit
View Code

bak1.bat  启动备份

rman target SYSTEM/Fsdd20200508@FSSPDB cmdfile 'E:\servers\bak11.txt' log 'E:\orabak\logs\bak1_`date +%Y%m%d`.log'
View Code

添加定时任务、备份日志

  在cmd下输入taskschd.msc---》右击任务计划程序库,创建基本任务逐步操作

温馨提示:本文由自己记录,仅作参考,出了问题概不负责。。。。。

原文地址:https://www.cnblogs.com/zhj5418/p/14437521.html