The following scripts are part of this chapter:
0-make-io
1-change_tracking
2-backup-backupset-compressed
3-backup-as-copy
4-incremental-backup-and-tags
5-backup-plus-archived-logs
6-backup-controlfile
7-incremental-for-backup-recover
8-incremental-for-quick-recover
0-make-io
This script generates insert/update statements on a cyclic way in order to advance the archive log sequences and produce some test data.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command : Masive Inserts into Test Table
sqlplus -s $dbauser/$dbapwd@$datadb as sysdba <<eof
-- create table tst as select * from dba_users;
delete from tst;
commit;
insert into tst select * from dba_users;
insert into tst select * from tst;
insert into tst select * from tst;
insert into tst select * from tst;
insert into tst select * from tst;
insert into tst select * from tst;
insert into tst select * from tst;
insert into tst select * from tst;
insert into tst select * from tst;
insert into tst select * from tst;
commit;
eof
exit
1-change_tracking
This script creates a change tracking file on the Flash Recovery Area ASM diskgroup +FRADG.
A Change Tracking File keeps track of changed blocks, rman instead of scanning all datafiles for changes, read the pointers on the change tracking file, that greatly speeds up incremental backups.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command :
echo
echo ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+fradg';
echo
sqlplus -s $dbauser/$dbapwd@$datadb as sysdba <<eof
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+fradg';
eof
set v_bct=V\$BLOCK_CHANGE_TRACKING
echo
echo Executing Command :
echo
echo "SELECT * FROM $v_bct"
echo
sqlplus -s $dbauser/$dbapwd@$datadb as sysdba <<eof
col filename for a60
set lines 200
SELECT * FROM $v_bct;
Eof
Exit
2-backup-backupset-compressed
This script creates a compressed database backupset that includes also the archived logs.
Once the backup complete successfully the original archived logs are removed from disk.
Rman compression saves around 80% of the space required to store a whole database backup.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command : BACKUP AS COMPRESSED BACKUPSET
echo
rman TARGET $dbauser/$dbapwd@$datadb CATALOG $rmanuser/$rmanpwd@$rmandb log=./scr.log <<eof
BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG DELETE INPUT;
eof
more ./scr.log
rm ./scr.log
exit
3-backup-as-copy
This script creates a bit by bit copy of the database files and archived logs, the backup destination is a file system.
This backup type create files that can be used to create a clone or restore the database without using rman.
In addition this kind of backup can be updated applying to it the changes recorded on future incremental backups.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command : BACKUP AS COPY - to file system -
echo
rman TARGET $dbauser/$dbapwd@$datadb CATALOG $rmanuser/$rmanpwd@$rmandb log=scr.log <<eof
BACKUP AS COPY DEVICE TYPE DISK DATABASE FORMAT '/oradisk/backup/%U' TAG='FULL2RECOVER' PLUS ARCHIVELOG DELETE INPUT;
eof
more ./scr.log
rm ./scr.log
exit
4-incremental-backup-and-tags
This script creates a compressed incremental level 0 backupset and assigns to it a tag, that can be used to reference it on another rman command later.
The backup is create on the Flash Recovery Area because the parameter db_recovery_file_dest is set to ASM diskgroup +FRADG
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command : BACKUP AS COMPRESSED BACKUPSET
echo
rman TARGET $dbauser/$dbapwd@$datadb CATALOG $rmanuser/$rmanpwd@$rmandb log=scr.log <<eof
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 DATABASE TAG 'production_full_lv0';
eof
more ./scr.log
rm ./scr.log
exit
5-backup-plus-archived-logs
This script like the previous creates a compressed incremental level 0 backupset and assigns to it a tag, that can be used to reference it on another rman command later.
In this case the destination is set to a file system with the FORMAT clause.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command : BACKUP AS COMPRESSED BACKUPSET
echo
rman TARGET $dbauser/$dbapwd@$datadb CATALOG $rmanuser/$rmanpwd@$rmandb log=scr.log <<eof
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0
DATABASE PLUS ARCHIVELOG
TAG 'prod_fll_l0_pls_arc2dsk'
FORMAT '/oradisk/backup/%U'
DELETE INPUT;
eof
more ./scr.log
rm ./scr.log
exit
6-backup-controlfile
This script setup some of the basic configurable rman parameters. by setting AUTOBACKUP ON each time a backup is executed, or an structural change is made to the database, automatical a backup of the controlfile will be created.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command : Controlfile Autobackup Settings
rman TARGET $dbauser/$dbapwd@$datadb CATALOG $rmanuser/$rmanpwd@$rmandb log=scr.log <<eof
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%d_%F';
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # delete obsolete and backed up 2 times
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/oradisk/oracle/app/product/11.1.0/db_1/dbs/snapcf_redpanda.f'; # default
eof
more scr.log
exit
7-incremental-for-backup-recover
This script when executed the first time look for a backup with tag 'INCREMENTAL_DAILY_UPDATED' that does not exist yet, so it creates it.
The second time it will create an incremental backup level 1 to be used to recover the original backup, on the next run.
From the third time on, the script will make recover the backup tag
'INCREMENTAL_DAILY_UPDATED' with the previous incremental and it will create a new incremental backup.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command INCREMENTAL DAILY BACKUP TO FILE SYSTEM
echo
rman TARGET $dbauser/$dbapwd@$datadb CATALOG $rmanuser/$rmanpwd@$rmandb log=scr.log <<eof
RUN
{
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '/oradisk/backup/%U';
ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '/oradisk/backup/%U';
RECOVER COPY OF DATABASE
WITH TAG 'INCREMENTAL_DAILY_UPDATED' ;
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'INCREMENTAL_DAILY_UPDATED'
DATABASE FORMAT '/oradisk/backup/%U'
PLUS ARCHIVELOG FORMAT '/oradisk/backup/%U';
}
eof
more ./scr.log
exit
8-incremental-for-quick-recover
This script is similar to the previous one, the difference is that instead of applying each day the previous day incremental backup, it will wait for a week before starting to apply the incremental pieces.
When executed the first time it will look for a backup with tag 'INCREMENTAL_FAST_RECOVER' that does not exist yet, so it creates it.
From the second and until the seventh time it will create an incremental backup level 1 to be used to recover the backup with tag 'INCREMENTAL_FAST_RECOVER'.
From the eight time on, the script will recover the backup taged 'INCREMENTAL_FAST_RECOVER' using the incremental produced a week ago.
#!/usr/bin/tcsh
source ./set-environment
echo Executing Command : INCREMENTAL SEVEN DAY BACKUP
echo
rman TARGET $dbauser/$dbapwd@$datadb CATALOG $rmanuser/$rmanpwd@$rmandb log=scr.log <<eof
RUN
{
RECOVER COPY OF DATABASE
WITH TAG 'INCREMENTAL_FAST_RECOVER'
UNTIL TIME 'SYSDATE - 7';
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'INCREMENTAL_FAST_RECOVER'
DATABASE;
}
Eof
more scr.log
exit
No comments:
Post a Comment