1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#!/usr/bin/perl
#
# Script that:
# - updates the database schema to support SRMv2.2
# - updates the 's_uid' field in the "dpm_space_reserv" table
# - updates the newly created 'protocol' field in the "dpm_get_filereq" and "dpm_put_filereq" tables
#
# Author : Sophie Lemaitre (sophie.lemaitre@cern.ch)
# Date : 19/10/2006
#
use strict;
use warnings;
use Getopt::Long;
use DBI;
use Env qw(ORACLE_HOME);
use UpdateDpmDatabase;
sub usage($) {
my $reason = shift(@_);
print <<EOF and die "\nWrong usage of the script: $reason.\n";
usage: $0 --db-vendor db_vendor --db db --user user --pwd-file pwd_file [--dpns-db dpns_db --dpm-db dpm_db] [--verbose]
The dpns-db and dpm-db arguments have to be specified only if the database backend is MySQL.
EOF
}
# Create arguments variables...
my ($db_vendor, $db, $user, $pwd_file, $dpns_db, $dpm_db, $verbose);
# ... and read the arguments
GetOptions("db-vendor:s", => \$db_vendor,
"db:s", => \$db,
"user:s", => \$user,
"pwd-file:s", => \$pwd_file,
"dpns-db:s", => \$dpns_db,
"dpm-db:s", => \$dpm_db,
"verbose" => \$verbose );
# check CLI consistency
usage("The database vendor must be specified. It can either be \'Oracle\' or \'MySQL\'") unless(defined $db_vendor);
usage("The DPNS database user must be specified") unless(defined $user);
usage("The file containing the DPNS database password must be specified") unless(defined $pwd_file);
if ($db_vendor eq "MySQL") {
usage("The DPNS MySQL database must be specified") unless(defined $dpns_db);
usage("The DPM MySQL database must be specified") unless(defined $dpm_db);
usage("The MySQL server host must be specified") unless(defined $db);
}
elsif ($db_vendor eq "Oracle") {
usage("The Oracle database SID must be specified") unless(defined $db);
}
else {
usage("The database vendor can either be \'Oracle\' or \'MySQL\'");
}
# useful variables
my ($start_time, $time, $end_time);
my $pwd;
my ($dbh_dpns, $dbh_dpm);
my $select;
my $count;
#
# read database password from file
#
open(FILE, $pwd_file) or die("Unable to open password file");
my @data = <FILE>;
$pwd = $data[0];
$pwd =~ s/\n//;
close(FILE);
eval {
$start_time = localtime();
print "$start_time : Starting to update the DPNS/DPM database.\n";
print "Please wait...\n";
if ($db_vendor eq "Oracle") {
$dpns_db = $user;
$dpm_db = $user;
#
# Check ORACLE_HOME is defined
#
if (!defined($ORACLE_HOME) ) {
print STDERR "Error: ORACLE_HOME is not set! Check your Oracle installation.\n";
exit(1);
}
my @drivers = DBI->available_drivers;
if ((my $result = grep /Oracle/ , @drivers) == 0){
print STDERR "Error: Oracle DBD Module is not installed.\n";
exit(1);
}
}
my $lifetime;
$lifetime = time() + 86400; # 86400 is the default lifetime
# connect to database
$dbh_dpns = Common::connectToDatabase($dpns_db, $user, $pwd, $db_vendor, $db);
$dbh_dpm = Common::connectToDatabase($dpm_db, $user, $pwd, $db_vendor, $db);
# update the database schema
if ($db_vendor eq "MySQL") {
UpdateDpmDatabase::modify_dpm_db_before_updating_fields_mysql($dbh_dpm, $lifetime);
UpdateDpmDatabase::modify_cns_db_mysql($dbh_dpns, $lifetime);
}
if ($db_vendor eq "Oracle") {
UpdateDpmDatabase::modify_dpm_db_before_updating_fields_oracle($dbh_dpm, $lifetime);
UpdateDpmDatabase::modify_cns_db_oracle($dbh_dpns, $lifetime);
}
# update the protocol and s_uid fields
$count = UpdateDpmDatabase::find_and_update_s_uid_field($dbh_dpns, $dbh_dpm);
$count = $count + UpdateDpmDatabase::find_and_update_protocol_field($dbh_dpm);
$count = $count + UpdateDpmDatabase::update_defpintime($dbh_dpm);
# delete the "protocol" column
if ($db_vendor eq "MySQL") {
UpdateDpmDatabase::modify_db_after_updating_fields_mysql($dbh_dpns, $dbh_dpm);
}
if ($db_vendor eq "Oracle") {
UpdateDpmDatabase::modify_db_after_updating_fields_oracle($dbh_dpns, $dbh_dpm);
}
$dbh_dpns->commit;
$dbh_dpm->commit;
$dbh_dpm->disconnect;
$dbh_dpns->disconnect;
#
# The migration is over
#
$end_time = localtime();
print "$end_time : The update of the DPNS/DPM database is over\n";
if ($verbose) {
print "db vendor = $db_vendor\n";
print "db = $db\n";
print "DPNS database user = $user\n";
print "DPNS database password = xxxxxx\n";
if ($db_vendor eq "MySQL") {
print "DPNS database name = $dpns_db\n";
print "DPM database name = $dpm_db\n";
}
}
};
die ("failed to query and/or update the DPNS/DPM databases : $@") if ($@);
|