<commit_before>[template]
# This is always executed with RMAN scripts. Must include CONNECT TARGET clause
header: SET ECHO ON
  CONNECT TARGET /@${configname}
# This is added when database is registered in catalog, so connect to catalog here
headercatalog: CONNECT CATALOG ${catalogconnect}
# This is always executed with RMAN, the last line must be EXIT
footer: EXIT
# Backup commands, all these commands are run inside a run block
backupimagecopy: backup incremental level 1 for recover of copy with tag 'image_copy_backup' database;
  recover copy of database with tag 'image_copy_backup';
  delete noprompt backupset tag 'image_copy_backup';
  delete noprompt force archivelog until time 'sysdate-${recoverywindow}';
  backup spfile tag 'image_copy_backup';
  backup current controlfile format '${backupdest}/after_backup_controlfile.cf' reuse tag 'image_copy_backup';
# Backupfooter is always executed with backup commands
backupfooter: delete noprompt obsolete recovery window of ${recoverywindow} days;
  show all;
# Configuration commands
registerdatabase: REGISTER DATABASE;
resynccatalog: RESYNC CATALOG;
config: CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF ${recoverywindow} DAYS;
  CONFIGURE BACKUP OPTIMIZATION ON;
  CONFIGURE DEFAULT DEVICE TYPE TO DISK;
  CONFIGURE CONTROLFILE AUTOBACKUP ON;
  CONFIGURE DEVICE TYPE DISK PARALLELISM ${parallel} BACKUP TYPE TO BACKUPSET;
  CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '${backupdest}/%%U';
  CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${backupdest}/%%F';
  CONFIGURE SNAPSHOT CONTROLFILE NAME TO '${backupdest}/snapcf_${configname}.f';
configdelalnodg: CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
configdelaldg: CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
# Report command
report: REPORT NEED BACKUP RECOVERY WINDOW OF ${recoverywindow} DAYS;
  REPORT UNRECOVERABLE;
  RESTORE DATABASE PREVIEW;
# This is executed to validate backup
validatebackup: RESTORE DATABASE VALIDATE HEADER;
  RESTORE CONTROLFILE VALIDATE;
  RESTORE ARCHIVELOG ALL VALIDATE;
  RESTORE DATABASE VALIDATE;
# Restore script
headerrestore: export ORACLE_SID=${configname}1 # The last number is RAC instance number
  export TNS_ADMIN=${tnspath}
  rman target /@${configname} catalog ${catalogconnect}
  # RMAN commands follow
fullrestore: set dbid ${dbid};
  startup nomount;
  # Spfile
  restore spfile;
  startup force nomount;
  # Controlfile
  restore controlfile;
  alter database mount;
  sql "alter database disable block change tracking";
  # Restore datafiles to diskgroup +DATA
  backup as copy format '+DATA' tag 'datafilerestore' copy of database from tag 'image_copy_backup';
  switch database to copy;
  recover database;
  # Recover will end with an error (cannot find the latest online log), if online logs are not available, then just ignore it, this data will be lost
  alter database open resetlogs;
  shutdown immediate;
restorefooter:
  == The following are OS command to put register database in GI
  == TODO
allocatearchlogchannel: allocate channel d1 device type disk format '${archdir}/%%U';

# Scheduler
dropschedule: begin
  begin
    DBMS_SCHEDULER.DROP_JOB(
      job_name=>'${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_JOB,${scheduleuserprefix}BACKUPEXEC.IMAGECOPY_JOB',
      force=>true,
      commit_semantics=>'ABSORB_ERRORS');
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_SCHEDULE(
      schedule_name=>'${scheduleuserprefix}BACKUPEXEC.IMAGECOPY_SCHEDULE,${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_SCHEDULE',
      force=>true);
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_PROGRAM(
      program_name=>'${scheduleuserprefix}BACKUPEXEC.IMAGECOPY_PRG,${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_PRG',
      force=>true);
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_CREDENTIAL(
      credential_name=>'${scheduleuserprefix}BACKUPEXEC.OSCRED',
      force => true);
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_JOB_CLASS (
      job_class_name=>'BACKUPEXEC_JOB',
      force=>true);
  exception
    when others then null;
  end;
  end;
  /

createschedule: CREATE OR REPLACE PROCEDURE ${scheduleuserprefix}backupexec.check_archlog_copy IS
    i  NUMBER;
  BEGIN
  -- Procedure automatically generated from backup.py
  -- Check if there are any archivelogs missing from the optional destination
  SELECT COUNT (*) INTO i
	 FROM (SELECT thread#, sequence#
				FROM v$$archived_log l
					  JOIN v$$archive_dest d ON l.dest_id = d.dest_id
					  JOIN v$$archive_dest_status s ON d.dest_id = s.dest_id
			  WHERE l.archived = 'YES' AND l.deleted = 'NO' AND UPPER (d.destination) = 'USE_DB_RECOVERY_FILE_DEST' AND d.status = 'VALID' AND s.TYPE = 'LOCAL'
			 MINUS
			 SELECT thread#, sequence#
				FROM v$$archived_log l
			  WHERE l.archived = 'YES' AND l.deleted = 'NO' AND l.name LIKE '${archdir}%%');
    IF i > 0 THEN
	 DBMS_SCHEDULER.create_job (job_name => '${scheduleuserprefix}BACKUPEXEC.'||DBMS_SCHEDULER.generate_job_name('MISSINGARCH'),
										 program_name => '${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_PRG',
										 job_class => '${scheduleuserprefix}BACKUPEXEC_JOB',
										 enabled => TRUE,
										 credential_name => '${scheduleuserprefix}BACKUPEXEC.OSCRED'<commit_msg>Fixed bug in the scheduler archivelog backup procedure<commit_after>[template]
# This is always executed with RMAN scripts. Must include CONNECT TARGET clause
header: SET ECHO ON
  CONNECT TARGET /@${configname}
# This is added when database is registered in catalog, so connect to catalog here
headercatalog: CONNECT CATALOG ${catalogconnect}
# This is always executed with RMAN, the last line must be EXIT
footer: EXIT
# Backup commands, all these commands are run inside a run block
backupimagecopy: backup incremental level 1 for recover of copy with tag 'image_copy_backup' database;
  recover copy of database with tag 'image_copy_backup';
  delete noprompt backupset tag 'image_copy_backup';
  delete noprompt force archivelog until time 'sysdate-${recoverywindow}';
  backup spfile tag 'image_copy_backup';
  backup current controlfile format '${backupdest}/after_backup_controlfile.cf' reuse tag 'image_copy_backup';
# Backupfooter is always executed with backup commands
backupfooter: delete noprompt obsolete recovery window of ${recoverywindow} days;
  show all;
# Configuration commands
registerdatabase: REGISTER DATABASE;
resynccatalog: RESYNC CATALOG;
config: CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF ${recoverywindow} DAYS;
  CONFIGURE BACKUP OPTIMIZATION ON;
  CONFIGURE DEFAULT DEVICE TYPE TO DISK;
  CONFIGURE CONTROLFILE AUTOBACKUP ON;
  CONFIGURE DEVICE TYPE DISK PARALLELISM ${parallel} BACKUP TYPE TO BACKUPSET;
  CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '${backupdest}/%%U';
  CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${backupdest}/%%F';
  CONFIGURE SNAPSHOT CONTROLFILE NAME TO '${backupdest}/snapcf_${configname}.f';
configdelalnodg: CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
configdelaldg: CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
# Report command
report: REPORT NEED BACKUP RECOVERY WINDOW OF ${recoverywindow} DAYS;
  REPORT UNRECOVERABLE;
  RESTORE DATABASE PREVIEW;
# This is executed to validate backup
validatebackup: RESTORE DATABASE VALIDATE HEADER;
  RESTORE CONTROLFILE VALIDATE;
  RESTORE ARCHIVELOG ALL VALIDATE;
  RESTORE DATABASE VALIDATE;
# Restore script
headerrestore: export ORACLE_SID=${configname}1 # The last number is RAC instance number
  export TNS_ADMIN=${tnspath}
  rman target /@${configname} catalog ${catalogconnect}
  # RMAN commands follow
fullrestore: set dbid ${dbid};
  startup nomount;
  # Spfile
  restore spfile;
  startup force nomount;
  # Controlfile
  restore controlfile;
  alter database mount;
  sql "alter database disable block change tracking";
  # Restore datafiles to diskgroup +DATA
  backup as copy format '+DATA' tag 'datafilerestore' copy of database from tag 'image_copy_backup';
  switch database to copy;
  recover database;
  # Recover will end with an error (cannot find the latest online log), if online logs are not available, then just ignore it, this data will be lost
  alter database open resetlogs;
  shutdown immediate;
restorefooter:
  == The following are OS command to put register database in GI
  == TODO
allocatearchlogchannel: allocate channel d1 device type disk format '${archdir}/%%U';

# Scheduler
dropschedule: begin
  begin
    DBMS_SCHEDULER.DROP_JOB(
      job_name=>'${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_JOB,${scheduleuserprefix}BACKUPEXEC.IMAGECOPY_JOB',
      force=>true,
      commit_semantics=>'ABSORB_ERRORS');
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_SCHEDULE(
      schedule_name=>'${scheduleuserprefix}BACKUPEXEC.IMAGECOPY_SCHEDULE,${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_SCHEDULE',
      force=>true);
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_PROGRAM(
      program_name=>'${scheduleuserprefix}BACKUPEXEC.IMAGECOPY_PRG,${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_PRG',
      force=>true);
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_CREDENTIAL(
      credential_name=>'${scheduleuserprefix}BACKUPEXEC.OSCRED',
      force => true);
  exception
    when others then null;
  end;
  begin
    DBMS_SCHEDULER.DROP_JOB_CLASS (
      job_class_name=>'BACKUPEXEC_JOB',
      force=>true);
  exception
    when others then null;
  end;
  end;
  /

createschedule: CREATE OR REPLACE PROCEDURE ${scheduleuserprefix}backupexec.check_archlog_copy IS
    i  NUMBER;
  BEGIN
  -- Procedure automatically generated from backup.py
  -- Check if there are any archivelogs missing from the optional destination
  SELECT COUNT (*) INTO i
	 FROM (SELECT thread#, sequence#
				FROM v$$archived_log l
					  JOIN v$$archive_dest d ON l.dest_id = d.dest_id
					  JOIN v$$archive_dest_status s ON d.dest_id = s.dest_id
			  WHERE l.archived = 'YES' AND l.deleted = 'NO' AND UPPER (d.destination) = 'USE_DB_RECOVERY_FILE_DEST' AND d.status = 'VALID' AND s.TYPE = 'LOCAL'
			 MINUS
			 SELECT thread#, sequence#
				FROM v$$archived_log l
			  WHERE l.archived = 'YES' AND l.deleted = 'NO' AND l.name LIKE '${archdir}%%');
    IF i > 0 THEN
	 DBMS_SCHEDULER.create_job (job_name => '${scheduleuserprefix}BACKUPEXEC.'||DBMS_SCHEDULER.generate_job_name('MISSINGARCH'),
										 program_name => '${scheduleuserprefix}BACKUPEXEC.ARCHLOGBACKUP_PRG',
										 job_class => 'BACKUPEXEC_JOB',
										 enabled => TRUE,
										 credential_name => '${scheduleuserprefix}BACKUPEXEC.OSCRED'
{'fraction_non_alphanumeric': 0.07848077640910787, 'fraction_numerical': 0.0007465472191116088, 'mean_word_length': 4.718783351120598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4071338', 'n_tokens_mistral': 3644, 'n_tokens_neox': 3425, 'n_words': 1054}