Tuesday 26 May 2020

Crontab -RMAN Backup scripts

  •  RMAN BACKUP Scripts

Crontab Details:

  • Scheduled scripts
05 04 * * * /u04/MasterDB/scripts/rman_DB_FULL.sh 2>&1 >>/u04/MasterDB/rmanbackup_PRODB/RMAN_PRODB_FULL.log

  • Rman Backup Status on Mail
35 06 * * * /u04/MasterDB/scripts/daily_health_check/rmanbackupstatus.sh


Scripts Details output :

  • RMAN SCRIPTS 

oracle@test02:~> cat /u04/MasterDB/scripts/rman_PRODB_FULL.sh

ORACLE_HOME=/u02/app/oracle/product/12.1.0/dbhome_1

DD=`date +%d%m%y`

export ORACLE_HOME

ORACLE_SID=PRODB

export ORACLE_SID

Rman_Log=/u04/MasterDB/scripts/"$ORACLE_SID"_bkp${DD}.log

touch $Rman_Log

/u02/app/oracle/product/12.1.0/dbhome_1/bin/rman target test/test1234 @/u04/MasterDB/scripts/rman_PRODB_FULL.rcv >> /u03/rmanbackup_PRODB/rman_RODB_FULL.log

oracle@test02:~>



oracle@test02:~> cat /u04/MasterDB/scripts/rman_PRODB_FULL.rcv

run

{

allocate channel c1 device type disk format '/u03/rmanbackup_SMRPRODB/Backup_%d_DB_%u_%s_%p_%T';

allocate channel c2 device type disk format '/u03/rmanbackup_SMRPRODB/Backup_%d_DB_%u_%s_%p_%T';

allocate channel c3 device type disk format '/u03/rmanbackup_SMRPRODB/Backup_%d_DB_%u_%s_%p_%T';

allocate channel c4 device type disk format '/u03/rmanbackup_SMRPRODB/Backup_%d_DB_%u_%s_%p_%T';

crosscheck backup;

crosscheck archivelog all;

report obsolete;

delete noprompt obsolete;

sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';

backup full database format '/u03/rmanbackup_PRODB/%d_%U.bckp' plus archivelog;

copy current controlfile to '/u03/rmanbackup_PRODB/control01_%d_%T_%U.bak';

backup current controlfile for standby format '/u03/rmanbackup_RODB/standbycontrol_%d_%T_%U.ctl';

release channel c1;

release channel c2;

release channel c3;

release channel c4;

}

oracle@test02:~>


  •  Rman Backup Status  

oracle@test02:~> cat /u04/MasterDB/scripts/daily_health_check/rmanbackupstatus.sh

. /home/oracle/.bash_profile

DR_log=/u04/MasterDB/scripts/daily_health_check/rmanbackupstatus.log

printf "to:varun.yadav@abc.com\n" > $DR_log

#printf "cc:abc@abccom,core@abc.com\n" >> $DR_log

printf "subject: SMRPRODB Database  RMAN Backup STATUS AND DETAILS " >> $DR_log



sqlplus -s "/as sysdba" <<EOF >> $DR_log



set lines 200

PROMPT DATABASE NAME

PROMPT =================

Select name,open_mode,database_role,db_unique_name from v\$database;



PROMPT RMAN backup and Size Details

PROMPT ==================================================

set lines 200

col START_TIME for a15

col END_TIME for a15

col TIME_TAKEN_DISPLAY for a10

col INPUT_BYTES_DISPLAY heading "DATA SIZE" for a10

col OUTPUT_BYTES_DISPLAY heading "Backup Size" for a11

col OUTPUT_BYTES_PER_SEC_DISPLAY heading "Speed/s" for a10

col output_device_type heading "Device_TYPE" for a11

SELECT to_char (start_time,'DD-MON-YY HH24:MI') START_TIME, to_char(end_time,'DD-MON-YY HH24:MI') END_TIME, time_taken_display, status,

input_type, output_device_type,input_bytes_display, output_bytes_display, output_bytes_per_sec_display ,COMPRESSION_RATIO

FROM v\$rman_backup_job_details

WHERE end_time > sysdate -3;

select ctime "Date"

        , decode(backup_type, 'L', 'Archive Log', 'D', 'Full', 'Incremental') backup_type

        , bsize "Size MB"

   from (select trunc(bp.completion_time) ctime

           , backup_type

           , round(sum(bp.bytes/1024/1024),2) bsize

      from v\$backup_set bs, v\$backup_piece bp

      where bs.set_stamp = bp.set_stamp

     and bs.set_count  = bp.set_count

     and bp.status = 'A'

     group by trunc(bp.completion_time), backup_type)

 order by 1, 2;

EOF

/usr/sbin/sendmail -t < $DR_log

oracle@test02:~>


Monday 25 May 2020

RMAN - Loss of the Password File Recovery example

Recovery from Loss of the Password File

  • Remove or move password file at OS level
suse1:/u01/app/oracle/product/12.1.0/dbhome_1/dbs # mv orapwplm orapwplm_pwd

  • Error during remote connection
oracle@suse1:/u01/app/oracle/product/12.1.0/dbhome_1/dbs> sqlplus sys/test@plm as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Mon May 25 13:48:35 2020

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

ERROR:
ORA-01017: invalid username/password; logon denied


Enter user-name:

  • Create password file at OS level.
orapwd file=/u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwplm password=test entries=5 format=12 


  • Login database again remotely
oracle@suse1:/u01/app/oracle/product/12.1.0/dbhome_1/dbs> sqlplus sys/test@plm as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sun May 24 11:43:24 2020

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Advanced Analytics
and Real Application Testing options

SQL> select name,open_mode,database_role from v$database;

NAME      OPEN_MODE            DATABASE_ROLE
--------- -------------------- ----------------
PLM       READ WRITE           PRIMARY



RMAN - ORA-19913: unable to decrypt backup ORA-28365: wallet is not open Restoring from a Password-encrypted Backupset

Restoring from a Password-encrypted Backupset

Scenario : 
We first encrypt rman setting then take backup after that restore backup . It will throw error and decrypt  again restore and recover.

Error:

RMAN-03002: failure of restore command at 05/24/2020 12:55:22
ORA-19870: error while restoring backup piece /u01/app/oracle/fast_recovery_area/PLM/backupset/2020_05_24/o1_mf_nnndf_ENCRYPTION_hdn89nxx_.bkp
ORA-19913: unable to decrypt backup
ORA-28365: wallet is not open

Solution:
  • Connect to the rman utility


oracle@suse1:/u01/app/oracle/product/12.1.0/dbhome_1/dbs> rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Sun May 24 12:53:23 2020

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PLM (DBID=1811128417)

  • Enable encryption on and set password

RMAN> SET ENCRYPTION ON IDENTIFIED BY Password ONLY; 

  • Backup Tablespace users from rman utility
RMAN> BACKUP TABLESPACE USERS TAG 'ENCRYPTION';

executing command: SET encryption
using target database control file instead of recovery catalog

Starting backup at 24-MAY-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=73 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/plm/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-MAY-20
channel ORA_DISK_1: finished piece 1 at 24-MAY-20
piece handle=/u01/app/oracle/fast_recovery_area/PLM/backupset/2020_05_24/o1_mf_nnndf_ENCRYPTION_hdn89nxx_.bkp tag=ENCRYPTION comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-MAY-20

RMAN> ALTER SYSTEM SWITCH LOGFILE;

Statement processed
  • Try to restore tablespace while encryption is ON
RMAN>
RESTORE TABLESPACE USERS;
RMAN>

Starting restore at 24-MAY-20
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/plm/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PLM/backupset/2020_05_24/o1_mf_nnndf_ENCRYPTION_hdn89nxx_.bkp
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 05/24/2020 12:55:22
ORA-19870: error while restoring backup piece /u01/app/oracle/fast_recovery_area/PLM/backupset/2020_05_24/o1_mf_nnndf_ENCRYPTION_hdn89nxx_.bkp
ORA-19913: unable to decrypt backup
ORA-28365: wallet is not open
  • Set decryption on rman setting 
RMAN> SET DECRYPTION IDENTIFIED BY Password;

executing command: SET decryption
  • Tablespace  users offline
RMAN> ALTER TABLESPACE USERS OFFLINE;

Statement processed
  • Restore tablespace users

RMAN> RESTORE TABLESPACE USERS;

Starting restore at 24-MAY-20
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/plm/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PLM/backupset/2020_05_24/o1_mf_nnndf_ENCRYPTION_hdn89nxx_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PLM/backupset/2020_05_24/o1_mf_nnndf_ENCRYPTION_hdn89nxx_.bkp tag=ENCRYPTION
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 24-MAY-20
  • Recover tablespace users 
RMAN> RECOVER TABLESPACE USERS;

Starting recover at 24-MAY-20
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 24-MAY-20

  • Tablespace online
RMAN> ALTER TABLESPACE USERS ONLINE;

Statement processed

RMAN>