File: migrate_RLS_entries

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (132 lines) | stat: -rwxr-xr-x 3,396 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl

#
# Script that migrates the entries from the EDG Replica Location Service (RLS)
# database to the new LCG File Catalog (LFC).
#

use strict;
use warnings;
use Getopt::Long;
use DBI;
use Env qw(ORACLE_HOME);

use FindBin;
use lib "$FindBin::Bin/../lib";
use Common;
use Cms;

sub usage($) {
  my $reason = shift(@_);
  print <<EOF and   die "\nWrong usage of the script: $reason.\n";
usage: $0 --db-vendor db_vendor --host db --lrc-user lrc_user --lrc-passwd lrc_passwd --path path --file /path/to/file [--verbose]

The RLS entries will all be migrated to the <path> directory.
The /path/to/file file is expected to contain entries in the following form :
	guid pfn RLS-lfn LFC-lfn

EOF
}

# Create arguments variables...
my ($vo, $db_vendor, $host, $lrc_user, $lrc_passwd, $path, $file, $verbose);

# ... and read the arguments
GetOptions("db-vendor:s", => \$db_vendor,
	   "host:s", => \$host,
	   "lrc-user:s", => \$lrc_user,
	   "lrc-passwd:s", => \$lrc_passwd,
	   "path:s", => \$path,
           "file:s", => \$file,
	   "verbose" => \$verbose );

# check CLI consistency
usage("The Database type must be specified. It can either be \'Oracle\' or \'MySQL\'") unless(defined $db_vendor);
usage("The LRC database user must be specified") unless(defined $lrc_user);
usage("The LRC user password must be specified") unless(defined $lrc_passwd);
usage("The path where to migrate the RLS entries must be specified") unless(defined $path);
usage("The file containing the entries must be specified") unless(defined $file);
usage("The LRC/RMC database host or Oracle SID must be specified") unless(defined $host);


if ($db_vendor eq "Oracle") {
	usage("The RLS database Oracle SID must be specified") unless(defined $host);
} elsif ($db_vendor eq "MySQL") { 
	usage("The host where the MySQL server resides must be specified") unless(defined $host);
} else {
	usage("The Database type can only be \'Oracle\' or \'MySQL\'");
}

# useful variables
my ($start_time, $time, $end_time);
my ($dbh_lrc);
my ($lrc);
my $select;
my $count;

eval {

$start_time = localtime();
print "$start_time : Starting to migrate data from the RLS to the LFC.\n"; 
print "Please wait...\n";

if ($db_vendor eq "Oracle") {
        $lrc = $lrc_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);
	}

} elsif ($db_vendor eq "MySQL") {
        $lrc = "edg_lrcdb";
}

#
# connect to the LRC database
#

$dbh_lrc = Common::connectToDatabase("edg_lrcdb", $lrc_user, $lrc_passwd, $db_vendor, $host);


#
# read the entry file and update the LFC
# 

$count = Cms::queryFromRLSAndFileAndUpdateLFC($dbh_lrc, $lrc_user, $file);


#
# disconnect from the LRC database
#

$dbh_lrc->disconnect;


#
# The migration is over
#

$end_time = localtime();
print "$end_time : The data migration from the RLS to the LFC is over : $count entries have been migrated.\n";

if ($verbose) {
	print "db vendor = $db_vendor";
	print "host = $host\n"; 
	print "lrc user = $lrc_user\n";
	print "lrc password = $lrc_passwd\n";
        print "path= $path\n";
}

};
die ("failed to query information from the LRC table : $@") if ($@);