RMAN Backup Using Shell Script
RMAN Backup Using Shell Script
REQUIREMENT:
Configure shell script to take rman Full backup .
SCRIPT: ( rman_full_bkp.sh)
1
2
3 # $Header: rman_full_bkp.sh
4 # *====================================================================================+
5 # | Author - DBACLASS ADMIN TEAM
6 # | |
7 # +====================================================================================+
8 #|
9 # | DESCRIPTION
10 # | Take rman full backup(incremental level 0 )
11 # | PLATFORM
12 # | Linux/Solaris/HP-UX
13
14 # +===========================================================================+
15 #!/bin/bash
16 RMANBACKUP_MOUNTPOINT1=/u01/oracle/rman_bkp
17 PARALLELISM=4
18 MAXPIECESIZE=3g
19 export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
20 export ORACLE_SID=TESTDB
21 export PATH=$ORACLE_HOME/bin:$PATH
22
23 fullBackup () {
24 rman log=/u01/oracle/rman_bkp/LOG/RMANFULLincr.log << EOF
25 connect target /
26 set echo on;
27 configure backup optimization on;
28 configure controlfile autobackup on;
29 configure controlfile autobackup format for device type disk to '$RMANBACKUP_MOUNTPOINT1/%F';
30 configure maxsetsize to unlimited;
31 configure device type disk parallelism $PARALLELISM;
32 run
33 {
34 allocate channel c1 type disk format '${RMANBACKUP_MOUNTPOINT1}/%I-%Y%M%D-%U' maxpiecesize ${MAXPIECESIZE};
35 allocate channel c2 type disk format '${RMANBACKUP_MOUNTPOINT1}/%I-%Y%M%D-%U' maxpiecesize ${MAXPIECESIZE};
36 allocate channel c3 type disk format '${RMANBACKUP_MOUNTPOINT1}/%I-%Y%M%D-%U' maxpiecesize ${MAXPIECESIZE};
37 allocate channel c4 type disk format '${RMANBACKUP_MOUNTPOINT1}/%I-%Y%M%D-%U' maxpiecesize ${MAXPIECESIZE};
38 backup as compressed backupset incremental level 0 check logical database plus archivelog;
39 release channel c1 ;
40 release channel c2 ;
41 release channel c3 ;
42 release channel c4 ;
43 }
44 configure backup optimization clear;
45 configure controlfile autobackup clear;
46 sql 'alter system archive log current';
47 exit
48 EOF
49 }
50
51 # Main
52
53 fullBackup
54
Give 755 permission
1
2
3 chmod 755 rman_full_bkp.sh
4
Configure script in crontab:
1
2
3 00 22 * * * "/u01/app/oracle/rman_full_bkp.sh" > /tmp/rmanarch.log
4
Shell script to monitor asm diskgroup usage
REQUIREMENT: Write a shell script, which will trigger a mail alert, if the utilization of the asm diskgroup reached 90 percent. SOLUTION: 1. Below is the shell script. Make
sure to update ORACLE_HOME, ORACLE_SID inside the shell script. cat /export/home/oracle/asm_dg.sh
1
2
3 export ORACLE_HOME=/oracle/app/oracle/product/12.1.0.2/dbhome_1
4 export ORACLE_SID=PRODDB1
5 export PATH=$ORACLE_HOME/bin:$PATH
6 logfile=/export/home/oracle/asm_dg.log
11 COLUMN group_name
19
25 spool off
26 exit
27 EOF
29 #echo $count
30 if [ $count -ge 4 ];
31 then
33 fi
34
1
2
3. Configure in crontab:
1
2
3 0,15,30,45 * * * * /export/home/oracle/asm_dg.sh
4
1
2
4
5 Audit succeeded.
6
2. Final shell script Below script for any invalid login attempts in last 15 minutes. cat /export/home/oracle/invalid_log.sh
1
2
3 export ORACLE_HOME=/oracle/app/oracle/product/12.1.0/dbhome_1
4 export ORACLE_SID=SBIP18DB
5 export PATH=$ORACLE_HOME/bin:$PATH
6 logfile=/export/home/oracle/test.log
8 spool $logfile
16 CASE
21 spool off
22 exit
23 EOF
25 #echo $count
26 if [ $count -ge 4 ];
27 then
29 fi
30
3. provide […]
1
2
3 #!/bin/sh
4
5 df -h | egrep -v '/system|/platform|/dev|/etc|lib' | awk '{print $6 " " $5}'|cut -d% -f1|while read fs val
6
7 do
8
9 if [ $val -ge 90 ]
10 then
11 echo "The $fs usage high $val% \n \n \n `df -h $fs`" | mailx -s "Filesystem $fs Usage high on Server `hostname`" support@dbaclass.com
12
13 fi
14 done
15
Put in crontab:
1
2
3 00 * * * * /usr/local/scripts/diskalert.sh
4
1
2
3 zpool list | awk '{print $5}'| grep -v CAP | cut -d% -f1| while read val
4
5 do
6
7 if [ $val -ge 80 ]
8 then
9 echo "The $fs usage high $val% \n \n \n `df -h $fs`" | mailx -s "Filesystem $fs Usage high on Server `hostname`" rpatro.c@stc.com.a
10
11 fi
12 done
13
1
2
3 00 * * * * /usr/local/scripts/zpoolusage.sh
4
Day by day, alert log size will grow in Oracle database. So for housekeeping, we need to move the existing alert log to a backup location and
compress there. Upon moving the alert log, the database will create a fresh alert log automatically.
2
3 # $Header: rotatealertlog.sh
4 # *====================================================================================+
6 # | |
7 # +====================================================================================+
8 #|
9 #!/bin/bash
10 echo ========================
12 echo ========================
13
15 ORACLE_HOME=/oracle/app/oracle/product/12.1.0.2/dbhome_1
18 PATH=$ORACLE_HOME/bin:$PATH;export PATH
20
21 echo =======
23 echo =======
25 else
27 fi
28
29 exit
30
2. Configure in crontab:
SCHEDULE – Weekly once
Here, we have passed the ORACLE_SID (PRODDB) as argument
1
2
3 00 22 * * 5 /u01/app/oracle/dbscripts/rotatealertlog.sh PRODDB
4
1. First, make the below .sql file, which will be used inside the shell script.
In this script we have defined the threshold as 90%. You can change it as per your requirement.
1
2
3 cat /export/home/oracle/Housekeeping/scripts/tablespace_alert.sql
4
5
6
10 set head on
22 WITH tbs_auto AS
29 FROM dba_data_files
30 GROUP BY tablespace_name),
31 fragments AS
35 FROM dba_free_space
36 GROUP BY tablespace_name),
37 AUTOEXTEND AS
40 FROM dba_data_files
42 GROUP BY tablespace_name
43 UNION
45 FROM dba_data_files
47 GROUP BY tablespace_name)
48 GROUP BY tablespace_name)
51 WHEN 'YES'
53 ELSE 'NO'
58 ) total_used_space,
61 / files.total_tbs_bytes
62 )
63 * 100
64 )) total_used_pct,
73 order by total_free_pct;
74
1
2
3 cat /export/home/oracle/Housekeeping/scripts/tablespace_threshold.ksh
4
5
6
7 #!/bin/sh
8 export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
9 export PATH=$ORACLE_HOME/bin:$PATH
10 export LD_LIBRARY_PATH=$ORACLE_HOME/lib
11 export ORACLE_SID=PRODDB
12 cd /export/home/oracle/Housekeeping/scripts
13 logfile=/export/home/oracle/Housekeeping/scripts/Tablespace_alert.log
15 if [ $cnt1 -eq 1 ];
16 then
18 spool $logfile
19 @/export/home/oracle/Housekeeping/scripts/tablespace_alert.sql
20 spool off
21 exit
22 EOF
23 # If there are more then these two lines in the output file, mail it.
25 #echo $count
26 if [ $count -ge 4 ];
27 then
30 fi
31
2
4
SCRIPT:(Adrci_alert_log.ksh)
1
2
3 ###########################################################################################
6 ###########################################################################################
7
8 LOG_DIR=/export/home/oracle/Housekeeping/logs/alert_log_check_daily.txt
11 echo '###########################################ALERT LOG OUTPUT FOR LAST 15 MINUTES ###########################' >> $LOG_DIR
13
15 do
16
22 adrci exec="set home ${adrci_home}; show alert -p \\\"message_text like '%ORA-%' and originating_timestamp > systimestamp-1/96\\\"" -term >> $LOG_DIR
23
24 done
26 if [ $num_errors != 0 ]
27 then
28
29 mailx -s "ORA- error found in alert Log of the server " support@dbaclass.com <$LOG_DIR
30
31 fi
32
2
3 chmod 755 Adrci_alert_log.ksh
4
2
4
1
2
3 # $Header: rman_full_bkp.sh
4 # *====================================================================================+
6 # | |
7 # +====================================================================================+
8 #|
9 # | DESCRIPTION
11 # | PLATFORM
12 # | Linux/Solaris/HP-UX
13
14 # +===========================================================================+
15 #!/bin/bash
16 RMANBACKUP_MOUNTPOINT1=/u01/oracle/rman_bkp
17 PARALLELISM=4
18 MAXPIECESIZE=3g
19 export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
20 export ORACLE_SID=TESTDB
21 export PATH=$ORACLE_HOME/bin:$PATH
22
23 fullBackup () {
25 connect target /
32 run
33 {
38 backup as compressed backupset incremental level 0 check logical database plus archivelog;
39 release channel c1 ;
40 release channel c2 ;
41 release channel c3 ;
42 release channel c4 ;
43 }
47 exit
48 EOF
49 }
50
51 # Main
52
53 fullBackup
54
1
2
4
1
2
For taking incremental backup,Just update the backup command with the below one. backup as compressed backupset incremental level 1 check logical database plus
archivelog;
1
2
3 # $Header: kill_snipped.sh
4 # *====================================================================================+
6 # | |
7 # +====================================================================================+
8 #|
9 # | DESCRIPTION
11 # | PLATFORM
12 # | Linux/Solaris/HP-UX
13
14 # +===========================================================================+
15 #!/usr/bin/ksh
16 export ORACLE_HOME=/oracle/app/oracle/product/12.1.0.2/dbhome_1
17 export PATH=$ORACLE_HOME/bin:$PATH
18 export ORACLE_SID=TESTDB
19 export LOG_PATH=/export/home/oracle/testdb/LOG
20 rm -f $LOG_PATH/snip_kill.sql
21
23 connect system/oracle
30 spool off;
33 set pages 0;
34 spool $LOG_PATH/snip_kill.sql
35 select 'alter system kill session '''||sid||','||serial#||''' immediate;' from v\$session where status='SNIPED' ;
36 spool off;
37 @"$LOG_PATH/snip_kill.sql"
38 exit;
39 !
40 date
41
1
2
4
Configure in crontab:
1
2
4
1 # $Header: EXP_TAB_cmprss.sh
2 # *====================================================================================+
4 # | |
5 # +====================================================================================+
6 #|
7 # | FILENAME
8 # | EXP_table_bkp_cmprss_dbaclass.sh
9 #|
10 # | DESCRIPTION
12 # | PLATFORM
13 # | Linux/Solaris
14
15 # +===========================================================================+
16 #!/bin/bash
18 export ORACLE_SID=$1
19 export ORACLE_HOME=/oracle/app/oracle/product/12.1.0/dbhome_1
20 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
21 export PATH=$ORACLE_HOME/bin:$PATH:/usr/local/bin
23 export EXP_DIR=/export/home/oracle
24
25
echo =======
26
echo =======
28
echo $ORACLE_HOME
29
31
32
echo SEND MAIL TO STAKE HOLDERS
33
echo =======
34
mailx -s "$ORACLE_SID $TIMESTAMP Export backup logfile" support@dbaclass.com < $EXP_DIR/expdp_log_${TIMESTAMP}.log
35
echo Export completed at $TIMESTAMP
36
exit
37
38
1
2
4
1
2
3 00 15 * * * /export/home/oracle/EXP_TAB_cmprss.sh TESTDB
4