Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle Automated backup script

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Oracle daily RMAN backup script, very basic. However, for multiple Oracle databases that need to be backed up, it can be easily implemented and facilitate the query of batch status in the later period.

Backup script, which needs to be modified appropriately based on the linux,windows environment.

The main script, which will call the rman.sql&status.sql of step 2 and step 3

$more main.sh#set env#Change the below parameter for the different server#export host_ip=172.16.32.115export instance_name=liangexport username=liangexport password=liangexport syspsw=oracleexport backup_home=/home/oracle/bkexport ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1export PATH=$PATH:$ORACLE_HOME/db_1/bin:/ Sbin:/usr/sbin#export curTime=$ (date "+% Y%m%d") mkdir $backup_home/ftp/$curTimeecho "- -RMAN start-- " Date#backup startcd $backup_home$ORACLE_HOME/bin/rman target sys/$syspsw@$host_ip:1521/$instance_name cmdfile='rman.sql'echo "--RMAN End--" Datesleep 10echo "--SQL Start--" Date$ORACLE_HOME/bin/sqlplus $username/$password@$host_ip:1521/$instance_name @ status.sqlecho "- END--"; date

RMAN backup sql script

[oracle@test bk] $more rman.sqlrun {ALLOCATE CHANNEL node_c1 DEVICE TYPE DISK MAXPIECESIZE=5G;ALLOCATE CHANNEL node_c2 DEVICE TYPE DISK MAXPIECESIZE=5G;backup as compressed backupset database format'C:\ ftp\ uploadfile\ db_%U.bak_%T';sql 'alter system switch logfile';CROSSCHECK ARCHIVELOG ALL;backup as compressed backupset archivelog all format' C:\ ftp\ uploadfile\ archivelog_%d_%s_%p_%T' not backed up 2 times;backup spfile format'C:\ ftp\ uploadfile\ spfile_%U_%T' Backup current controlfile format'C:\ ftp\ uploadfile\ controlfile_%d_%s_%p_%I_%u_%T';sql 'alter system switch logfile';CROSSCHECK BACKUP;CROSSCHECK COPY;delete noprompt archivelog all completed before' sysdate-7';release channel node_c1;release channel node_c2;} script to query the backup status and print the query information to the log for easy query. Daily archive output of $more status.sql----, which can be used to determine whether the database is busy spool $backup_home/redo_switch.log Set echo offset feedback offset colsep', 'set pagesize 2000set term offset heading offset line 400col Count for 9999col GB for 99999selectd.dbiddandreparing totalchar (trunc (completion_time),' yyyy-mm-dd') as "Date", count (*) as "Count", substr ((sum (blocks*block_size)) / 1024Count) as "GB" from vested archivedlogrecoverable database dgroup by trunc (completion_time), d.dbidskspool off;--- query tablespace usage spool $backup_home/tablepace_usage.log Set echo offset feedback offset colsep', 'set pagesize 2000set term offset heading offset line 400col startup_time for a20col status for a6col tablespace_name for a20col total_mb for 99999999col used_mb for 99999999col used_pct for a10 selectd.dbidder as Used_MB as Used_MB (total.MB-free.MB, 2) as Total_MB,round (total.MB-free.MB, 2) Round ((1-free.MB / total.MB) * 100,2) | |%'as Used_Pctfrom (select tablespace_name, sum (bytes) / 1024 / 1024 as MBfrom dba_free_spacegroup by tablespace_name) free, (select tablespace_name, sum (bytes) / 1024 / 1024 as MBfrom dba_data_filesgroup by tablespace_name) total, v$instance b, v$database dwhere free.tablespace_name = total.tablespace_name Spool off;--- checks backups in the last 7 days spool / home/oracle/bk/log/rman.log Set echo offset feedback offset colsep', 'set pagesize 2000set term offset heading offset line 202000col DBID for 9999999999col status for a25col type for a12col start_time for a22col Finish_time for a22col in_sec for a12col out_sec for a12col command for a8col INPUT_M for 99999col OUTPUT_M for 99999col obj_type for a15select d.DBID as DBID,s.status as status,b.INPUT_TYPE as type,to_char (b.STARTROTIMEMMMMMMAIDD hh34:mi:ss') as start_time,to_char (b.end_time 'yyyy-mm-dd hh34:mi:ss') as Finish_time,b.INPUT_BYTES_PER_SEC_DISPLAY in_sec,b.OUTPUT_BYTES_PER_SEC_DISPLAY out_sec,s.OPERATION as command,trunc (s.INPUTIX BYTES pick 1024ppt 2) as INPUT_M,trunc (s.OUTPUTIX BYTES pencils 1024pence1024BYTES2) as OUTPUT_M,s.OBJECT_TYPE as obj_typefrom v$rman_status srecinct vainrmancy backupdated jobless details b, v$database dwhere to_char (s.START_TIME) 'yyyy-mm-dd hh34:mi:ss')

< to_char(sysdate,'yyyy-mm-dd hh34:mi:ss')and to_char(s.END_TIME, 'yyyy-mm-dd hh34:mi:ss') >

To_char (sysdate-7,'yyyy-mm-dd hh34:mi:ss') and s.COMMAND_ID=b.COMMAND_IDorder by s.START_TIME desc; spool off;exit

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report