Skip to content

Commit

Permalink
Modify ora2pg script to return 0 on success, 1 on any fatal error and…
Browse files Browse the repository at this point in the history
… 2 when a child process die is detected. Change the way the generic configuration file is handle during project initialisation. You can use -c option to copy your own into the project directory. If the file has the .dist extension, ora2pg will apply the generic configuration on it. Thanks to Kuppusamy Ravindran for the report and features request.
  • Loading branch information
darold committed Feb 12, 2015
1 parent 3fa690a commit a1e4250
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 26 deletions.
9 changes: 9 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ CONFIGURATION
--project_base DIR : define the base dir for ora2pg project trees. Default
is current directory.

ora2pg will return 0 on success, 1 on error. It will return 2 when a
child process have been interrupted and you've got the warning message:
WARNING: an error occurs during data export. Please check what's happen.

It is possible to add your own custom option(s) in the Perl script
ora2pg as any configuration directive from ora2pg.conf can be passed in
lower case to the new Ora2Pg object instance. See ora2pg code on how to
Expand Down Expand Up @@ -312,6 +316,11 @@ CONFIGURATION
contains the code ported to PostgreSQL. The reports/ directory will
contains the html reports with the migration cost assessment.

If you want to use your own default config file, use the -c option to
give the path to that file. Rename it with .dist suffix if you want
ora2pg to apply the generic configuration values otherwise, the
configuration file will be copied untouched.

Oracle database connection
There's 5 configuration directives to control the access to the Oracle
database.
Expand Down
20 changes: 15 additions & 5 deletions doc/Ora2Pg.pod
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ Here are all command line parameters available when using ora2pg:
--project_base DIR : define the base dir for ora2pg project trees. Default
is current directory.

ora2pg will return 0 on success, 1 on error. It will return 2 when a child
process have been interrupted and you've got the warning message:
WARNING: an error occurs during data export. Please check what's happen.


It is possible to add your own custom option(s) in the Perl script ora2pg as any
configuration directive from ora2pg.conf can be passed in lower case to the new
Expand Down Expand Up @@ -310,11 +314,17 @@ of the command usage:
Generating generic configuration file
Creating script export_schema.sh to automate all exports.

It create a generic config file where you just have to define the Oracle database
connection and a shell script called export_schema.sh. The sources/ directory will
contains the Oracle code, the schema/ will contains the code ported to PostgreSQL.
The reports/ directory will contains the html reports with the migration cost
assessment.
It create a generic config file where you just have to define the Oracle
database connection and a shell script called export_schema.sh. The sources/
directory will contains the Oracle code, the schema/ will contains the code
ported to PostgreSQL. The reports/ directory will contains the html reports
with the migration cost assessment.

If you want to use your own default config file, use the -c option to give
the path to that file. Rename it with .dist suffix if you want ora2pg to
apply the generic configuration values otherwise, the configuration file
will be copied untouched.


=head2 Oracle database connection

Expand Down
21 changes: 15 additions & 6 deletions doc/ora2pg.3
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
.\" ========================================================================
.\"
.IX Title "ORA2PG 1"
.TH ORA2PG 1 "2015-01-29" "perl v5.14.2" "User Contributed Perl Documentation"
.TH ORA2PG 1 "2015-02-12" "perl v5.14.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down Expand Up @@ -397,6 +397,10 @@ Here are all command line parameters available when using ora2pg:
\& is current directory.
.Ve
.PP
ora2pg will return 0 on success, 1 on error. It will return 2 when a child
process have been interrupted and you've got the warning message:
\s-1WARNING:\s0 an error occurs during data export. Please check what's happen.
.PP
It is possible to add your own custom option(s) in the Perl script ora2pg as any
configuration directive from ora2pg.conf can be passed in lower case to the new
Ora2Pg object instance. See ora2pg code on how to add your own option.
Expand Down Expand Up @@ -445,11 +449,16 @@ of the command usage:
\& Creating script export_schema.sh to automate all exports.
.Ve
.PP
It create a generic config file where you just have to define the Oracle database
connection and a shell script called export_schema.sh. The sources/ directory will
contains the Oracle code, the schema/ will contains the code ported to PostgreSQL.
The reports/ directory will contains the html reports with the migration cost
assessment.
It create a generic config file where you just have to define the Oracle
database connection and a shell script called export_schema.sh. The sources/
directory will contains the Oracle code, the schema/ will contains the code
ported to PostgreSQL. The reports/ directory will contains the html reports
with the migration cost assessment.
.PP
If you want to use your own default config file, use the \-c option to give
the path to that file. Rename it with .dist suffix if you want ora2pg to
apply the generic configuration values otherwise, the configuration file
will be copied untouched.
.SS "Oracle database connection"
.IX Subsection "Oracle database connection"
There's 5 configuration directives to control the access to the Oracle database.
Expand Down
68 changes: 53 additions & 15 deletions scripts/ora2pg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ my $VERSION = '15.1';
$| = 1;

my $CONFIG_FILE = '/etc/ora2pg/ora2pg.conf';
my $FILE_CONF = '';
my $DEBUG = 0;
my $QUIET = 0;
my $HELP = 0;
Expand Down Expand Up @@ -81,7 +82,7 @@ my $TMP_DIR = File::Spec->tmpdir() || '/tmp';
GetOptions (
'a|allow=s' => \$ALLOW,
'b|basedir=s' => \$OUTDIR,
'c|conf=s' => \$CONFIG_FILE,
'c|conf=s' => \$FILE_CONF,
'd|debug!' => \$DEBUG,
'e|exclude=s' => \$EXCLUDE,
'h|help!' => \$HELP,
Expand Down Expand Up @@ -134,17 +135,24 @@ if ($CREATE_PROJECT) {

# Clean temporary files
unless(opendir(DIR, "$TMP_DIR")) {
die "Error: can't opendir $TMP_DIR: $!";
print "FATAL: can't opendir $TMP_DIR: $!\n";
exit 1;
}
my @files = grep { $_ =~ /^tmp_ora2pg.*$/ } readdir(DIR);
closedir DIR;
foreach (@files) {
unlink("$TMP_DIR/$_\n");
if (not unlink("$TMP_DIR/$_\n")){
print "FATAL: can not remove old temporary files $TMP_DIR/$_\n";
exit 1;
}
}


# Check configuration file
if (! -e $CONFIG_FILE) {
if ($FILE_CONF && ! -e $FILE_CONF) {
print "FATAL: can't find configuration file $FILE_CONF\n";
&usage();
} elsif (! -e $CONFIG_FILE) {
print "FATAL: can't find configuration file $CONFIG_FILE\n";
&usage();
}
Expand Down Expand Up @@ -176,7 +184,8 @@ sub getout

# Cleaning temporary files
unless(opendir(DIR, "$TMP_DIR")) {
die "Error: can't opendir $TMP_DIR: $!";
print "FATAL: can't opendir $TMP_DIR: $!\n";
exit 1;
}
my @files = grep { $_ =~ /^tmp_ora2pg.*$/ } readdir(DIR);
closedir DIR;
Expand All @@ -191,7 +200,7 @@ $SIG{TERM} = \&getout;

# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
config => $CONFIG_FILE,
config => $FILE_CONF || $CONFIG_FILE,
type => $EXPORT_TYPE,
debug => $DEBUG,
logfile=> $LOGFILE,
Expand Down Expand Up @@ -228,12 +237,14 @@ if ( ($EXPORT_TYPE !~ /^SHOW_/i) && !$INPUT_FILE ) {

# Check if error occurs during data export
unless(opendir(DIR, "$TMP_DIR")) {
die "Error: can't opendir $TMP_DIR: $!";
print "FATAL: can't opendir $TMP_DIR: $!\n";
exit 1;
}
my @files = grep { $_ =~ /^tmp_ora2pg.*$/ } readdir(DIR);
@files = grep { $_ =~ /^tmp_ora2pg.*$/ } readdir(DIR);
closedir DIR;
if ($#files >= 0) {
print STDERR "\nWARNING: an error occurs during data export. Please check what's happen.\n\n";
exit 2;
}

exit(0);
Expand Down Expand Up @@ -296,8 +307,12 @@ Usage: ora2pg [-dhpqv --estimate_cost --dump_as_html] [--option value]
See full documentation at http://ora2pg.darold.net/ for more help or see
manpage with 'man ora2pg'.
ora2pg will return 0 on success, 1 on error. It will return 2 when a child
process have been interrupted and you've got the warning message:
WARNING: an error occurs during data export. Please check what's happen.
};
exit 0;
exit 1;

'init_project=s' => \$CREATE_PROJECT,
'project_base=s' => \$PROJECT_BASE,
Expand All @@ -310,9 +325,22 @@ sub create_project
{
my ($create_project, $project_base) = @_;

# Look at default configuration file to use
my $conf_file = $CONFIG_FILE . '.dist';
if ($FILE_CONF) {
# Use file given in parameter
$conf_file = $FILE_CONF;
}
if (!-f $conf_file || -z $conf_file) {
print "FATAL: file $conf_file does not exists.\n";
exit 1;
}
# Build entire project tree
my $base_path = $project_base . '/' . $create_project;
die "FATAL: project directory exists $base_path\n" if (-e $base_path);
if (-e $base_path) {
print "FATAL: project directory exists $base_path\n";
exit 1;
}
mkdir("$base_path");
print "$base_path/\n";
mkdir("$base_path/schema");
Expand Down Expand Up @@ -342,21 +370,31 @@ sub create_project

# Copy configuration file and transform it as a generic one
print "Generating generic configuration file\n";
my $conf_file = '/etc/ora2pg/ora2pg.conf.dist';
if (open(IN, "$conf_file")) {
my @cf = <IN>;
close(IN);
&make_config_generic(\@cf);
open(OUT, ">$base_path/config/ora2pg.conf") or die "FATAL: can't write to file $base_path/config/ora2pg.conf\n";
# Create a generic configuration file only if it has the .dist extension
# otherwise use the configuration given at command line (-c option)
if ($conf_file =~ /\.dist/) {
&make_config_generic(\@cf);
}
unless(open(OUT, ">$base_path/config/ora2pg.conf")) {
print "FATAL: can't write to file $base_path/config/ora2pg.conf\n";
exit 1;
}
print OUT @cf;
close(OUT);
} else {
print "ERROR: file $CONFIG_FILE does not exists.\n";
print "FATAL: can not read file $conf_file, $!.\n";
exit 1;
}

# Generate shell script to execute all export
print "Creating script export_schema.sh to automate all exports.\n";
open(OUT, "> $base_path/export_schema.sh") or die "FATAL: Can't write to file $base_path/export_schema.sh\n";
unless(open(OUT, "> $base_path/export_schema.sh")) {
print "FATAL: Can't write to file $base_path/export_schema.sh\n";
exit 1;
}
print OUT qq{#!/bin/sh
#-------------------------------------------------------------------------------
#
Expand Down

0 comments on commit a1e4250

Please sign in to comment.