Oracle database RMAN example command

** Credit Web
#rman_delete_archvie_old_2day#
########################################################################
rman target / << EOF
run
{
allocate channel D1 type disk;
delete noprompt archivelog until time 'SYSDATE-2';
release channel D1;
}




#rmanArchive#
########################################################################
export ORACLE_SID=TEST2
sqlplus /nolog <<EOF
connect / as sysdba
alter system switch logfile;
EXIT
EOF
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk
format '/data/oracle8/BACKUP/rman_ARC_%s_%p_%t.bus';
# backup archivelog until time 'sysdate-1/24' delete input;
backup archivelog from time 'sysdate-1/24';
}
EOF
sqlplus /nolog <<EOF
connect / as sysdba
alter system switch logfile;
EXIT
EOF






#rmanCatalog#
########################################################################
rman <<EOF
connect catalog rman/rman_oracledba@test1
create catalog;
EOF






#rmanClone#
########################################################################
export NLS_DATE_FORMAT='DD-MON-RRRR HH24:MI:SS'
export ORACLE_SID=TEST2
sqlplus /nolog <<EOF
connect  / as sysdba
alter system switch logfile;
exit
EOF
rmanA.sh
export ORACLE_SID=TEST3
sqlplus /nolog <<EOF
connect sys/oracledba as sysdba
shutdown abort
startup nomount
exit
EOF
rm /data/oracle8/TEST3/*
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
connect auxiliary sys/oracledba@test3
run {
# set until time "to_date('2002-01-29:15:16:53','yyyy-mm-dd:hh24:mi:ss')";
# set until time "to_date('30-JAN-2002 10:50:00','dd-mon-YYYY HH24:MI:SS')";
set until time '31-JAN-2002 10:51:00';
# set until time 'sysdate-1/1000';
# set until scn = 155534;
allocate auxiliary channel d1 type disk;
allocate auxiliary channel d2 type disk;
duplicate target database to test3;
}
EOF






#rmanConnect#
########################################################################
rman target rman/rman_oracledba@test2 catalog rman/rman_oracledba@test1







#rmanControl#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk
format '/data/oracle8/BACKUP/rman_CTL_%s_%p_%t.bus';
backup current controlfile;
}
EOF






#rmanCopy#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
copy datafile '/data/oracle8/TEST2/dataTEST2.dbf'
to '/data/oracle8/BACKUP/dataTEST2.dbf';
copy datafile '/data/oracle8/TEST2/rbsTEST2.dbf'
to '/data/oracle8/BACKUP/rbsTEST2.dbf';
copy datafile '/data/oracle8/TEST2/tempTEST2.dbf'
to '/data/oracle8/BACKUP/tempTEST2.dbf';
copy datafile '/data/oracle8/TEST2/systemTEST2.dbf'
to '/data/oracle8/BACKUP/systemTEST2.dbf';
copy current controlfile to '/data/oracle8/BACKUP/ctrlTEST201.ctl';
}
EOF






#rmanDatafile#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
backup datafile '/data/oracle8/TEST2/dataTEST2.dbf' 
filesperset 2  include current controlfile 
format '/data/oracle8/BACKUP/rman_DF_%d.%t.%p.%c.bus';
}
EOF






#rmanDuplicate#
########################################################################
export ORACLE_SID=TEST2
sqlplus /nolog <<EOF
connect / as sysdba
@rmanDuplicate.sql
exit
EOF>>






#rmanDuplicate_temp#
########################################################################
export NLS_DATE_FORMAT='DD-MON-RRRR HH24:MI:SS'
export ORACLE_SID=TEST2
sqlplus /nolog <<EOF
connect  / as sysdba
alter system switch logfile;
alter system archive log all;
exit
EOF
rmanA.sh
export ORACLE_SID=TEST3
sqlplus /nolog <<EOF
connect sys/oracledba as sysdba
shutdown abort
startup nomount
exit
EOF
rm /data/oracle8/TEST3/*
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
connect auxiliary sys/oracledba@test3
run {
resync catalog;
allocate auxiliary channel d1 type disk;
allocate auxiliary channel d2 type disk;
# set until time "to_date('2002-01-29:15:16:53','yyyy-mm-dd:hh24:mi:ss')"
# set until time "to_date('30-JAN-2002 10:50:00','dd-mon-YYYY HH24:MI:SS')"
# set until time '31-JAN-2002 10:51:00'
# set until time 'sysdate-1/96';
# set until scn = 155534
set newname for datafile '/data/oracle8/TEST2/systemTEST2.dbf' TO '/data/oracle8/TEST3/systemTEST3.dbf';
set newname for datafile '/data/oracle8/TEST2/rbsTEST2.dbf' TO '/data/oracle8/TEST3/rbsTEST3.dbf';
set newname for datafile '/data/oracle8/TEST2/tempTEST2.dbf' TO '/data/oracle8/TEST3/tempTEST3.dbf';
set newname for datafile '/data/oracle8/TEST2/dataTEST2.dbf' TO '/data/oracle8/TEST3/dataTEST3.dbf';
sql 'alter system switch logfile';
duplicate target database to test3
LOGFILE
'/data/oracle8/TEST3/redoTEST301.log' size 1M,
'/data/oracle8/TEST3/redoTEST302.log' size 1M,
'/data/oracle8/TEST3/redoTEST303.log' size 1M;
}
EOF






#rmanFullbu#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
backup full tag backup_1 filesperset 2
format '/data/oracle8/BACKUP/rman_BACKUP_%d_%t.%p.%s.%c.%n.%u.bus'
database;
}
EOF






#rmanLev0#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
backup incremental level 0 
filesperset 2
format '/data/oracle8/BACKUP/rman_LVL0_%d.%t.%p.%c.bus'
database;
}
EOF






#rmanLev1#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
backup incremental level 1 
filesperset 2
format '/data/oracle8/BACKUP/rman_LVL1_%d.%t.%p.%c.bus'
database;
}
EOF






#rmanLev2#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
backup incremental level 2 
filesperset 2
format '/data/oracle8/BACKUP/rman_LVL2_%d.%t.%p.%c.bus'
database;
}
EOF






#rmanList#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
list backup;
EOF

rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
report obsolete orphan;
EOF




#rmanList2#
########################################################################
rman <<EOF
connect catalog rman/rman_oracledba@test1
connect target sys/oracledba@test2
list backup;
EOF






#rmanRecover#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
recover database;
alter database open ;
}
EOF






#rmanRegister#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
resync catalog;
# register database;
EOF






#rmanRescontrolfile#
########################################################################
export ORACLE_SID=TEST2
echo 'shutting down TEST2 ABORT'
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
shutdown abort
exit
EOF
echo 'removing Controlfile'
rm /data/oracle8/TEST2/*.ctl
echo 'listing the directory to verify Controlfile does not exist'
ls -l /data/oracle8/TEST2
echo 'starting TEST2 in NOMOUNT mode'
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
startup nomount
exit
EOF
echo 'Restoring Controlfile using RMAN'   
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
restore controlfile;
alter database  mount;
alter database  open resetlogs;
}
EOF






#rmanResdatafile#
########################################################################
export ORACLE_SID=TEST2
echo 'shutting down TEST2 ABORT'
echo
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
shutdown abort
exit
EOF
echo
echo 'removing datafile /data/oracle8/TEST2/dataTEST2.dbf '
echo
rm /data/oracle8/TEST2/dataTEST2.dbf
echo 'listing the directory to verify datafile does not exist'
ls -l /data/oracle8/TEST2
sleep 5
echo
echo 'starting TEST2 in MOUNT mode'
echo
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
startup mount
alter database datafile '/data/oracle8/TEST2/dataTEST2.dbf' offline;
alter database open;
exit
EOF
echo
echo 'checking the status of datafiles'
echo
sqlplus /nolog @checkdf.sql
sleep 10
echo 'Restoring datafile using RMAN'   
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
restore datafile '/data/oracle8/TEST2/dataTEST2.dbf';
recover datafile '/data/oracle8/TEST2/dataTEST2.dbf';
}
EOF
sqlplus /nolog <<EOF
connect rman/rman_oracledba as sysdba
alter database datafile '/data/oracle8/TEST2/dataTEST2.dbf' online;
exit
EOF
echo
echo 'checking the status of datafiles'
echo
sqlplus /nolog @checkdf.sql






#rmanResresetlogs#
########################################################################
rman target rman/rman_oracledba@test2 catalog rman/rman_oracledba@test1 <<EOF
run {
allocate channel d1 type disk;
restore controlfile;
alter database mount;
restore database;
recover database ;
alter database open resetlogs;
}
EOF






#rmanRestablespace#
########################################################################
export ORACLE_SID=TEST2
# sqlplus /nolog <<EOF
# connect rman/rman_oracledba as sysdba
# shutdown abort
# startup
# exit
# EOF
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
sql 'Alter tablespace data offline';
restore tablespace data;
recover tablespace data;
sql 'Alter tablespace data online';
}
EOF






#rmanRestore#
########################################################################
export ORACLE_SID=TEST2
sqlplus /nolog <<EOF
connect / as sysdba
shutdown immediate
startup mount
exit
EOF
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
# set until time "to_date('2002-01-29:15:16:53','yyyy-mm-dd:hh24:mi:ss')";
restore database;
recover database;
alter database open resetlogs;
}
EOF






#rmanResync#
########################################################################
export ORACLE_SID=TEST2
# This script will resync the catalog.
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
resync catalog;
# register database;
EOF






#rmanTablespace#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
backup tablespace "DATA" filesperset 2 
include current controlfile 
format '/data/oracle8/BACKUP/rman_TBS_%d.%t.%p.%c.bus';
}
EOF






#rmanValidate#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
run { allocate channel d1 type disk;
restore database validate;
}
EOF






#rmanXC#
########################################################################
rman <<EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
allocate channel for maintenance type disk;
crosscheck backup of database;
delete expired backup of database;
list backup;
EOF




0 comments:

Loading