gpt4 book ai didi

oracle - 如何将oracle转储从ec2实例导入到AWS中的RDS

转载 作者:行者123 更新时间:2023-12-02 09:40:25 24 4
gpt4 key购买 nike

我是 AWS 中的 RDS 新手。我有一个驻留在 ec2 实例 上的数据库转储文件。我有几个问题:

  1. 如何将转储文件移至 RDS 实例
  2. 执行此操作的先决条件是什么。我的意思是我需要安装什么客户端才能执行此操作。

感谢任何帮助或领导。

谢谢

最佳答案

我同意官方文档在Oracle导入转储文件时相当困惑且不清楚。

亚马逊还有另一个文档分步说明,网址为 http://d0.awsstatic.com/whitepapers/strategies-for-migrating-oracle-database-to-aws.pdf以及 http://fr.slideshare.net/AmazonWebServices/dat308-28616289 的演示

基本上这个过程是:

  1. 您需要将文件传输到 Amazon RDS 数据库实例 - Amazon 提供了已定义的 DATA_PUMP_DIR,因此您需要一个脚本将转储文件从 EC2 实例移动到 Amazon RDS DATA_PUMP_DIR

以下脚本可以为您完成这项工作

use DBI;
use warnings;
use strict;

# RDS instance info
my $RDS_PORT=1521;
my $RDS_HOST="<my rds instance>";
my $RDS_LOGIN="<myuser>/*******";
my $RDS_SID="<ORCL_LIKE>";

#The $ARGV[0] is a parameter you pass into the script
my $dirname = "DATA_PUMP_DIR";
my $fname = $ARGV[0];

my $data = "dummy";
my $chunk = 8192;

my $sql_open = "BEGIN perl_global.fh := utl_file.fopen(:dirname, :fname, 'wb', :chunk); END;";
my $sql_write = "BEGIN utl_file.put_raw(perl_global.fh, :data, true); END;";
my $sql_close = "BEGIN utl_file.fclose(perl_global.fh); END;";
my $sql_global = "create or replace package perl_global as fh utl_file.file_type; end;";

my $conn = DBI->connect('dbi:Oracle:host='.$RDS_HOST.';sid='.$RDS_SID.';port='.$RDS_PORT,$RDS_LOGIN, '') || die ( $DBI::errstr . "\n");

my $updated=$conn->do($sql_global);
my $stmt = $conn->prepare ($sql_open);
$stmt->bind_param_inout(":dirname", \$dirname, 12);
$stmt->bind_param_inout(":fname", \$fname, 12);
$stmt->bind_param_inout(":chunk", \$chunk, 4);
$stmt->execute() || die ( $DBI::errstr . "\n");

open (INF, $fname) || die "\nCan't open $fname for reading: $!\n";
binmode(INF);
$stmt = $conn->prepare ($sql_write);
my %attrib = ('ora_type','24');
my $val=1;
while ($val> 0) {
$val = read (INF, $data, $chunk);
$stmt->bind_param(":data", $data , \%attrib);
$stmt->execute() || die ( $DBI::errstr . "\n") ; };
die "Problem copying: $!\n" if $!;
close INF || die "Can't close $fname: $!\n";
$stmt = $conn->prepare ($sql_close);
$stmt->execute() || die ( $DBI::errstr . "\n") ;

确保所有文件均已导入

select * from table(RDSADMIN.RDS_FILE_UTIL.LISTDIR('DATA_PUMP_DIR')) order by FILENAME;
  • 将数据从转储文件导入到 RDS 实例
  • 您可以运行 impdp 或者使用 PL/SQL 脚本提交作业

    declare
    h1 NUMBER;
    begin

    h1 := dbms_datapump.open (operation => 'IMPORT', job_mode => 'FULL', job_name => 'IMPORT_DUMP', version => 'COMPATIBLE');
    dbms_datapump.add_file(handle => h1, filename => 'IMPORT.LOG', directory => 'DATA_PUMP_DIR', filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);

    -- optional
    dbms_datapump.set_parallel(handle => h1, degree => 8);

    dbms_datapump.add_file(handle => h1, filename => 'IMPORT.LOG', directory => 'DATA_PUMP_DIR', filetype => 3);
    dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 0);

    dbms_datapump.add_file(handle => h1, filename => 'HOST_01.dmp', directory => 'DATA_PUMP_DIR', filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE);
    <repeat the add_file for all your files>

    dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA', value => 1);
    dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD', value => 'AUTOMATIC');
    dbms_datapump.set_parameter(handle => h1, name => 'REUSE_DATAFILES', value => 0);
    dbms_datapump.set_parameter(handle => h1, name => 'SKIP_UNSUSABLE_INDEXES', value => 0);

    dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
    dbms_datapump.detach(handle => h1);
    end;
    /

    导入已完成,数据可存入您的 RDS 数据库。您可以从 DATA_PUMP_DIR 清理文件,以下脚本即可完成该工作

    -- remove file from data pump dir
    begin
    utl_file.fremove ('DATA_PUMP_DIR','import.log');
    utl_file.fremove ('DATA_PUMP_DIR','<name of file>.dmp');
    end fremove;
    /

    关于oracle - 如何将oracle转储从ec2实例导入到AWS中的RDS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23486198/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com