westdc-zf1/tools/md-thumb-restore.php

33 lines
959 B
PHP
Executable File

#!/usr/bin/php
<?php
if ($_SERVER["argc"]<4)
{
print "Usage: md-thumb-restore.php CSV_FILE BACKUP_DIR GN_DATA_DIR\n";
print "\tCSV_FILE:\t the CSV format file which contain id and uuid column\n";
print "\tBACKUP_DIR:\t the destincation directory to backup\n";
print "\tGN_DATA_DIR:\t the old Geonetwork data directory\n";
die();
}
$csv=$_SERVER["argv"][1];
$backup_dir=$_SERVER["argv"][2];
$data_dir=$_SERVER["argv"][3];
if (substr($data_dir,-1)!="/")
$data_dir.="/";
if (substr($backup_dir,-1)!="/")
$backup_dir.="/";
$fp=fopen($csv,'rb');
$dus=fread($fp,filesize($csv));
fclose($fp);
$duuids=explode("\n",$dus);
foreach($duuids as $duuid1)
{
$duuid2=explode(";",$duuid1);
if ($duuid2[0]>0)
{
$newdir=$data_dir.sprintf('%05d',floor(($duuid2[0]+0.1)/100)*100).'-'.sprintf('%05d',ceil(($duuid2[0]+0.1)/100)*100-1)."/".$duuid2[0];
print $dir."\n";
$dir=$backup_dir.trim($duuid2[1]);
rename($dir,$newdir);
}
}
?>