Script di esempio
Gli script presentati sono forniti come esempi di come eseguire lo script di varie attività del sistema operativo e del database. Vengono forniti così come sono. Se è necessario supporto per una procedura particolare, contattare NetApp o un rivenditore NetApp.
Arresto del database
Lo script Perl seguente prende un singolo argomento del SID Oracle e chiude un database. Può essere eseguito come utente Oracle o come root.
#! /usr/bin/perl
use strict;
use warnings;
my $oraclesid=$ARGV[0];
my $oracleuser='oracle';
my @out;
my $uid=$<;
if ($uid == 0) {
@out=`su - $oracleuser -c '. oraenv << EOF1
77 Migration of Oracle Databases to NetApp Storage Systems © 2021 NetApp, Inc. All rights reserved
$oraclesid
EOF1
sqlplus / as sysdba << EOF2
shutdown immediate;
EOF2
'
`;}
else {
@out=`. oraenv << EOF1
$oraclesid
EOF4
sqlplus / as sysdba << EOF2
shutdown immediate;
EOF2
`;};
print @out;
if ("@out" =~ /ORACLE instance shut down/) {
print "$oraclesid shut down\n";
exit 0;}
elsif ("@out" =~ /Connected to an idle instance/) {
print "$oraclesid already shut down\n";
exit 0;}
else {
print "$oraclesid failed to shut down\n";
exit 1;}
Avvio del database
Lo script Perl seguente prende un singolo argomento del SID Oracle e chiude un database. Può essere eseguito come utente Oracle o come root.
#! /usr/bin/perl
use strict;
use warnings;
my $oraclesid=$ARGV[0];
my $oracleuser='oracle';
my @out;
my $uid=$<;
if ($uid == 0) {
@out=`su - $oracleuser -c '. oraenv << EOF1
$oraclesid
EOF1
sqlplus / as sysdba << EOF2
startup;
EOF2
'
`;}
else {
@out=`. oraenv << EOF3
$oraclesid
EOF1
sqlplus / as sysdba << EOF2
startup;
EOF2
`;};
print @out;
if ("@out" =~ /Database opened/) {
print "$oraclesid started\n";
exit 0;}
elsif ("@out" =~ /cannot start already-running ORACLE/) {
print "$oraclesid already started\n";
exit 1;}
else {
78 Migration of Oracle Databases to NetApp Storage Systems © 2021 NetApp, Inc. All rights reserved
print "$oraclesid failed to start\n";
exit 1;}
Convertire il file system in sola lettura
Lo script seguente prende un argomento del file system e tenta di smontarlo e rimontarlo in modalità di sola lettura. Questa operazione è utile durante i processi di migrazione in cui un file system deve essere mantenuto disponibile per replicare i dati e deve essere protetto contro danni accidentali.
#! /usr/bin/perl
use strict;
#use warnings;
my $filesystem=$ARGV[0];
my @out=`umount '$filesystem'`;
if ($? == 0) {
print "$filesystem unmounted\n";
@out = `mount -o ro '$filesystem'`;
if ($? == 0) {
print "$filesystem mounted read-only\n";
exit 0;}}
else {
print "Unable to unmount $filesystem\n";
exit 1;}
print @out;
Sostituire il file system
L'esempio di script riportato di seguito viene utilizzato per sostituire un file system con un altro. Poiché modifica il file ``/etc/fstab, deve essere eseguito come root. Accetta un singolo argomento delimitato da virgole per i file system vecchi e nuovi.
-
Per sostituire il file system, eseguire lo script seguente:
#! /usr/bin/perl use strict; #use warnings; my $oldfs; my $newfs; my @oldfstab; my @newfstab; my $source; my $mountpoint; my $leftover; my $oldfstabentry=''; my $newfstabentry=''; my $migratedfstabentry=''; ($oldfs, $newfs) = split (',',$ARGV[0]); open(my $filehandle, '<', '/etc/fstab') or die "Could not open /etc/fstab\n"; while (my $line = <$filehandle>) { chomp $line; ($source, $mountpoint, $leftover) = split(/[ , ]/,$line, 3); if ($mountpoint eq $oldfs) { $oldfstabentry = "#Removed by swap script $source $oldfs $leftover";} elsif ($mountpoint eq $newfs) { $newfstabentry = "#Removed by swap script $source $newfs $leftover"; $migratedfstabentry = "$source $oldfs $leftover";} else { push (@newfstab, "$line\n")}} 79 Migration of Oracle Databases to NetApp Storage Systems © 2021 NetApp, Inc. All rights reserved push (@newfstab, "$oldfstabentry\n"); push (@newfstab, "$newfstabentry\n"); push (@newfstab, "$migratedfstabentry\n"); close($filehandle); if ($oldfstabentry eq ''){ die "Could not find $oldfs in /etc/fstab\n";} if ($newfstabentry eq ''){ die "Could not find $newfs in /etc/fstab\n";} my @out=`umount '$newfs'`; if ($? == 0) { print "$newfs unmounted\n";} else { print "Unable to unmount $newfs\n"; exit 1;} @out=`umount '$oldfs'`; if ($? == 0) { print "$oldfs unmounted\n";} else { print "Unable to unmount $oldfs\n"; exit 1;} system("cp /etc/fstab /etc/fstab.bak"); open ($filehandle, ">", '/etc/fstab') or die "Could not open /etc/fstab for writing\n"; for my $line (@newfstab) { print $filehandle $line;} close($filehandle); @out=`mount '$oldfs'`; if ($? == 0) { print "Mounted updated $oldfs\n"; exit 0;} else{ print "Unable to mount updated $oldfs\n"; exit 1;} exit 0;Come esempio di utilizzo di questo script, si supponga che i dati in
/oradataviene migrato in/neworadatae./logsviene migrato in/newlogs. Uno dei metodi più semplici per eseguire questa attività consiste nell'utilizzare una semplice operazione di copia dei file per riportare la nuova periferica al punto di montaggio originale. -
Si supponga che i file system vecchi e nuovi siano presenti in
/etc/fstabarchiviare come segue:cluster01:/vol_oradata /oradata nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 cluster01:/vol_logs /logs nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 cluster01:/vol_neworadata /neworadata nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 cluster01:/vol_newlogs /newlogs nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0
-
Quando viene eseguito, questo script smonta il file system corrente e lo sostituisce con il nuovo:
[root@jfsc3 scripts]# ./swap.fs.pl /oradata,/neworadata /neworadata unmounted /oradata unmounted Mounted updated /oradata [root@jfsc3 scripts]# ./swap.fs.pl /logs,/newlogs /newlogs unmounted /logs unmounted Mounted updated /logs
-
Lo script aggiorna anche
/etc/fstabfile di conseguenza. Nell'esempio illustrato, sono incluse le seguenti modifiche:#Removed by swap script cluster01:/vol_oradata /oradata nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 #Removed by swap script cluster01:/vol_neworadata /neworadata nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 cluster01:/vol_neworadata /oradata nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 #Removed by swap script cluster01:/vol_logs /logs nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 #Removed by swap script cluster01:/vol_newlogs /newlogs nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0 cluster01:/vol_newlogs /logs nfs rw,bg,vers=3,rsize=65536,wsize=65536 0 0
Migrazione automatizzata del database
In questo esempio viene illustrato l'utilizzo di script di arresto, avvio e sostituzione del file system per automatizzare completamente la migrazione.
#! /usr/bin/perl
use strict;
#use warnings;
my $oraclesid=$ARGV[0];
my @oldfs;
my @newfs;
my $x=1;
while ($x < scalar(@ARGV)) {
($oldfs[$x-1], $newfs[$x-1]) = split (',',$ARGV[$x]);
$x+=1;}
my @out=`./dbshut.pl '$oraclesid'`;
print @out;
if ($? ne 0) {
print "Failed to shut down database\n";
exit 0;}
$x=0;
while ($x < scalar(@oldfs)) {
my @out=`./mk.fs.readonly.pl '$oldfs[$x]'`;
if ($? ne 0) {
print "Failed to make filesystem $oldfs[$x] readonly\n";
exit 0;}
$x+=1;}
$x=0;
while ($x < scalar(@oldfs)) {
my @out=`rsync -rlpogt --stats --progress --exclude='.snapshot' '$oldfs[$x]/' '/$newfs[$x]/'`;
print @out;
if ($? ne 0) {
print "Failed to copy filesystem $oldfs[$x] to $newfs[$x]\n";
exit 0;}
else {
print "Succesfully replicated filesystem $oldfs[$x] to $newfs[$x]\n";}
$x+=1;}
$x=0;
while ($x < scalar(@oldfs)) {
print "swap $x $oldfs[$x] $newfs[$x]\n";
my @out=`./swap.fs.pl '$oldfs[$x],$newfs[$x]'`;
print @out;
if ($? ne 0) {
print "Failed to swap filesystem $oldfs[$x] for $newfs[$x]\n";
exit 1;}
else {
print "Swapped filesystem $oldfs[$x] for $newfs[$x]\n";}
$x+=1;}
my @out=`./dbstart.pl '$oraclesid'`;
print @out;
Visualizzare le posizioni dei file
Questo script raccoglie una serie di parametri critici del database e li stampa in un formato di facile lettura. Questo script può essere utile quando si esaminano i layout dei dati. Inoltre, lo script può essere modificato per altri usi.
#! /usr/bin/perl
#use strict;
#use warnings;
my $oraclesid=$ARGV[0];
my $oracleuser='oracle';
my @out;
sub dosql{
my $command = @_[0];
my @lines;
my $uid=$<;
if ($uid == 0) {
@lines=`su - $oracleuser -c "export ORAENV_ASK=NO;export ORACLE_SID=$oraclesid;. oraenv -s << EOF1
EOF1
sqlplus -S / as sysdba << EOF2
set heading off
$command
EOF2
"
`;}
else {
$command=~s/\\\\\\/\\/g;
@lines=`export ORAENV_ASK=NO;export ORACLE_SID=$oraclesid;. oraenv -s << EOF1
EOF1
sqlplus -S / as sysdba << EOF2
set heading off
$command
EOF2
`;};
return @lines}
print "\n";
@out=dosql('select name from v\\\\\$datafile;');
print "$oraclesid datafiles:\n";
for $line (@out) {
chomp($line);
if (length($line)>0) {print "$line\n";}}
print "\n";
@out=dosql('select member from v\\\\\$logfile;');
print "$oraclesid redo logs:\n";
for $line (@out) {
chomp($line);
if (length($line)>0) {print "$line\n";}}
print "\n";
@out=dosql('select name from v\\\\\$tempfile;');
print "$oraclesid temp datafiles:\n";
for $line (@out) {
chomp($line);
if (length($line)>0) {print "$line\n";}}
print "\n";
@out=dosql('show parameter spfile;');
print "$oraclesid spfile\n";
for $line (@out) {
chomp($line);
if (length($line)>0) {print "$line\n";}}
print "\n";
@out=dosql('select name||\' \'||value from v\\\\\$parameter where isdefault=\'FALSE\';');
print "$oraclesid key parameters\n";
for $line (@out) {
chomp($line);
if ($line =~ /control_files/) {print "$line\n";}
if ($line =~ /db_create/) {print "$line\n";}
if ($line =~ /db_file_name_convert/) {print "$line\n";}
if ($line =~ /log_archive_dest/) {print "$line\n";}}
if ($line =~ /log_file_name_convert/) {print "$line\n";}
if ($line =~ /pdb_file_name_convert/) {print "$line\n";}
if ($line =~ /spfile/) {print "$line\n";}
print "\n";
Pulitura della migrazione ASM
#! /usr/bin/perl
#use strict;
#use warnings;
my $oraclesid=$ARGV[0];
my $oracleuser='oracle';
my @out;
sub dosql{
my $command = @_[0];
my @lines;
my $uid=$<;
if ($uid == 0) {
@lines=`su - $oracleuser -c "export ORAENV_ASK=NO;export ORACLE_SID=$oraclesid;. oraenv -s << EOF1
EOF1
sqlplus -S / as sysdba << EOF2
set heading off
$command
EOF2
"
`;}
else {
$command=~s/\\\\\\/\\/g;
@lines=`export ORAENV_ASK=NO;export ORACLE_SID=$oraclesid;. oraenv -s << EOF1
EOF1
sqlplus -S / as sysdba << EOF2
set heading off
$command
EOF2
`;}
return @lines}
print "\n";
@out=dosql('select name from v\\\\\$datafile;');
print @out;
print "shutdown immediate;\n";
print "startup mount;\n";
print "\n";
for $line (@out) {
if (length($line) > 1) {
chomp($line);
($first, $second,$third,$fourth)=split('_',$line);
$fourth =~ s/^TS-//;
$newname=lc("$fourth.dbf");
$path2file=$line;
$path2file=~ /(^.*.\/)/;
print "host mv $line $1$newname\n";}}
print "\n";
for $line (@out) {
if (length($line) > 1) {
chomp($line);
($first, $second,$third,$fourth)=split('_',$line);
$fourth =~ s/^TS-//;
$newname=lc("$fourth.dbf");
$path2file=$line;
$path2file=~ /(^.*.\/)/;
print "alter database rename file '$line' to '$1$newname';\n";}}
print "alter database open;\n";
print "\n";
Conversione del nome da ASM a file system
set serveroutput on;
set wrap off;
declare
cursor df is select file#, name from v$datafile;
cursor tf is select file#, name from v$tempfile;
cursor lf is select member from v$logfile;
firstline boolean := true;
begin
dbms_output.put_line(CHR(13));
dbms_output.put_line('Parameters for log file conversion:');
dbms_output.put_line(CHR(13));
dbms_output.put('*.log_file_name_convert = ');
for lfrec in lf loop
if (firstline = true) then
dbms_output.put('''' || lfrec.member || ''', ');
dbms_output.put('''/NEW_PATH/' || regexp_replace(lfrec.member,'^.*./','') || '''');
else
dbms_output.put(',''' || lfrec.member || ''', ');
dbms_output.put('''/NEW_PATH/' || regexp_replace(lfrec.member,'^.*./','') || '''');
end if;
firstline:=false;
end loop;
dbms_output.put_line(CHR(13));
dbms_output.put_line(CHR(13));
dbms_output.put_line('rman duplication script:');
dbms_output.put_line(CHR(13));
dbms_output.put_line('run');
dbms_output.put_line('{');
for dfrec in df loop
dbms_output.put_line('set newname for datafile ' ||
dfrec.file# || ' to ''' || dfrec.name ||''';');
end loop;
for tfrec in tf loop
dbms_output.put_line('set newname for tempfile ' ||
tfrec.file# || ' to ''' || tfrec.name ||''';');
end loop;
dbms_output.put_line('duplicate target database for standby backup location INSERT_PATH_HERE;');
dbms_output.put_line('}');
end;
/
Riprodurre i log sul database
Questo script accetta un singolo argomento di un SID Oracle per un database in modalità mount e tenta di riprodurre tutti i log di archivio attualmente disponibili.
#! /usr/bin/perl
use strict;
my $oraclesid=$ARGV[0];
my $oracleuser='oracle';
84 Migration of Oracle Databases to NetApp Storage Systems © 2021 NetApp, Inc. All rights reserved
my $uid = $<;
my @out;
if ($uid == 0) {
@out=`su - $oracleuser -c '. oraenv << EOF1
$oraclesid
EOF1
sqlplus / as sysdba << EOF2
recover database until cancel;
auto
EOF2
'
`;}
else {
@out=`. oraenv << EOF1
$oraclesid
EOF1
sqlplus / as sysdba << EOF2
recover database until cancel;
auto
EOF2
`;
}
print @out;
Riprodurre i registri sul database di standby
Questo script è identico allo script precedente, tranne che è progettato per un database di standby.
#! /usr/bin/perl
use strict;
my $oraclesid=$ARGV[0];
my $oracleuser='oracle';
my $uid = $<;
my @out;
if ($uid == 0) {
@out=`su - $oracleuser -c '. oraenv << EOF1
$oraclesid
EOF1
sqlplus / as sysdba << EOF2
recover standby database until cancel;
auto
EOF2
'
`;}
else {
@out=`. oraenv << EOF1
$oraclesid
EOF1
sqlplus / as sysdba << EOF2
recover standby database until cancel;
auto
EOF2
`;
}
print @out;