Sunday 22 August 2021

RMAN Stored backup scripts

RMAN stored scripts used to store backup scripts in catalog database with local and global options, 

Local script are specific to target database which is connected when script created,
Global scripts can be run in any db registered with catalog database.

Create stored scripts:
need to connect catalog db to create stored scripts,

/home/oracle> rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Sun Aug 22 22:57:24 2021
Version 19.8.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
connected to target database: LABDB19C (DBID=4148792351)

RMAN> connect catalog rcat/rcat@labdb19c_test1
connected to recovery catalog database

before creating scripts, lets check if any existing stored scripts available in db or not
RMAN> LIST GLOBAL SCRIPT NAMES;
List of Stored Scripts in Recovery Catalog
        No scripts in recovery catalog

RMAN> LIST SCRIPT NAMES;
List of Stored Scripts in Recovery Catalog
        No scripts in recovery catalog

catalog db don't have stored scripts, 
Create global script: 
RMAN> CREATE GLOBAL SCRIPT DB_BACKUP_FULL
{     
  BACKUP DATABASE PLUS ARCHIVELOG format '/backup/exports/lab19c_bkps/rman_bkp/%d_db_full_%u_%t';
}
created global script DB_BACKUP_FULL

Global script created ,validate with list command 
RMAN>  LIST GLOBAL SCRIPT NAMES;
List of Stored Scripts in Recovery Catalog
    Global Scripts

       Script Name
       Description
       ---------------------------------------------
       DB_BACKUP_FULL   
       
Create local script:
RMAN> CREATE SCRIPT DB_BACKUP_FULL
{     
  BACKUP DATABASE PLUS ARCHIVELOG format '/backup/exports/lab19c_bkps/rman_bkp/%d_db_full_%u_%t';
}
created script DB_BACKUP_FULL

Local script created ,validate with list command 
RMAN>  LIST SCRIPT NAMES;
List of Stored Scripts in Recovery Catalog

    Scripts of Target Database LABDB19C
       Script Name
       Description
       --------------------------------------
       DB_BACKUP_FULL

    Global Scripts
       Script Name
       Description
       ---------------------------------------
       DB_BACKUP_FULL

Create script from file:
/home/oracle/jay> cat /home/oracle/jay/Delete_archivelog.txt
{
delete noprompt archivelog until time 'sysdate-6/24';
}

RMAN> CREATE GLOBAL SCRIPT Delete_archives FROM FILE '/home/oracle/jay/Delete_archivelog.txt';

script commands will be loaded from file /home/oracle/jay/Delete_archivelog.txt
created global script Delete_archives

RMAN>  LIST GLOBAL SCRIPT NAMES;

List of Stored Scripts in Recovery Catalog

    Global Scripts
       Script Name
       Description
       -------------------------------------
       DB_BACKUP_FULL
       Delete_archives

Stored script backup to file:
RMAN> PRINT GLOBAL SCRIPT Delete_archives TO FILE '/home/oracle/jay/Delete_archivelog.txt_bkp';

global script Delete_archives written to file /home/oracle/jay/Delete_archivelog.txt_bkp

validate backup file:
/home/oracle/jay > cat /home/oracle/jay/Delete_archivelog.txt_bkp
{
delete noprompt archivelog until time 'sysdate-6/24';
}

Validate backup scripts:
RMAN> PRINT SCRIPT DB_BACKUP_FULL;
printing stored script: DB_BACKUP_FULL
{     
  BACKUP DATABASE PLUS ARCHIVELOG format '/backup/exports/lab19c_bkps/rman_bkp/%d_db_full_%u_%t';
}

RMAN> PRINT GLOBAL SCRIPT Delete_archives;
printing stored global script: Delete_archives
{
delete noprompt archivelog until time 'sysdate-6/24';
}

List commands:
LIST SCRIPT NAMES;
LIST GLOBAL SCRIPT NAMES;
LIST ALL SCRIPT NAMES;

Delete stored scripts:
DELETE SCRIPT global_full_backup;

example:
RMAN> DELETE SCRIPT Delete_archives;
deleted global script: Delete_archives


Run backups using stored scripts:
Commands:
RUN { EXECUTE GLOBAL SCRIPT DB_BACKUP_FULL ;}
RUN { EXECUTE SCRIPT DB_BACKUP_FULL; }

example:
RMAN> RUN { EXECUTE GLOBAL SCRIPT Delete_archives ;} 

executing global script: Delete_archives

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=285 device type=DISK
List of Archived Log Copies for database with db_unique_name LABDB19C
======================================================
Key     Thrd Seq     S Low Time       
------- ---- ------- - ---------------
1230    1    1119    A 20210802.082001
        Name: +POC19C_DATA/LABDB19C/ARCHIVELOG/2021_08_02/thread_1_seq_1119.290.1079511603
1231    1    1120    A 20210802.082002
        Name: +POC19C_DATA/LABDB19C/ARCHIVELOG/2021_08_02/thread_1_seq_1120.309.1079511603

deleted archived log
archived log file name=+POC19C_DATA/LABDB19C/ARCHIVELOG/2021_08_02/thread_1_seq_1119.290.1079511603 RECID=17 STAMP=1079511602
deleted archived log
archived log file name=+POC19C_DATA/LABDB19C/ARCHIVELOG/2021_08_02/thread_1_seq_1120.309.1079511603 RECID=18 STAMP=1079511603
Deleted 2 objects

No comments:

Post a Comment