- Timestamp:
- May 23, 2018, 6:21:26 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tools/stsci_disks/p4_restore.pl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/stsci_disks/p4_restore.pl
r38684 r40443 29 29 30 30 my ( $db, $dbhost, $dbpass, $dbuser); 31 my $conffile = "/home/panstarrs/ipp/ippconfig/nebulous.config"; 31 #my $conffile = "/home/panstarrs/ipp/ippconfig/nebulous.config"; 32 my $conffile = '/data/ippc64.1/ippitc/ippconfig/nebulous.config'; 33 32 34 if (-e $conffile) { 33 35 # printf STDERR "found config\n"; … … 53 55 54 56 pod2usage( -msg => "Cannot configure nebulous database", -exitval => 2) unless 55 defined $host && defined $volume && defined $dir && 57 defined $host && defined $volume && defined $dir && 56 58 defined $db && defined $dbhost && defined $dbuser && defined $dbpass; 57 59 … … 71 73 my $time = time(); 72 74 73 my $dbh = DBI->connect( 74 "DBI:mysql:database=$db:host=$dbhost", 75 $dbuser, 76 $dbpass, 77 { 78 RaiseError => 1, 79 PrintError => 0, 80 AutoCommit => 1, 81 }, 82 ); 75 76 #$dbhost = '166.122.172.39'; 77 #my $dbport = '3308'; 78 #my $dbh = DBI->connect( 79 # "DBI:mysql:database=$db:host=$dbhost:port=$dbport", 80 # $dbuser, 81 # $dbpass, 82 # { 83 # RaiseError => 1, 84 # PrintError => 0, 85 # AutoCommit => 1, 86 # }, 87 # ); 88 use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock'; 89 90 my $dbh = DBI->connect("DBI:mysql:database=${db};host=${dbhost};" . 91 "mysql_socket=" . DB_SOCKET(), 92 ${dbuser},${dbpass}, 93 { RaiseError => 1, AutoCommit => 1} 94 ) or die "Unable to connect to database $DBI::errstr\n"; 83 95 84 96 85 my $logDest = "neb://any/stsci_shuffle/restore/${host}.${volume}/${source}.${volume}/${dir}.log.${time}"; 97 my $logDest = "/export/${host}.${volume}/retire_rsync/restore/${host}.${volume}/${source}.${volume}/${dir}.log.${time}"; 98 99 #if ((${host} eq 'ippb04')&&($volume == 2)) { 100 # $logDest = "/export/${host}.0/stsci_shuffle/restore/${host}.${volume}/${source}.${volume}/${dir}.log.${time}"; 101 #} 102 86 103 my $ipprc = PS::IPP::Config->new( "GPC1" ) or die "Could not create config object.\n"; 87 104 $ipprc->redirect_output($logDest) or die "Could not redirect output to logfile ${logDest}\n"; 88 105 89 my $root = "/export/${host}.${volume}/ stsci_shuffle/${source}.${source_vol}/nebulous/${dir}";106 my $root = "/export/${host}.${volume}/retire_rsync/data/${source}.${source_vol}/nebulous/${dir}"; 90 107 my @subdirectories = <$root/*>; 91 108 … … 113 130 114 131 my $destination_subdir = $subdir; 115 $destination_subdir =~ s%/ stsci_shuffle/${source}.${source_vol}/nebulous%/nebulous%;132 $destination_subdir =~ s%/retire_rsync/data/${source}.${source_vol}/nebulous%/nebulous%; 116 133 117 134 my @files = <${subdir}/*>; … … 121 138 print "LOG BEGIN $subdir $time $dtime\n"; 122 139 for (my $i = 0; $i <= $#files; $i++) { 123 my $f = $files[$i];140 my $f = $files[$i]; 124 141 my ($ins_id); 125 142 $ins_id = $f; 126 143 $ins_id =~ s/^$subdir\///; 127 144 $ins_id =~ s/\..*//; 128 129 # Write log of what we plan to do.130 my $destination_f = $f;131 $destination_f =~ s%/stsci_shuffle/${source}.${source_vol}/nebulous%/nebulous%;132 133 my $db_uri = $destination_f;134 $db_uri =~ s%^/export/%/data/%;135 $db_uri = 'file://' . $db_uri;136 145 137 print "$ins_id $f $destination_f $db_uri\n"; 146 # Write log of what we plan to do. 147 my $destination_f = $f; 148 $destination_f =~ s%/retire_rsync/data/${source}.${source_vol}/nebulous%/nebulous%; 138 149 139 # die; 150 my $db_uri = $destination_f; 151 $db_uri =~ s%^/export/%/data/%; 152 $db_uri = 'file://' . $db_uri; 140 153 141 # Do move of file. 142 if (-e $destination_f) { 143 print "FILE ALREADY FOUND\n"; 144 next; 145 } 154 print "$ins_id $f $destination_f $db_uri\n"; 146 155 147 my $validate_ins_id_query = "SELECT * FROM instance WHERE vol_id = ${source_vol_id} AND ins_id = ${ins_id}"; 148 my @instances = $dbh->selectall_arrayref( $validate_ins_id_query ); 149 if ($#instances != 0) { # We expect one instance on the source 150 print "NO DB ENTRY\n"; 151 next; 152 } 153 # print "PASSED DB CHECK: $#instances\n"; 154 # system("stat ${f}"); 155 system("mv ${f} ${destination_f}"); 156 # system("stat ${destination_f}"); 156 # die; 157 157 158 # Register database change: 158 # Do move of file. 159 if (-e $destination_f) { 160 print "FILE ALREADY FOUND\n"; 161 next; 162 } 159 163 160 unless (-e $destination_f) { 161 die; 162 } 163 164 $query = $dbh->prepare( $sql->update_instance_uri ); 165 $query->execute( $local_vol_id, $db_uri, $ins_id ); 166 $query->finish; 167 # die; 164 my $validate_ins_id_query = "SELECT * FROM instance WHERE vol_id = ${source_vol_id} AND ins_id = ${ins_id}"; 165 my @instances = $dbh->selectall_arrayref( $validate_ins_id_query ); 166 if ($#instances != 0) { # We expect one instance on the source 167 print "NO DB ENTRY\n"; 168 next; 169 } 170 171 172 # print "PASSED DB CHECK: $#instances\n"; 173 # system("stat ${f}"); 174 system("mv ${f} ${destination_f}"); 175 # system("stat ${destination_f}"); 176 177 # Register database change: 178 179 unless (-e $destination_f) { 180 die; 181 } 182 183 $query = $dbh->prepare( $sql->update_instance_uri ); 184 $query->execute( $local_vol_id, $db_uri, $ins_id ); 185 $query->finish; 186 # die; 168 187 } # END loop over files 169 188 rmdir($subdir);
Note:
See TracChangeset
for help on using the changeset viewer.
