File: migrate_data_atlas

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 (124 lines) | stat: -rwxr-xr-x 3,824 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
#!/usr/bin/perl

#
# Script that migrates the Atlas data 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 FindBin;
use lib "$FindBin::Bin/../lib";
use Common;
use Atlas;
use AliceAndLHCB;
use CMS;

sub usage($) {
  my $reason = shift(@_);
  print <<EOF and   die "\nWrong usage of the script: $reason.\n";
usage: $0 --sid sid --lrc-user lrc_user --lrc-passwd lrc_passwd --rmc-user rmc_user --rmc-passwd rmc_passwd --lfc-sid lfc_sid --lfc-user lfc_user --lfc-passwd lfc_passwd [--verbose]
EOF
}

# Create arguments variables...
my ($vo, $sid, $lfc_sid, $lrc_user, $lrc_passwd, $rmc_user, $rmc_passwd, $lfc_user, $lfc_passwd, $verbose);

# ... and read the arguments
GetOptions("vo:s", => \$vo,
	   "sid:s", => \$sid,
           "lfc-sid:s", => \$lfc_sid,
	   "lrc-user:s", => \$lrc_user,
	   "lrc-passwd:s", => \$lrc_passwd,
	   "rmc-user:s", => \$rmc_user,
	   "rmc-passwd:s", => \$rmc_passwd,
           "lfc-user:s", => \$lfc_user,
           "lfc-passwd:s", => \$lfc_passwd,
	   "verbose" => \$verbose );

# check CLI consistency
usage("The VO must be specified. The possible VOs are : alice, atlas, cms and lhcb.") unless(defined $vo);
usage("The RLS database SID must be specified") unless(defined $sid);
usage("The LFC database SID must be specified") unless(defined $lfc_sid);
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 RMC database user must be specified") unless(defined $rmc_user);
usage("The RMC user password must be specified") unless(defined $rmc_passwd);
usage("The LFC database user must be specified") unless(defined $lfc_user);
usage("The LFC user password must be specified") unless(defined $lfc_passwd);

# useful variables
my ($start_time, $time, $end_time);
my ($dbh_lrc, $dbh_rmc, $dbh_lfc);
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";

#
# First grant select privileges to the RMC user on the LRC tables
#
    $dbh_lrc = Common::connectToDatabase($sid, $lrc_user, $lrc_passwd);

    Common::grantSelectPrivileges($dbh_lrc, "guid", $rmc_user);
    Common::grantSelectPrivileges($dbh_lrc, "pfn", $rmc_user);

    $dbh_lrc->disconnect;

#
# Connect to the LFC database 
# -> to directly add the creation time, as the C API only allows to set the time to the current time)
#

    $dbh_lfc = Common::connectToDatabase($lfc_sid, $lfc_user, $lfc_passwd);

#
# Then, connect to the RMC database and query all the information from the LRC and RMC tables
#
    $dbh_rmc = Common::connectToDatabase($sid, $rmc_user, $rmc_passwd);

    if ($vo eq "atlas") {
	$count = Atlas::queryFromRLSAndUpdateLFC($dbh_lfc, $dbh_rmc, $lrc_user, $rmc_user);
    }

    if ($vo eq "alice" || $vo eq "lhcb") {
	$count = AliceAndLHCB::queryFromRLSAndUpdateLFC($dbh_lfc, $dbh_rmc, $lrc_user, $rmc_user, $vo);
    }

    if ($vo eq "cms") {
	print "The migration for CMS doesn't take into account the POOL attributes yet.\n";
	$count = CMS::queryFromRLSAndUpdateLFC($dbh_lfc, $dbh_rmc, $lrc_user, $rmc_user);
    }

    $dbh_rmc->disconnect;

    $dbh_lfc->disconnect;

#
# Finally, revoke the select privileges
#
    $dbh_lrc = Common::connectToDatabase($sid, $lrc_user, $lrc_passwd);

    Common::revokeSelectPrivileges($dbh_lrc, "guid", $rmc_user);
    Common::revokeSelectPrivileges($dbh_lrc, "pfn", $rmc_user);

    $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.";

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