Pages

Showing posts with label RMAN. Show all posts
Showing posts with label RMAN. Show all posts

Thursday, January 25, 2024

RMAN-06091 no channel allocated for maintenance

Issue
During rman backup, there is an error:
RMAN-00571: ==============================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS 
RMAN-00571: ==============================================
RMAN-03002: failure of delete command at 18/01/2021 22:04:21
RMAN-06091: no channel allocated for maintenance (of an appropriate type)

The error is coming from delete obsolete archive logs and backups.

Solution

A way to see expired backups
RMAN> CROSSCHECK BACKUP;
RMAN> DELETE EXPIRED BACKUP;
Are you sure? YES

In case of disk backup:
To delete obsolete backup sets :
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE TYPE DISK;
To delete obsolete:
RMAN> CROSSCHECK ARCHIVELOG ALL;
RMAN> DELETE OBSOLETE DEVICE TYPE DISK; 

To delete expired:
RMAN> DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
RMAN> DELETE NOPROMPT EXPIRED BACKUPSET;


In case of SBT backup:
To delete obsolete backup sets of SBT type:
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE TYPE SBT;
RMAN> CROSSCHECK ARCHIVELOG ALL;
RMAN> DELETE OBSOLETE DEVICE TYPE SBT; 


But this step failed!
allocate channel for maintenance device type 'SBT_TAPE'; 
ORA-27211 Failed to load media management library

Note:
I failed to understand how SBT type backup pieces were created on the system in the first place.
All the scheduled scripts work only with DISK type!
All the SBT type backup pieces were expired.
Seems they were created, but then failed to be deleted with the default script that uses DISK type.
To delete them manually, I had to allocate a dummy path, to be able to delete the SBT type backupsets.

--This will allow to work with SBT type
allocate channel for maintenance device type sbt parms 'SBT_LIBRARY=oracle.disksbt, ENV=(BACKUP_DIR=/tmp)';

--This will give list of all backupsets
LIST BACKUPSET;

--This will give info for backupsets 8840
LIST BACKUPSET 8840;

The output gives:
Backupset 8840 is a SBT_TYPE, and it has no backuppieces.

--It will mark it as EXPIRED, and now it can be deleted
CROSSCHECK BACKUPSET 8840;

--Delete the backupset without the "YES" approval
DELETE NOPROMPT BACKUPSET 8840;


==========================================
crontab task to delete old SBT and Disk backups
==========================================

/backup/ora_online/scripts/rnam_del_old_backups.sh
#!/bin/bash

./etc/profile > /dev/null 2>/dev/null
./etc/sh/orash/oracle_login.sh igt
. $BACKUP_ROOT/internal/backupFunctions.sh

WORK_DIR=/backup/ora_online/scripts
LOGFILE=/backup/ora_online/scripts/rman_del_old_backups.log

write_to_log() {
 echo $1
 echo $1 >> $LOGFILE
}

#main()
RUN_DATE=`date +"%Y%m%d"_"%H%M%S"`
write_to_log " "
write_to_log "============================="
write_to_log "Running at $RUN_DATE"
write_to_log "============================="

write_to_log "Starting Clean SBT Backups"
rman target / << zZ >> $LOGFILE
allocate channel for maintenance device type SBT_TAPE PARMS 'SBT_LIBRARY=oracle.disksbt, ENV=(BACKUP_DIR=/tmp)';
LIST BACKUPSET;
CROSSCHECK BACKUPSE;
DELETE NOPROMPT EXPIRED BACKUPSET;
RELEASE CHANNEL;
EXIT;
zZ

write_to_log "Starting Clean Disk Backups"
rman target / << zZ >> $LOGFILE
allocate channel for maintenance device type disk;
DELETE NOPROMPT ACRHIVELOG ALL BACKED UP 1 TIMES TO DEVICE TYPE DISK;
DELETE NOPROMPT COPY OF ACRHIVELOG ALL COMPLETED BEFORE 'SYSDATE-2';
DELETE NOPROMPT OBSOLETE REDUNDANCE = 1;
RELEASE CHANNEL;
EXIT;
zZ

write_to_log "Finished Clean Backups"



crontab task to delete old directories

/backup/ora_online/scripts/clean_old_backups.sh
#!/bin/bash

WORK_DIR=/backup/ora_online/scripts
BACKUP_DIR=/backup/ora_online
TARGET_DIR=/backup/ora_online/for_backup
LOGFILE=${WORK_DIR}/clean_old_backups.log

write_to_log() {
 echo $1
 echo $1 >> $LOGFILE
}

#main()
RUN_DATE=`date +"%Y%m%d"_"%H%M%S"`
write_to_log " "
write_to_log "============================="
write_to_log "Running at $RUN_DATE"
write_to_log "============================="

for d in `find /backup/ora_online -maxdepth 1 -type d -name "20*"`
do
 write_to_log "Handling Directory $d"
 mv $d ${TARGET_DIR}/
done

directories=`ls -1 ${TARGET_DIR} | grep 20 | wc -l`
while [[ $directories -gt 2 ]];
do
 del_dir=`ls -1 ${TARGET_DIR} | grep 20 | sort | head -1`
 write_to_log "Deleting Directory ${TARGET_DIR}/$del_dir"
 rm -r ${TARGET_DIR}/$del_dir
 directories=`ls -1 ${TARGET_DIR} | grep 20 | wc -l`
done

Monday, November 14, 2022

RMAN ORA-27037: unable to obtain file status

===============
General
===============
After running RMAN, archive files are not deleted
In RMAN log, there is an error:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 11/14/2022 15:00:44
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability
ORA-19625: error identifying file /oracle_db/db1/db_igt/arch/arch0001_2710_1084024359.arc
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7

===============
General
===============
The solution would be to :

rman  target / 
crosscheck archivelog all;
delete expired archivelog all;

===============
Example
===============

rman target /

RMAN> LIST EXPIRED ARCHIVELOG ALL; specification does not match any archived log in the recovery catalog 

RMAN> LIST ARCHIVELOG ALL;
A list of archive several days old is listed.


Now run RMAN backup

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 09/11/2017 17:12:54
RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
ORA-19625: error identifying file /oracle_db/db2/db_igt/arch/arch0001_100463_669127092.arc
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


This was because some arch files were already deleted.

CROSSCHECK ARCHIVELOG ALL;
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101016_669127092.arc RECID=101005 STAMP=954426612
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101017_669127092.arc RECID=101006 STAMP=954428414
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101018_669127092.arc RECID=101007 STAMP=954430213
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101019_669127092.arc RECID=101008 STAMP=954432013
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101020_669127092.arc RECID=101009 STAMP=954433815
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101021_669127092.arc RECID=101010 STAMP=954435614
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101022_669127092.arc RECID=101011 STAMP=954436373
Crosschecked 560 objects

LIST EXPIRED ARCHIVELOG ALL;  
Now many files are listed
100806  1    100817  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100817_669127092.arc

100807  1    100818  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100818_669127092.arc

100808  1    100819  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100819_669127092.arc

100809  1    100820  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100820_669127092.arc


DELETE EXPIRED ARCHIVELOG ALL;  
Many files are deleted, some are kept
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100816_669127092.arc thread=1 sequence=100816
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100817_669127092.arc thread=1 sequence=100817
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100818_669127092.arc thread=1 sequence=100818
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100819_669127092.arc thread=1 sequence=100819
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100820_669127092.arc thread=1 sequence=100820


Now run RMAN backup again

./rman target / log=/backup/ora_online/logs/$1_backup_$DATE.log << EOF sql 'alter system archive log current'; run { allocate channel C1 type disk; allocate channel C2 type disk; backup AS COMPRESSED BACKUPSET tag whole_database_open format '/backup/ora_online/$1/$1_$DATE/db_%T_%t_s%s_p%p.bak' (DATABASE); BACKUP format '/backup/ora_online/$1/$1_$DATE/AR_%d_%s_%p.bak' TAG 'Arch_backup' ARCHIVELOG ALL NOT BACKED UP DELETE ALL INPUT; #BACKUP format '/backup/ora_online/$1/$1_$DATE/AR_%d_%s_%p.bak' TAG 'Arch_backup' ARCHIVELOG ALL; backup current controlfile format '/backup/ora_online/$1/$1_$DATE/cntc_%T_%t_s%s_p%p'; release channel C1; release channel C2; } crosscheck archivelog all; crosscheck backup; delete noprompt obsolete; EOF

or
run { configure controlfile autobackup on; configure backup optimization on; set controlfile autobackup format for device type disk to '/backup/ora_online/20170911_1718/%F'; allocate channel 'dev_0' type disk format = '/backup/ora_online/20170911_1718/dbf_%d_%T_%U'; backup full database; backup archivelog from time = "TO_DATE('2017:09:11:17:18','YYYY:MM:DD:HH24:MI')-20" format '/backup/ora_online/20170911_1718/arch_%d_%T_%U'; release channel 'dev_0'; }