diff --git a/CHANGELOG.md b/CHANGELOG.md index f7cc6be..3aa6119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.4.23 + +### Added +- Support for Postgresql ( dSource / VDB ) +- Data patch flag added for Oracle VDBs + ## 2.4.22.1 ### Changes diff --git a/bin/dx_ctl_dsource.pl b/bin/dx_ctl_dsource.pl index 77bcc67..4ac758e 100644 --- a/bin/dx_ctl_dsource.pl +++ b/bin/dx_ctl_dsource.pl @@ -89,6 +89,17 @@ 'uniqname=s' => \(my $uniqname), 'template=s' => \(my $template), 'oracledbtype=s' => \(my $oracledbtype), + 'sourcehostname=s' => \(my $sourcehostname), + 'sourceport=n' => \(my $sourceport), + 'ingestiontype=s' => \(my $ingestiontype), + 'singledbname=s' => \(my $singledbname), + 'stagingport=n' => \(my $stagingport), + 'dumpdir=s' => \(my $dumpdir), + 'restorejobs=n' => \(my $restorejobs), + 'dumpjobs=n' => \(my $dumpjobs), + 'customparameters=s@' => \(my $customparameters), + 'backup_dir_log=s' => \(my $backup_dir_log), + 'keepinsync=s' => \(my $keepinsync), 'dever=s' => \(my $dever), 'debug:n' => \(my $debug), 'all' => (\my $all), @@ -134,13 +145,13 @@ exit (1); } - if ( defined ($type) && ( ! ( ( lc $type eq 'oracle') || ( lc $type eq 'sybase') || ( lc $type eq 'mssql') || ( lc $type eq 'vfiles') || ( lc $type eq 'db2') ) ) ) { + if ( defined ($type) && ( ! ( ( lc $type eq 'oracle') || ( lc $type eq 'sybase') || ( lc $type eq 'mssql') || ( lc $type eq 'vfiles') || ( lc $type eq 'db2') || ( lc $type eq 'postgresql') ) ) ) { print "Option -type has invalid parameter - $type \n"; pod2usage(-verbose => 1, -input=>\*DATA); exit (1); } - if (((lc $type eq 'vfiles') || (lc $type eq 'db2')) && (lc $action eq 'attach')) { + if (((lc $type eq 'vfiles') || ( lc $type eq 'db2') || ( lc $type eq 'postgresql')) && (lc $action eq 'attach')) { print "Can't attach $type dSource\n"; exit (1); } @@ -153,7 +164,7 @@ exit (1); } } - elsif ( ( lc $type ne 'db2' ) && ( ! ( defined($type) && defined($sourcename) && defined($dsourcename) && defined($source_os_user) && defined($group) ) ) ) { + elsif ( ( lc $type ne 'postgresql' ) && ( lc $type ne 'db2' ) && ( ! ( defined($type) && defined($sourcename) && defined($dsourcename) && defined($source_os_user) && defined($group) ) ) ) { print "Options -sourcename, -dsourcename, -group, -source_os_user are required. \n"; pod2usage(-verbose => 1, -input=>\*DATA); exit (1); @@ -175,7 +186,7 @@ } else { - if (defined ($type) && ((lc $type eq 'vfiles') || (lc $type eq 'db2') ) && (lc $action eq 'detach')) { + if (defined ($type) && ((lc $type eq 'vfiles') || (lc $type eq 'db2') || ( lc $type eq 'postgresql') ) && (lc $action eq 'detach')) { print "Can't deattach $type dSource\n"; exit (1); } @@ -229,6 +240,12 @@ pod2usage(-verbose => 1, -input=>\*DATA); exit (1) } + } elsif (lc $type eq 'postgresql') { + if ( lc $ingestiontype ne 'externalbackup' ) { + print "Options -dbuser and -password are required for non vFiles dsources. \n"; + pod2usage(-verbose => 1, -input=>\*DATA); + exit (1); + } } else { print "Options -dbuser and -password are required for non vFiles dsources. \n"; pod2usage(-verbose => 1, -input=>\*DATA); @@ -410,6 +427,17 @@ } $jobno = $db->addSource($sourcename,$sourceinst,$sourceenv,$source_os_user,$dbuser,$password,$dsourcename,$group,$logsync,$stageenv,$stageinst,$stage_os_user, $backup_dir, $hadr); } + elsif ($type eq 'postgresql') { + my $db = new PostgresVDB_obj($engine_obj,$debug); + if (addhooks($hooks, $db, $presync, $postsync)) { + $ret = $ret + 1; + last; + } + $jobno = $db->addSource($sourcename,$dbuser,$password,$dsourcename,$group,$logsync,$stageenv,$stageinst,$stage_os_user, $backup_dir, + $sourcehostname, $sourceport, $ingestiontype, $dumpdir, $restorejobs, $dumpjobs, $stagingport, $singledbname, $mountbase, + $customparameters, $backup_dir, $backup_dir_log, $keepinsync); + + } # we are adding only one dSource - so one job $ret = $ret + Toolkit_helpers::waitForAction($engine_obj, $jobno, "Action completed with success", "There were problems with dSource action"); @@ -508,6 +536,17 @@ =head1 SYNOPSIS [-postsync [hookname,]template|filename[,OS_shell] ] [-stagingpush] [-oracledbtype nonmt|cdb|pdb] + [-customparameters (param_name=value)|(#param_name)] + [-ingestiontype single|initalized|externalbackup ] + [-sourcehostname hostname ] + [-sourceport xxx] + [-singledbname dbname] + [-stagingport xxx ] + [-dumpdir directory] + [-restorejobs x] + [-dumpjobs x] + [-backup_dir_log directory] + [-keepinsync yes|no] [-debug ] [-version ] [-help|? ] @@ -659,6 +698,40 @@ =head2 dSource arguments =item B<-hooks path_to_hooks> Import hooks exported using dx_get_hooks +=item B<-customparameters (param_name=value)|(#param_name)> +Provide a custom parameter for Postgresql. For more then one parameter, use -customparameters multiple times. +To comment an existing variable inside Postgresql VDB, put a # sign before a parameter. + +=item B<-ingestiontype single|initalized|externalbackup > +Postgresql dSource ingestion type + +=item B<-sourcehostname hostname> +Postgresql dSource source host + +=item B<-sourceport xxx> +Postgresql dSource source port + +=item B<-singledbname dbname> +Postgresql dSource single database name + +=item B<-stagingport xxx> +Postgresql dSource staging port + +=item B<-dumpdir directory> +Postgresql dSource single database dump directory + +=item B<-restorejobs x> +Postgresql dSource single database number of restore jobs + +=item B<-dumpjobs x> +Postgresql dSource single database number of dump joba + +=item B<-backup_dir_log> +Location of WAL logs for external Postgresql ingestion + +=item B<-keepinsync yes|no-> +Keep a dSource in sync using Postgresql replication. If value set to yes, replication parameters are mandatory + =back =head2 Hooks @@ -808,6 +881,27 @@ =head1 EXAMPLES Waiting for all actions to complete. Parent action is ACTION-2919 Action completed with success +Adding a Posgresql dSource using Delphix initialized backup + + dx_ctl_dsource -d dxtest -action create -group "Untitled" -creategroup -dsourcename "postdsource" -type postgresql -sourcename "postdsource" -stageinst "Postgres vFiles (15.2)" \ + -stageenv "POSTSTG" -stage_os_user "postgres" -mountbase "/mnt/provision/postdsource" -password xxxxxxxxx -stagingport 5433 -ingestiontype initiated \ + -dbuser "delphix" -sourcehostname "sourceserver" -sourceport 5432 -customparameters "deadlock_timeout=123s" + Waiting for all actions to complete. Parent action is ACTION-734 + Action completed with success + +Adding a Posgresql dSource using single database ingestion + +dx_ctl_dsource -d dxtest -action create -group "Untitled" -creategroup -dsourcename "postdsource" -type postgresql -sourcename "postdsource_cluster" -stageinst "Postgres vFiles (15.2)" \ + -stageenv "POSTSTG" -mountbase "/mnt/provision/pioro" -dbuser "postgres" -password xxxxxxxxx -stagingport 5433 -sourcehostname "sourceserver" \ + -ingestiontype single -sourceport 5432 -singledbname "singleDB" -dumpdir "/home/postgres" -restorejobs 2 -dumpjobs 2 + +Adding a Postgresql dSource using external backup + + dx_ctl_dsource -d dxtest -action create -group "Untitled" -creategroup -dsourcename "extbac" -type postgresql -sourcename "extbac" -stageinst "Postgres vFiles (15.2)" \ + -stageenv "POSTSTG" -mountbase "/mnt/provision/extbac" -stagingport 5434 -ingestiontype externalbackup \ + -backup_dir "/home/postgres/backup" -backup_dir_log "/home/postgres/backup" -keepinsync no + + Updating a backup path and validated sync mode for Sybase dx_ctl_dsource -d Landshark5 -action update -validatedsync ENABLED -backup_dir "/u02/sybase_back" -dsourcename pubs3 @@ -839,4 +933,6 @@ =head1 EXAMPLES Action completed with success + + =cut diff --git a/bin/dx_ctl_env.pl b/bin/dx_ctl_env.pl index d446eca..538f13f 100755 --- a/bin/dx_ctl_env.pl +++ b/bin/dx_ctl_env.pl @@ -410,7 +410,7 @@ } elsif (lc $repotype eq 'postgresql') { my %native_params; my %plugin_params_hash = ( - "prettyName" => $dbname + "name" => $dbname ); if ($sourceconfig_obj->createSourceConfig('plugin', $repo->{reference}, $dbname, \%native_params, \%plugin_params_hash)) { print "Can't add Postgresql $dbname \n"; diff --git a/bin/dx_get_dsourcesize.pl b/bin/dx_get_dsourcesize.pl index 1234931..5487e6c 100644 --- a/bin/dx_get_dsourcesize.pl +++ b/bin/dx_get_dsourcesize.pl @@ -170,7 +170,7 @@ if ($dbobj->getEnvironmentName() eq 'NA') { # staging push - $envname = $dbobj->getStagingEnvironment(); + $envname = $dbobj->getStagingEnvironmentName(); } else { $envname = $dbobj->getEnvironmentName(); } diff --git a/bin/dx_provision_vdb.pl b/bin/dx_provision_vdb.pl index d16722c..744b35d 100644 --- a/bin/dx_provision_vdb.pl +++ b/bin/dx_provision_vdb.pl @@ -51,6 +51,7 @@ my $version = $Toolkit_helpers::version; my $archivelog = 'yes'; +my $datapatch = 'no'; GetOptions( 'help|?' => \(my $help), @@ -122,6 +123,8 @@ 'tdeexportsecret=s' => \(my $tdeexportsecret), 'tdecdbpassword=s' => \(my $tdecdbpassword), 'tdekeyid=s' => \(my $tdekeyid), + 'customparameters=s@' => \(my $customparameters), + 'datapatch=s' => \($datapatch), 'dever=s' => \(my $dever), 'debug:n' => \(my $debug), 'all' => (\my $all), @@ -171,7 +174,7 @@ } -if ( ! ( ( $type eq 'oracle') || ( $type eq 'mssql') || ( $type eq 'sybase') || ( $type eq 'mysql') ||( $type eq 'db2') || ( $type eq 'vFiles') ) ) { +if ( ! ( ( $type eq 'oracle') || ( $type eq 'mssql') || ( $type eq 'sybase') || ( $type eq 'mysql') ||( $type eq 'db2') || ( $type eq 'vFiles') || ( $type eq 'postgresql') ) ) { print "Option -type has invalid parameter - $type \n"; pod2usage(-verbose => 1, -input=>\*DATA); exit (1); @@ -288,6 +291,8 @@ $db = new DB2VDB_obj($engine_obj,$debug); } elsif ($type eq 'vFiles') { $db = new AppDataVDB_obj($engine_obj,$debug); + } elsif ($type eq 'postgresql') { + $db = new PostgresVDB_obj($engine_obj,$debug); } # common database code @@ -554,7 +559,15 @@ $db->setNewDBID(); } - + if (defined($datapatch)) { + if ((lc $datapatch eq 'no') || ( lc $datapatch eq 'yes') ) { + $db->setDataPatch($datapatch); + } else { + print "Datapatch argument should be yes or no. VDB won't be created\n" ; + $ret = $ret + 1; + next; + } + } if ( defined($template) ) { if ( $db->setTemplate($template) ) { @@ -688,6 +701,16 @@ } $db->setName($targetname, $dbname); $jobno = $db->createVDB($group,$environment,$envinst); + } elsif ($type eq 'postgresql') { + if (! defined($port)) { + print "Port not defined. VDB won't be created.\n"; + $ret = $ret + 1; + next; + } + + $db->setName($targetname, $dbname); + $jobno = $db->createVDB($group,$environment,$envinst,$mntpoint,$port, $customparameters); + } if (defined($snapshotpolicy_ref)) { @@ -778,13 +801,14 @@ =head1 SYNOPSIS -tdeexportsecret tde_export_secret] [-tdekeyid tde_key_id] [-tdecdbpassword tde_cdb_keystore_password] + [-customparameters (param_name=value)|(#param_name)] [-help] [-debug] =head1 DESCRIPTION Provision VDB from a defined source on the defined target environment. - +dx_provision_vdb.pl -d dxtest -type postgresql -group "Untitled" -creategroup -sourcename "pioro" -srcgroup "Untitled" -targetname "postvdb" -dbname "postvdb" -environment "marcinposttgt.dlpxdc.co" -envinst "Postgres vFiles (15.2)" -envUser "postgres" -hooks /tmp/postvdb.dbhooks -mntpoint "/mnt/provision/postvdb" -port "5444" -customparameters "deadlock_timeout=123s" -customparameters "#max_connections" =head1 ARGUMENTS =head2 Delphix Engine selection - if not specified a default host(s) from dxtools.conf will be used. @@ -1006,6 +1030,9 @@ =head2 VDB arguments =item B<-tdecdbpassword tde_cdb_keystore_password> Password for an existing target CDB keystore (this is an optional parameter is password of the CDB is already set) +=item B<-customparameters (param_name=value)|(#param_name)> +Provide a custom parameter for Postgresql. For more then one parameter, use -customparameters multiple times. +To comment an existing variable inside Postgresql VDB, put a # sign before a parameter. =back @@ -1159,4 +1186,11 @@ =head1 EXAMPLES Job JOB-158167 finised with state: COMPLETED VDB created. +Provision a Postgresql VDB + + dx_provision_vdb -d dxtest -type postgresql -group "Untitled" -sourcename "pioro" -targetname "postvdb" -dbname "postvdb" -environment "POSTTGT" -envinst "Postgres vFiles (15.2)" -mntpoint "/mnt/provision/postvdb" -port "5444" -customparameters "deadlock_timeout=123s" -customparameters "#max_connections" + Starting job - JOB-608 + 0 - 7 - 11 - 18 - 75 - 100 + Job JOB-608 finished with state: COMPLETED + VDB created. =cut diff --git a/lib/Bookmark_obj.pm b/lib/Bookmark_obj.pm index 1870df2..ebc8e97 100644 --- a/lib/Bookmark_obj.pm +++ b/lib/Bookmark_obj.pm @@ -217,6 +217,8 @@ sub createBookmark $bookmark_timeflow_type = 'AppDataTimeflowPoint' } elsif ($db->getDBType() eq 'vFiles') { $bookmark_timeflow_type = 'AppDataTimeflowPoint' + } elsif ($db->getDBType() eq 'postgresql') { + $bookmark_timeflow_type = 'AppDataTimeflowPoint' } else { print "Can't determine a DB type. Exiting\n"; return 1; diff --git a/lib/Databases.pm b/lib/Databases.pm index da0f19b..a6af3eb 100644 --- a/lib/Databases.pm +++ b/lib/Databases.pm @@ -41,6 +41,8 @@ use MSSQLVDB_obj; use SybaseVDB_obj; use AppDataVDB_obj; use DB2VDB_obj; +use PluginVDB_obj; +use PostgresVDB_obj; use Toolkit_obj; use Toolkit_helpers qw (logger); use Encode qw(decode_utf8); @@ -136,10 +138,6 @@ sub LoadDBList { $db = MSSQLVDB_obj->new($self->{_dlpxObject}, $self->{_debug}); } - elsif ($dbitem->{type} eq 'PgSQLDatabaseContainer' ) - { - $db = PostgresVDB_obj->new($self->{_dlpxObject}, $self->{_debug}); - } elsif ($dbitem->{type} eq 'ASEDBContainer' ) { $db = SybaseVDB_obj->new($self->{_dlpxObject}, $self->{_debug}); @@ -153,6 +151,8 @@ sub LoadDBList if (defined($dbitem->{toolkit}) && defined($toolkits->getName($dbitem->{toolkit})) ) { if ($toolkits->getName($dbitem->{toolkit}) eq 'db2db') { $db = DB2VDB_obj->new($self->{_dlpxObject}, $self->{_debug}); + } elsif ($toolkits->getName($dbitem->{toolkit}) eq 'postgres-vsdk') { + $db = PostgresVDB_obj->new($self->{_dlpxObject}, $self->{_debug}); } else { $db = AppDataVDB_obj->new($self->{_dlpxObject}, $self->{_debug}); } diff --git a/lib/MSSQLVDB_obj.pm b/lib/MSSQLVDB_obj.pm index b377057..de447ad 100644 --- a/lib/MSSQLVDB_obj.pm +++ b/lib/MSSQLVDB_obj.pm @@ -116,7 +116,7 @@ sub getConfig $config = join($joinsep,($config, "-recoveryModel $recoveryModel")); } elsif ($self->getType() eq 'dSource') { my $staging_user = $self->getStagingUser(); - my $staging_env = $self->getStagingEnvironment(); + my $staging_env = $self->getStagingEnvironmentName(); my $staging_inst = $self->getStagingInst(); $config = join($joinsep,($config, "-stageinst \"$staging_inst\"")); diff --git a/lib/OracleVDB_obj.pm b/lib/OracleVDB_obj.pm index 6f470d1..5b32628 100644 --- a/lib/OracleVDB_obj.pm +++ b/lib/OracleVDB_obj.pm @@ -318,6 +318,11 @@ sub getConfig $config = join($joinsep,($config, $tde)); } + my $datapatch = $self->getDataPatch(); + if (defined($datapatch)) { + $config = join($joinsep,($config, "-datapatch $datapatch")); + } + } else { # dSource config for Oracle @@ -350,7 +355,7 @@ sub getConfig } else { my $staging_user = $self->getStagingUser(); - my $staging_env = $self->getStagingEnvironment(); + my $staging_env = $self->getStagingEnvironmentName(); my $staging_inst = $self->getStagingInst(); $config = join($joinsep,($config, "-sourcename \"" . $self->{staging_sourceConfig}->{databaseName} . "\"")); @@ -1066,6 +1071,47 @@ sub setMountPoint { $self->{"NEWDB"}->{"source"}->{"mountBase"} = $mountpoint; } + +# Procedure getDataPatch +# parameters: +# Get mountpoint of DB. + +sub getDataPatch { + my $self = shift; + logger($self->{_debug}, "Entering OracleVDB_obj::getDataPatch",1); + my $ret; + if (version->parse($self->{_dlpxObject}->getApi()) >= version->parse(1.11.26)) { + if ($self->{"source"}->{"invokeDatapatch"}) { + $ret = "yes"; + } else { + $ret = "no"; + } + } + return $ret; +} + +# Procedure setDataPatch +# parameters: +# - mountpoint - mount point +# Set mountpoint for new db. + +sub setDataPatch { + my $self = shift; + my $datapatch = shift; + logger($self->{_debug}, "Entering OracleVDB_obj::setDataPatch",1); + + if (version->parse($self->{_dlpxObject}->getApi()) >= version->parse(1.11.26)) { + # only for 15 and higher + if (lc $datapatch eq 'no') { + $self->{"NEWDB"}->{"source"}->{"invokeDatapatch"} = JSON::false; + } + elsif (lc $datapatch eq 'yes') { + $self->{"NEWDB"}->{"source"}->{"invokeDatapatch"} = JSON::true; + } + } +} + + # Procedure setArchivelog # parameters: # - archivelog - type diff --git a/lib/PluginVDB_obj.pm b/lib/PluginVDB_obj.pm new file mode 100644 index 0000000..3cf15ad --- /dev/null +++ b/lib/PluginVDB_obj.pm @@ -0,0 +1,249 @@ + + +package PluginVDB_obj; +use Data::Dumper; +use JSON; +use Toolkit_helpers qw (logger); +our @ISA = qw(VDB_obj); + +sub new { + my $class = shift; + my $dlpxObject = shift; + my $debug = shift; + logger($debug, "Entering PluginVDB_obj::constructor",1); + # call VDB_obj constructor + my $self = $class->SUPER::new($dlpxObject, $debug); + + $self->{_dbtype} = 'plugin'; + $self->{_pluginbased} = 1; + + # my @configureClone; + # my @postRefresh; + # my @preRefresh; + # my @configParams; + # my @mntPoints; + # my %configParams = (); + + my %operations = ( + "type" => "VirtualSourceOperations", + "configureClone" => \@configureClone, + "postRefresh" => \@postRefresh, + "preRefresh" => \@preRefresh + ); + my %prov = ( + "type" => "AppDataProvisionParameters", + "container" => { + "type" => 'AppDataContainer', + "name" => '', + "group" => '' + }, + "sourceConfig" => { + "type" => "AppDataDirectSourceConfig", + "repository" => "", + "name" => "" + }, + "source" => { + "type" => "AppDataVirtualSource", + "operations" => \%operations + }, + "timeflowPointParameters" => { + "type" => "TimeflowPointSemantic", + "container" => "", + "location" => "LATEST_SNAPSHOT" + }, + ); + $self->{"NEWDB"} = \%prov; + + + return $self; +} + + +sub addSource +{ + my $self = shift; + $sourcename = shift; + $dbuser = shift; + $password = shift; + $dsourcename = shift; + $group = shift; + $logsync = shift; + $stageenv = shift; + $stageinst = shift; + $stage_os_user = shift; + $backup_dir = shift; + $sourcehostname = shift; + $sourceport = shift; + $ingestiontype = shift; + $dumpdir = shift; + $restorejobs = shift; + $dumpjobs = shift; + $staging_port = shift; + $singledbname = shift; + $mountbase = shift; + $plugin_parameters = shift; + + + logger($self->{_debug}, "Entering PluginVDB_obj::addSource",1); + + my $config = $self->setConfig($sourcename, $stageinst, $stageenv); + + if (! defined($config)) { + print "Source database $sourcename not found\n"; + return undef; + } + + if ( $self->setGroup($group) ) { + print "Group $group not found. dSource won't be created\n"; + return undef; + } + + if ( $self->setEnvironment($stageenv) ) { + print "Staging environment $stageenv not found. dSource won't be created\n"; + return undef; + } + + + my $stage_osuser_ref = $self->{_environment}->getEnvironmentUserByName($stageenv,$stage_os_user); + + if (!defined($stage_osuser_ref)) { + print "Source OS user $stage_os_user not found\n"; + return undef; + } + + + + my %dsource_params = ( + "type" => "LinkParameters", + "group" => $self->{"NEWDB"}->{"container"}->{"group"}, + "name" => $dsourcename, + "linkData" => { + "type" => "AppDataStagedLinkData", + "config" => $config->{reference}, + "environmentUser" => $stage_osuser_ref, + "stagingEnvironment" => $self->{'_newenv'}, + "stagingEnvironmentUser" => $stage_osuser_ref, + "parameters" => $plugin_parameters, + "syncParameters" => { + "type"=> "AppDataSyncParameters", + "parameters" => { + "resync" => JSON::true + } + } + } + ); + + + my $ds_hooks = $self->set_dsource_hooks(); + if (defined($ds_hooks)) { + if (version->parse($self->{_dlpxObject}->getApi()) < version->parse(1.8.0)) { + $dsource_params{"source"}{"operations"} = $ds_hooks; + } else { + $dsource_params{"linkData"}{"operations"} = $ds_hooks; + } + } + + my $operation = 'resources/json/delphix/database/link'; + my $json_data = to_json(\%dsource_params, {pretty=>1}); + #my $json_data = encode_json(\%dsource_params, pretty=>1); + + logger($self->{_debug}, $json_data, 1); + + return $self->runJobOperation($operation,$json_data, 'ACTION'); + + +} + + +# Procedure snapshot +# parameters: +# - resync - yes/no +# Run snapshot +# Return job number if job started or undef otherwise + +sub snapshot +{ + my $self = shift; + my $resync = shift; + logger($self->{_debug}, "Entering PluginVDB_obj::snapshot",1); + + my %snapshot_type = ( + "type" => "AppDataSyncParameters" + ); + + my $resync_value; + + if (defined ($resync)) { + $resync_value = JSON::true + } else { + $resync_value = JSON::false + } + + if (version->parse($self->{_dlpxObject}->getApi()) < version->parse(1.11.6)) { + # until 6.0.6 + %snapshot_type = ( + "type" => "AppDataSyncParameters", + "resync" => $resync_value + ); + + } else { + # 6.0.6 and higher + %snapshot_type = ( + "type" => "AppDataSyncParameters", + "parameters" => { + "resync" => $resync_value + } + ); + + } + + + return $self->VDB_obj::snapshot(\%snapshot_type) ; +} + + +sub createVDB { + my $self = shift; + my $group = shift; + my $env = shift; + my $inst = shift; + my $mountpoint = shift; + my $port = shift; + my $parameters = shift; + + logger($self->{_debug}, "Entering PluginVDB_obj::createVDB",1); + + + if ( $self->setGroup($group) ) { + print "Group $group not found. VDB won't be created\n"; + return undef; + } + + if ( $self->setEnvironment($env) ) { + print "Environment $env not found. VDB won't be created\n"; + return undef; + } + + if ( $self->setHome($inst) ) { + print "Instance $inst in environment $env not found. VDB won't be created\n"; + return undef; + } + + if (!defined($mountpoint)) { + print "Mount point not defined. VDB won't be created\n"; + return undef; + } + + if (!defined($port)) { + print "Port not defined. VDB won't be created\n"; + return undef; + } + + $self->{"NEWDB"}->{"source"}->{"parameters"}=$parameters; + + my $operation = 'resources/json/delphix/database/provision'; + my $json_data = $self->getJSON(); + + return $self->runJobOperation($operation,$json_data); + +} \ No newline at end of file diff --git a/lib/PostgresVDB_obj.pm b/lib/PostgresVDB_obj.pm new file mode 100644 index 0000000..2509628 --- /dev/null +++ b/lib/PostgresVDB_obj.pm @@ -0,0 +1,633 @@ + + +package PostgresVDB_obj; +use Data::Dumper; +use JSON; +use Toolkit_helpers qw (logger); +our @ISA = qw(PluginVDB_obj); + +sub new { + my $class = shift; + my $dlpxObject = shift; + my $debug = shift; + logger($debug, "Entering PostgresVDB_obj::constructor",1); + # call VDB_obj constructor + my $self = $class->SUPER::new($dlpxObject, $debug); + + $self->{_dbtype} = 'postgresql'; + $self->{_pluginbased} = 1; + + return $self; +} + + +# Procedure getStagingEnvironmentName +# parameters: none +# Return database staging environment + +sub getStagingEnvironmentName +{ + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getStagingEnvironmentName",1); + my $ret; + if (defined($self->{environment}->{name})) { + $ret = $self->{environment}->{name}; + } else { + $ret = 'N/A'; + } + return $ret; +} + +# Procedure getStagingInst +# parameters: none +# Return database staging environment + +sub getStagingInstName +{ + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getStagingInst",1); + my $ret; + + my $repo = $self->{_repository}->getRepository($self->{"repository"}); + + if (defined($repo)) { + $ret = $repo->{name}; + } else { + $ret = 'N/A'; + } + return $ret; +} + + +# Procedure getMountPoint +# parameters: +# Get mountpoint of staging DB. + +sub getMountPoint { + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getMountPoint",1); + return $self->{"source"}->{"parameters"}->{"mountLocation"}; +} + + +# Procedure getCustomparams +# parameters: +# Get custom parameters + +sub getCustomparams { + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getCustomparams",1); + my $ret = ""; + if (defined($self->{"source"}->{"parameters"}->{"configSettingsStg"})) { + for my $param (@{$self->{"source"}->{"parameters"}->{"configSettingsStg"}}) { + if ($param->{"commentProperty"}) { + # remove parameter so output with # + $ret = $ret . "-customparameters \"#" . $param->{"propertyName"} . "\" "; + } else { + # add parameter + $ret = $ret . "-customparameters \"" . $param->{"propertyName"} . "=" . $param->{"value"} . "\" "; + } + } + } + return $ret; +} + + + +# Procedure getStagingUser +# parameters: none +# Return OS user + +sub getStagingUser +{ + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getStagingUser",1); + my $ret; + my $user; + + my $staging_env = $self->{environment}->{reference}; + my $staging_user_ref; + + if (defined($staging_env)) { + $staging_user_ref = $self->{source}->{stagingEnvironmentUser}; + $ret = $self->{_environment}->getEnvironmentUserNamebyRef($staging_env, $staging_user_ref); + } else { + $ret = 'N/A'; + } + + return $ret; +} + + +# Procedure getPostgresqlPort +# parameters: none +# Return staging port + +sub getPostgresqlPort +{ + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getPostgresqlPort",1); + my $ret; + if (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"postgresPort"})) { + $ret = $self->{"source"}->{"parameters"}->{"postgresPort"}; + } else { + $ret = 'N/A'; + } + return $ret; +} + + +# Procedure getSingleParam +# parameters: parameter name +# Return parameter value for single ingestion + +sub getSingleParam +{ + my $self = shift; + my $param = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getSingleParam",1); + my $ret; + if (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"singleDatabaseIngestionFlag"}) && $self->{"source"}->{"parameters"}->{"singleDatabaseIngestionFlag"}) { + $ret = $self->{"source"}->{"parameters"}->{"singleDatabaseIngestion"}->[-1]->{$param}; + } else { + $ret = 'N/A'; + } + return $ret; +} + + +# Procedure getInitialParam +# parameters: parameter name +# Return parameter value for initialized ingestion + +sub getInitialParam +{ + my $self = shift; + my $param = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getInitialParam",1); + my $ret; + if (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"delphixInitiatedBackup"}) && (scalar(@{$self->{"source"}->{"parameters"}->{"delphixInitiatedBackup"}}) > 0) ) { + $ret = $self->{"source"}->{"parameters"}->{"delphixInitiatedBackup"}->[-1]->{$param}; + } else { + $ret = 'N/A'; + } + return $ret; +} + +# Procedure getExternalParam +# parameters: parameter name +# Return parameter value for initialized ingestion + +sub getExternalParam +{ + my $self = shift; + my $param = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getExternalParam",1); + my $ret; + if (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"externalBackup"}) && (scalar(@{$self->{"source"}->{"parameters"}->{"externalBackup"}}) > 0)) { + $ret = $self->{"source"}->{"parameters"}->{"externalBackup"}->[-1]->{$param}; + } else { + $ret = 'N/A'; + } + return $ret; +} + + +# Procedure getIngestionType +# parameters: None +# return an ingestion type +# delphixInitiatedBackup, singleDatabaseIngestion, stagingPush, externalBackup + +sub getIngestionType +{ + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getIngestionType",1); + my $ret; + + if (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"delphixInitiatedBackupFlag"}) && $self->{"source"}->{"parameters"}->{"delphixInitiatedBackupFlag"}) { + $ret = "initiated"; + } + elsif (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"singleDatabaseIngestionFlag"}) && $self->{"source"}->{"parameters"}->{"singleDatabaseIngestionFlag"}) { + $ret = "single"; + } + elsif (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"stagingPushFlag"}) && $self->{"source"}->{"parameters"}->{"stagingPushFlag"}) { + $ret = "stagingpush"; + } + else { + if (defined($self->{"source"}->{"parameters"}) && defined($self->{"source"}->{"parameters"}->{"externalBackup"}) && (scalar(@{$self->{"source"}->{"parameters"}->{"externalBackup"}})>0)) { + $ret = "externalbackup"; + } else { + $ret = 'N/A'; + } + } + + return $ret; +} + +# Procedure getConfig +# parameters: none +# Return database config + +sub getConfig +{ + my $self = shift; + my $templates = shift; + my $backup = shift; + + logger($self->{_debug}, "Entering PostgresVDB_obj::getConfig",1); + my $config = ''; + my $joinsep; + + if (defined($backup)) { + $joinsep = ' '; + } else { + $joinsep = ','; + } + + if ($self->getType() eq 'VDB') { + my $vdb_port = $self->getPostgresqlPort(); + my $mountpoint = $self->getMountPoint(); + $config = join($joinsep,($config, "-mntpoint \"" . $mountpoint . "\"")); + $config = join($joinsep,($config, "-port \"" . $vdb_port . "\"")); + } else { + # dSource + my $staging_port = $self->getPostgresqlPort(); + my $ingestion_type = $self->getIngestionType(); + + + $config = join($joinsep,($config, "-mountbase \"" . $self->getMountPoint() . "\"")); + $config = join($joinsep,($config, "-stagingport " . $staging_port )); + + # postgeresql related + $config = join($joinsep,($config, "-ingestiontype $ingestion_type ")); + + if ($ingestion_type eq "single" ) { + $config = join($joinsep,($config, "-dbuser \"" . $self->getSingleParam("databaseUserName") . "\"")); + $config = join($joinsep,($config, "-password xxxxxxxxx")); + $config = join($joinsep,($config, "-sourcehostname \"" . $self->getSingleParam("sourceHost") . "\"")); + $config = join($joinsep,($config, "-sourceport " . $self->getSingleParam("sourcePort") )); + $config = join($joinsep,($config, "-singledbname \"" . $self->getSingleParam("databaseName") . "\"")); + $config = join($joinsep,($config, "-dumpdir \"" . $self->getSingleParam("dumpDir") . "\"")); + $config = join($joinsep,($config, "-restorejobs " . $self->getSingleParam("restoreJobs") )); + $config = join($joinsep,($config, "-dumpjobs " . $self->getSingleParam("dumpJobs") )); + } + elsif ($ingestion_type eq "initiated" ) { + $config = join($joinsep,($config, "-dbuser \"" . $self->getInitialParam("userName") . "\"")); + $config = join($joinsep,($config, "-password xxxxxxxxx")); + $config = join($joinsep,($config, "-sourcehostname \"" . $self->getInitialParam("sourceHostAddress") . "\"")); + $config = join($joinsep,($config, "-sourceport " . $self->getInitialParam("postgresSourcePort") )); + } + elsif ($ingestion_type eq "externalbackup" ) { + $config = join($joinsep,($config, "-backup_dir \"" . $self->getExternalParam("backupPath") . "\"")); + $config = join($joinsep,($config, "-backup_dir_log \"" . $self->getExternalParam("walLogPath") . "\"")); + my $insync = $self->getExternalParam("keepStagingInSync"); + my $insync_text; + if ($insync) { + $insync_text = "yes"; + $config = join($joinsep,($config, "-dbuser \"" . $self->getInitialParam("userName") . "\"")); + $config = join($joinsep,($config, "-password xxxxxxxxx")); + $config = join($joinsep,($config, "-sourcehostname \"" . $self->getInitialParam("sourceHostAddress") . "\"")); + $config = join($joinsep,($config, "-sourceport " . $self->getInitialParam("postgresSourcePort") )); + } else { + $insync_text = "no"; + } + $config = join($joinsep,($config, "-keepinsync " . $insync_text )); + + } + } + + $config = join($joinsep, ($config, $self->getCustomparams())); + + if ( (my $rest) = $config =~ /^,(.*)/ ) { + $config = $rest; + } + + return $config; + +} + + +sub addSource +{ + my $self = shift; + $sourcename = shift; + $dbuser = shift; + $password = shift; + $dsourcename = shift; + $group = shift; + $logsync = shift; + $stageenv = shift; + $stageinst = shift; + $stage_os_user = shift; + $backup_dir = shift; + $sourcehostname = shift; + $sourceport = shift; + $ingestiontype = shift; + $dumpdir = shift; + $restorejobs = shift; + $dumpjobs = shift; + $staging_port = shift; + $singledbname = shift; + $mountbase = shift; + $customparameters = shift; + $backup_path = shift; + $backup_dir_log = shift; + $keepinsync = shift; + + logger($self->{_debug}, "Entering PostgresVDB_obj::addSource",1); + + my @empty; + + my %parameters = ( + 'configSettingsStg' => \@empty, + 'externalBackup' => \@empty, + 'delphixInitiatedBackupFlag' => undef, + 'singleDatabaseIngestion' => \@empty, + 'delphixInitiatedBackup' => \@empty, + 'stagingPushFlag' => undef, + 'singleDatabaseIngestionFlag' => undef, + 'postgresPort' => $staging_port, + "mountLocation" => $mountbase + ); + + + if (lc $ingestiontype eq 'single') { + $parameters{"delphixInitiatedBackupFlag"} = JSON::false; + $parameters{"stagingPushFlag"} = JSON::false; + $parameters{"singleDatabaseIngestionFlag"} = JSON::true; + my @arr; + + if ((!defined($dbuser)) || (!defined($password)) || (!defined($sourcehostname)) || (!defined($sourceport)) + || (!defined($singledbname)) || (!defined($restorejobs)) || (!defined($dumpjobs)) || (!defined($dumpdir)) ) { + print "Parameters -dbuser, -password, -sourcehostname, -sourceport, -singledbname, -restorejobs, -dumpjobs, -dumpdir are mandatory with single ingestion mode. Exiting\n"; + return undef; + } + + my %param_single = ( + "databaseName" => $singledbname, + "databaseUserName" => $dbuser, + "databaseUserPassword" => $password, + "dumpDir" => $dumpdir, + "dumpJobs" => $dumpjobs, + "restoreJobs" => $restorejobs, + "sourceHost" => $sourcehostname, + "sourcePort" => $sourceport + ); + + push(@arr, \%param_single); + + $parameters{"singleDatabaseIngestion"} = \@arr; + + } + elsif (lc $ingestiontype eq 'initiated') { + $parameters{"delphixInitiatedBackupFlag"} = JSON::true; + $parameters{"stagingPushFlag"} = JSON::false; + $parameters{"singleDatabaseIngestionFlag"} = JSON::false; + my @arr; + + if ((!defined($dbuser)) || (!defined($password)) || (!defined($sourcehostname)) || (!defined($sourceport)) ) { + print "Parameters -dbuser, -password, -sourcehostname, -sourceport are mandatory with initiated ingestion mode. Exiting\n"; + return undef; + } + + my %param_single = ( + "userName" => $dbuser, + "userPass" => $password, + "sourceHostAddress" => $sourcehostname, + "postgresSourcePort" => $sourceport + ); + + push(@arr, \%param_single); + + $parameters{"delphixInitiatedBackup"} = \@arr; + + + } + elsif (lc $ingestiontype eq 'externalbackup') { + + my @arr; + my @arr_sync; + + if ((!defined($backup_dir)) || (!defined($backup_dir_log)) || (!defined($keepinsync)) ) { + print "Parameters -backup_dir, -backup_dir_log and -keepinsync are mandatory external backup ingestion mode. Exiting\n"; + return undef; + } + + $parameters{"delphixInitiatedBackupFlag"} = JSON::false; + $parameters{"stagingPushFlag"} = JSON::false; + $parameters{"singleDatabaseIngestionFlag"} = JSON::false; + + if (!(defined($keepinsync) && (( lc $keepinsync eq 'no' ) || (lc $keepinsync eq 'yes')))) { + print "Parameter keepinsync should be no or yes. Exiting.\n"; + return undef; + } + + my $insync; + + if ( lc $keepinsync eq 'no' ) { + $insync = JSON::false; + } else { + $insync = JSON::true; + + if ((!defined($dbuser)) || (!defined($password)) || (!defined($sourcehostname)) || (!defined($sourceport)) ) { + print "Parameters -dbuser, -password, -sourcehostname, -sourceport are mandatory with keepinsync set to yes. Exiting\n"; + return undef; + } + + my %param_sync = ( + "userName" => $dbuser, + "userPass" => $password, + "sourceHostAddress" => $sourcehostname, + "postgresSourcePort" => $sourceport + ); + + push(@arr_sync, \%param_sync); + $parameters{"delphixInitiatedBackup"} = \@arr_sync; + } + + my %param_single = ( + "backupPath" => $backup_dir, + "walLogPath" => $backup_dir_log, + "keepStagingInSync" => $insync, + ); + + push(@arr, \%param_single); + $parameters{"externalBackup"} = \@arr; + + } + + if (defined($customparameters)) { + $parameters{"configSettingsStg"} = $self->setCustomParams($customparameters); + } + + return $self->PluginVDB_obj::addSource( + $sourcename, + $dbuser, + $password, + $dsourcename, + $group, + $logsync, + $stageenv, + $stageinst, + $stage_os_user, + $backup_dir , + $sourcehostname, + $sourceport, + $ingestiontype, + $dumpdir, + $restorejobs, + $dumpjobs, + $staging_port, + $singledbname, + $mountbase, + \%parameters + ) ; + +} + + +# Procedure setSource +# parameters: +# - name - source name +# Set dsource reference by name for new db. +# Return 0 if success, 1 if not found + +sub setSource { + my $self = shift; + #my $name = shift; + my $sourceitem = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::setSource",1); + + my $dlpxObject = $self->{_dlpxObject}; + my $debug = $self->{_debug}; + + + if (defined ($sourceitem)) { + my $sourcetype = $sourceitem->{container}->{'type'}; + + if (($sourcetype eq 'AppDataContainer') || ($sourcetype eq 'AppDataVirtualSource') || ($sourcetype eq 'AppDataLinkedSource') ) { + $self->{"NEWDB"}->{"timeflowPointParameters"}->{"container"} = $sourceitem->{container}->{reference}; + return 0; + } else { + return 1; + } + } else { + return 1; + } + +} + + +# Procedure setName +# parameters: +# - contname - container name +# - dbname - database name +# Set name for new db. + +sub setName { + my $self = shift; + my $contname = shift; + my $dbname = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::setName",1); + + $self->{"NEWDB"}->{"container"}->{"name"} = $contname; + $self->{"NEWDB"}->{"sourceConfig"}->{"name"} = $contname; + +} + + +# Procedure createVDB +# parameters: +# - group - new DB group +# - env - new DB environment +# - inst - new DB instance +# - mountpoint - moint point +# - port - VDB port +# Start job to create postgresql VBD +# all above parameters are required. Additional parameters should by set by setXXXX procedures before this one is called +# Return job number if provisioning has been started, otherwise return undef + +sub createVDB { + my $self = shift; + my $group = shift; + my $env = shift; + my $inst = shift; + my $mountpoint = shift; + my $port = shift; + my $customparameters = shift; + + logger($self->{_debug}, "Entering PostgresVDB_obj::createVDB",1); + + my %parameters; + + $parameters{"mountLocation"} = $mountpoint; + $parameters{"postgresPort"} = $port; + + if (defined($customparameters)) { + $parameters{"configSettingsStg"} = $self->setCustomParams($customparameters); + } + + return $self->PluginVDB_obj::createVDB( + $group, + $env, + $inst, + $mountpoint, + $port, + \%parameters + ); + +} + + +sub setCustomParams { + my $self = shift; + my $customparameters = shift; + + my @postgresql_params; + if (defined($customparameters)) { + my @pair; + for my $param (@{$customparameters}) { + if ($param =~ /=/ ) { + @pair = split("=", $param); + if (scalar(@pair)!=2) { + print "Error with vdbparameter definition. $param. Exiting\n"; + return undef; + } + push(@postgresql_params, { + "propertyName" => $pair[0], + "value"=> $pair[1], + "commentProperty" => JSON::false + }); + } + elsif (($toremove) = $param =~ /^#(.*)/ ) { + push(@postgresql_params, { + "propertyName" => $toremove, + "value"=> "", + "commentProperty" => JSON::true + }); + } + else { + print "Error with vdbparameter definition. $param. Exiting\n"; + return undef; + } + } + } + return \@postgresql_params; +} + +# Procedure getDatabaseName +# parameters: none +# Return database name + +sub getDatabaseName +{ + my $self = shift; + logger($self->{_debug}, "Entering PostgresVDB_obj::getDatabaseName",1); + return $self->{source}->{name}; +} + +# +# End of package + + +1; \ No newline at end of file diff --git a/lib/SybaseVDB_obj.pm b/lib/SybaseVDB_obj.pm index d61c0c2..70ab9e4 100644 --- a/lib/SybaseVDB_obj.pm +++ b/lib/SybaseVDB_obj.pm @@ -311,7 +311,7 @@ sub getConfig } } elsif ($self->getType() eq 'dSource') { my $staging_user = $self->getStagingUser(); - my $staging_env = $self->getStagingEnvironment(); + my $staging_env = $self->getStagingEnvironmentName(); my $staging_inst = $self->getStagingInst(); $config = join($joinsep,($config, "-stageinst \"$staging_inst\"")); diff --git a/lib/Toolkit_helpers.pm b/lib/Toolkit_helpers.pm index 9218e6d..10c462c 100644 --- a/lib/Toolkit_helpers.pm +++ b/lib/Toolkit_helpers.pm @@ -29,7 +29,7 @@ use File::Spec; use lib '../lib'; -our $version = '2.4.22.1'; +our $version = '2.4.23'; my $tz = new Date::Manip::TZ; my $dt = new Date::Manip::Date; @@ -776,7 +776,9 @@ sub timezone_fix { if ($timezone eq 'Etc/GMT+0') { $timezone = 'GMT'; } - + if ($timezone eq 'EST') { + $timezone = 'US/Eastern'; + } return $timezone; } @@ -865,18 +867,21 @@ sub convert_timezone { $timestamp =~ s/T/ /; $timestamp =~ s/\.000Z//; - $err = $dt->parse($timestamp); - if ($err) { return undef; } - my $dttemp = $dt->value(); + my $dttemp = $dt->value(); ($err,$date,$offset,$isdst,$abbrev) = $tz->convert($dttemp, $src, $dst); my $ts; if ($err) { + # 0 No error + # 1 Invalid arguments + # 2 Invalid FROM zone + # 3 Invalid TO zone + # 4 Invalid date return undef; } @@ -958,7 +963,7 @@ sub print_size { $decnum = 2; } - if ($bytes eq 'N/A') { + if (($bytes eq 'N/A') || ($bytes eq 'NA')) { return 'N/A'; } diff --git a/lib/VDB_obj.pm b/lib/VDB_obj.pm index 5fda246..6ca1d44 100644 --- a/lib/VDB_obj.pm +++ b/lib/VDB_obj.pm @@ -864,6 +864,12 @@ sub getdSourceBackup my $vendor = $self->{_dbtype}; my $rephome = $self->getHome(); + my $plugin = 0; + + if (defined($self->{_pluginbased}) && ($self->{_pluginbased} eq 1) ) { + $plugin = 1; + } + $dbhostname = $self->getSourceConfigName(); if (! defined($dbhostname)) { @@ -882,13 +888,34 @@ sub getdSourceBackup my $restore_args = "dx_ctl_dsource$suffix -d $engine -action create -group \"$groupname\" -creategroup "; $restore_args = $restore_args . "-dsourcename \"$dbn\" -type $vendor "; - if (($staging_push eq 'no') || ($staging_push eq 'N/A')) { - # for normal dsources - $restore_args = $restore_args . "-sourcename \"$dbhostname\" "; - $restore_args = $restore_args . "-sourceinst \"$rephome\" -sourceenv \"" . $self->getEnvironmentName() . "\" -source_os_user \"$osuser\" "; - my $logsync = $self->getLogSync() eq 'ACTIVE'? 'yes' : 'no' ; + + if ($plugin eq 0) { + if (($staging_push eq 'no') || ($staging_push eq 'N/A')) { + # for normal dsources + $restore_args = $restore_args . "-sourcename \"$dbhostname\" "; + $restore_args = $restore_args . "-sourceinst \"$rephome\" -sourceenv \"" . $self->getEnvironmentName() . "\" -source_os_user \"$osuser\" "; + my $logsync = $self->getLogSync() eq 'ACTIVE'? 'yes' : 'no' ; + my $dbuser = $self->getDbUser(); + + if ($dbuser ne 'N/A') { + if ($dbuser =~ /dbusertype environment/ ) { + $restore_args = $restore_args . " $dbuser "; + } else { + # this is for all users but not an dbuser type environent for ms sql + $restore_args = $restore_args . "-dbuser $dbuser -password xxxxxxxx "; + } + } + + $restore_args = $restore_args . " -logsync $logsync"; + } + } else { + # for plugin based dSources + my $dbuser = $self->getDbUser(); + $restore_args = $restore_args . "-sourcename \"$dbhostname\" "; + $restore_args = $restore_args . "-stageinst \"$rephome\" -stageenv \"" . $self->getEnvironmentName() . "\" -stage_os_user \"$osuser\" "; + if ($dbuser ne 'N/A') { if ($dbuser =~ /dbusertype environment/ ) { $restore_args = $restore_args . " $dbuser "; @@ -898,8 +925,8 @@ sub getdSourceBackup } } - $restore_args = $restore_args . " -logsync $logsync"; - } + + } $restore_args = $restore_args . " -hooks " . File::Spec->catfile($backup,$dbn.'.dbhooks') . " "; $restore_args = $restore_args . $self->getConfig(undef, 1); @@ -922,14 +949,14 @@ sub getCurrentTimeflow } -# Procedure getStagingEnvironment +# Procedure getStagingEnvironmentName # parameters: none # Return database staging environment -sub getStagingEnvironment +sub getStagingEnvironmentName { my $self = shift; - logger($self->{_debug}, "Entering VDB_obj::getStagingEnvironment",1); + logger($self->{_debug}, "Entering VDB_obj::getStagingEnvironmentName",1); my $ret; if (defined($self->{staging_environment}->{name})) { $ret = $self->{staging_environment}->{name}; @@ -2582,6 +2609,7 @@ sub setHook { $self->{"source"} = $self->{_source}->refreshSource($self->{"source"}->{"reference"}); } else { + print Dumper "settuke"; if (defined($self->{"NEWDB"}->{"source"}->{"operations"}->{$hooktype})) { @hook_array = @{$self->{"NEWDB"}->{"source"}->{"operations"}->{$hooktype}}; push(@hook_array, \%hook_hash); @@ -3190,27 +3218,6 @@ sub snapshot -######################## - -package PostgresVDB_obj; -use Data::Dumper; -use JSON; -use Toolkit_helpers qw (logger); -our @ISA = qw(VDB_obj); - -sub new { - my $class = shift; - my $dlpxObject = shift; - my $debug = shift; - logger($debug, "Entering PostgresVDB_obj::constructor",1); - # call VDB_obj constructor - my $self = $class->SUPER::new($dlpxObject, $debug); - - $self->{_dbtype} = 'postgresql'; - - return $self; -} - # # End of package