샘플 스크립트
제공되는 스크립트는 다양한 OS 및 데이터베이스 작업을 스크립팅하는 방법의 예로 제공됩니다. 그들은 있는 그대로 제공됩니다. 특정 절차에 대한 지원이 필요한 경우 NetApp 또는 NetApp 리셀러에게 문의하십시오.
데이터베이스 종료
다음 Perl 스크립트는 Oracle SID의 단일 인수를 사용하고 데이터베이스를 종료합니다. Oracle 사용자 또는 루트로 실행할 수 있습니다.
#! /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;}
데이터베이스 시작
다음 Perl 스크립트는 Oracle SID의 단일 인수를 사용하고 데이터베이스를 종료합니다. Oracle 사용자 또는 루트로 실행할 수 있습니다.
#! /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;}
파일 시스템을 읽기 전용으로 변환합니다
다음 스크립트는 파일 시스템 인수를 사용하여 읽기 전용으로 마운트 해제 및 다시 마운트하려고 시도합니다. 이렇게 하면 데이터를 복제하기 위해 파일 시스템을 사용할 수 있어야 하지만 우발적인 손상으로부터 보호해야 하는 마이그레이션 프로세스 중에 유용합니다.
#! /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;
파일 시스템을 교체합니다
다음 스크립트 예제는 파일 시스템 하나를 다른 파일 시스템으로 바꾸는 데 사용됩니다. '/etc/fstab' 파일을 편집하므로 루트로 실행해야 합니다. 이전 파일 시스템과 새 파일 시스템의 쉼표로 구분된 단일 인수를 사용할 수 있습니다.
-
파일 시스템을 교체하려면 다음 스크립트를 실행합니다.
#! /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;
이 스크립트 사용의 예로, 의 데이터를 가정합니다
/oradata
로 마이그레이션됩니다/neworadata
및/logs
로 마이그레이션됩니다/newlogs
. 이 작업을 수행하는 가장 간단한 방법 중 하나는 간단한 파일 복제 작업을 사용하여 새 디바이스를 원래 마운트 지점으로 재배치하는 것입니다. -
에 이전 파일 시스템과 새 파일 시스템이 있다고 가정합니다
/etc/fstab
다음과 같은 파일: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
-
이 스크립트를 실행하면 현재 파일 시스템을 마운트 해제하고 새 파일 시스템으로 대체합니다.
[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
-
스크립트도 를 업데이트합니다
/etc/fstab
그에 따라 보관합니다. 여기에 표시된 예에서는 다음과 같은 변경 사항이 포함되어 있습니다.#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
자동화된 데이터베이스 마이그레이션
이 예제에서는 마이그레이션을 완전히 자동화하기 위해 종료, 시작 및 파일 시스템 교체 스크립트를 사용하는 방법을 보여 줍니다.
#! /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;
파일 위치를 표시합니다
이 스크립트는 많은 중요한 데이터베이스 매개 변수를 수집하여 읽기 쉬운 형식으로 인쇄합니다. 이 스크립트는 데이터 레이아웃을 검토할 때 유용할 수 있습니다. 또한 스크립트를 다른 용도로 수정할 수도 있습니다.
#! /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";
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";
ASM에서 파일 시스템 이름으로 변환
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; /
데이터베이스에서 로그를 재생합니다
이 스크립트는 마운트 모드에 있는 데이터베이스에 대해 Oracle SID의 단일 인수를 허용하고 현재 사용 가능한 모든 아카이브 로그를 재생하려고 시도합니다.
#! /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;
대기 데이터베이스에서 로그를 재생합니다
이 스크립트는 대기 데이터베이스용으로 설계되었다는 점을 제외하고 위의 스크립트와 동일합니다.
#! /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;