Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Using RMAN to remove archive logs

David JanesSep 5 2024

Hi

I have a Windows 2019 server on a Cloud platform along with a Acronis backup server . I have a job on Acronis to backup the D drive of my Windows 2019 server each morning at 0100. Tuesdays are full backups. Wednesday-Saturday incremental backups. Retention policy is 4 full, 4 incremental.

Windows Server 2019 with Oracle DB 19c
I use task scheduler Monday-Friday at 2350 to run a bat file.

hot_backup.bat

REM   
echo off   
echo "HOT BACKUP started"
del D:\oracle_backup\archive_log_and_control_files\*.* /F /Q
set ORACLE_HOME=C:\Oracle\product\19.0.0\dbhome_1
set ORACLE_SID=cdb
sqlplus / as sysdba @C:\Users\Administrator\Documents\hot_backup.sql
EXIT

hot_backup.sql

set define on
set lines 1000   

COLUMN spool_file_name NEW_VALUE spool_file_name NOPRINT
COLUMN backup_folder NEW_VALUE backup_folder NOPRINT

select 'hot_backup_output_' || to_char(sysdate, 'yyyymmdd_HH24_MM_SS' ) || '.log' spool_file_name,
       'Backup_'  || to_char(sysdate, 'ddmmyyyy') backup_folder from dual;

prompt "D:\oracle_backup\&backup_folder"

spool D:\oracle_backup\archive_log_and_control_files\&spool_file_name

prompt "Alter database begin backup"
Alter database begin backup;

select * from v$backup;

prompt Sequence Number of archive logs
SELECT group#, sequence#, status from v$log;

prompt "alter system switch logfile"
alter system switch logfile;

host C:\Users\Administrator\Documents\copy_oracle_datafiles.bat

prompt "Alter database end backup"
Alter database end backup;

prompt "ALTER SYSTEM ARCHIVE LOG ALL"
ALTER SYSTEM ARCHIVE LOG ALL;

Alter database backup controlfile to 'D:\oracle_backup\archive_log_and_control_files\CONTROLFILE.BAK.CTL';
Alter database backup controlfile to trace as 'D:\oracle_backup\archive_log_and_control_files\CONTROLFILE_TRACE_BAK.CTL';

prompt "Also BackUp these files from V$ARCHIVED_LOG"
SELECT THREAD#,SEQUENCE#,NAME FROM V$ARCHIVED_LOG where name is not null;

prompt Sequence Number of archive logs
SELECT group#, sequence#, status from v$log;

spool off 

set head off   
set term off   
set feedback off
set verify off
spool D:\oracle_backup\archive_log_and_control_files\archive_log_copy.bat
   select 'copy ' || name || ' D:\oracle_backup\archive_log_and_control_files\' from v$ARCHIVED_LOG where name is not null;
spool off 

host D:\oracle_backup\archive_log_and_control_files\archive_log_copy.bat
host move D:\oracle_backup\archive_log_and_control_files\archive_log_copy.bat D:\oracle_backup\archive_log_and_control_files\archive_log_copy.txt

exit

copy_oracle_datafiles.bat

robocopy C:\Oracle\oradata D:\oracle_backup\oradata /s /z /XO

The hot_backup.sql might be a bit overkill on the prompts and logging but it will do the job and allow me to restore the db with a maximum of 1 days lost data.

The D drive only contains one set of files as the previous nights backups are now on the backup server.
Set of files contains:
All the archive logs
2 control files
text file with archive logs copied
And the logging log file from the sql.

But obviously the archive logs keep growing and growing. every night there are more and more log files to be backed up. And as you can imagine the older archive log files could be weeks behind the actual data file and of no use whatsoever.

How can I use RMAN please to remove archive logs each week? or to do all of the above ? The only thing i do in RMAN is "delete noprompt archivelog all;" after I've shutdown the database (just to make the database consistent and clear the log files)

I have thought about the following but i don't know how to set retention, how to specify where the backup files go etc etc.

run
{
backup incremental level [0|1] database tag 'ABC_DBF';
backup archivelog all delete all input tag 'ABC_ARCH';
backup current controlfile tag 'ABC_CTL';
backup spfile tag 'ABC_SPFILE';
crosscheck backup;
delete noprompt obsolete device type disk;
delete noprompt expired backup;
}

I'm really confused by how to set this up in RMAN and would be very grateful for any help.

Many Thanks

DJ

Comments
Post Details
Added on Sep 5 2024
2 comments
59 views