Copying Archive log from ASM to local file system using script
- Set archivelog in ASM location (OPTIONAL)
SQL> ALTER SYSTEM SET log_archive_dest_1='LOCATION=+FRA/archivelog' scope=memory;
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +FRA/archivelog
Oldest online log sequence 119
Next log sequence to archive 120
Current log sequence 120
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL>
- Mention the local file and archivelog location , Script details below :
[grid@srv1 archivelog]$ cat asm_archivelog.sh
#!/bin/bash
#
# This script copies files from FRA on ASM to local disk
#
export ORACLE_SID=+ASM1
export ORACLE_HOME=/u01/app/12.2.0/grid ##{Grid OH}
export PATH=$ORACLE_HOME/perl/bin:$PATH
ASMLS=/u01/archivelog/asm_log.txt ##{ASM files list}
FRA=+FRA/archivelog ##{source location of files}
LOCALBACKUPDIR=/u01/archivelog ##{destination filesystem location }
LOG=/u01/archivelog/asm_grid_smrpod.txt ##{log file location }
#
# Get the list of files
#
$ORACLE_HOME/bin/asmcmd > $ASMLS <<EOF
ls $FRA
exit
EOF
#
# Clean the list by removing "ASMCMD>"
#
sed -i 's/ASMCMD> //g' $ASMLS
##cat $ASMLS
echo `date` > $LOG
#
# Copy files one by one
#
for FILENAME in `cat $ASMLS`
do
if [[ ! -f $LOCALBACKUPDIR/${FILENAME} ]]
then
$ORACLE_HOME/bin/asmcmd >> $LOG <<EOF
cp $FRA/$FILENAME $LOCALBACKUPDIR
EOF
fi
done
echo `date` >> $LOG
[grid@srv1 archivelog]$
[grid@srv1 archivelog]$ sh asm_archivelog.sh
- OUTPUT
[grid@srv1 archivelog]$ ll
total 4888
-rw-r----- 1 grid oinstall 1960448 Feb 5 20:36 1_120_1088276576.dbf
-rw-r----- 1 grid oinstall 6656 Feb 5 20:36 1_121_1088276576.dbf
-rw-r----- 1 grid oinstall 3072 Feb 5 20:36 1_122_1088276576.dbf
-rw-r----- 1 grid oinstall 4096 Feb 5 20:36 1_123_1088276576.dbf
-rw-r----- 1 grid oinstall 174592 Feb 5 20:36 1_124_1088276576.dbf
-rw-r----- 1 grid oinstall 2664960 Feb 5 20:36 2_88_1088276576.dbf
-rw-r----- 1 grid oinstall 162816 Feb 5 20:36 2_89_1088276576.dbf
-rw-r----- 1 grid oinstall 3072 Feb 5 20:36 2_90_1088276576.dbf
-rw-r----- 1 grid oinstall 2048 Feb 5 20:36 2_91_1088276576.dbf
No comments:
Post a Comment