Using variables in RMAN

When using RMAN catalog it is preferred to use backup script stored in catalog. It is best if scripts can be reused for different retention.

You can use variables in RMAN script this way:

CREATE global script global_backup_full_database 
comment 'backup full of database. Parameter sysdate+n,tag db, tag archivelog'
{
allocate channel c1 TYPE SBT_TAPE PARMS 'BLKSIZE=1048576,SBT_LIBRARY=/usr/lib/ddbda/libddboostora.so, ENV=(CONFIG_FILE=/opt/ddbda/config/oracle_ddbda.cfg)' FORMAT '%d_%U';
backup AS backupset DATABASE filesperset 1 keep until TIME '&1' tag &2;
backup AS backupset archivelog ALL DELETE INPUT filesperset=1 keep until TIME '&1' tag &3;
}

You can then call the script from rman this way:

RUN
{ 
  EXECUTE SCRIPT global_backup_full_database 
    USING 'sysdate+15'
          backup_daily_db
          backup_daily_arch;
}