实现数据库抽取以及文件读取判断功能
This commit is contained in:
parent
da8bd2f307
commit
776d054838
|
@ -3,3 +3,5 @@
|
||||||
* 从数据库提取数据文件,生成包含数据集uuid、path、volume、count信息的文本
|
* 从数据库提取数据文件,生成包含数据集uuid、path、volume、count信息的文本
|
||||||
* 逐条检查数据集的文件大小和数量,记录异常数据集
|
* 逐条检查数据集的文件大小和数量,记录异常数据集
|
||||||
* 将结果通过邮件进行发送
|
* 将结果通过邮件进行发送
|
||||||
|
|
||||||
|
只检查对外公开的数据集,并且有实体的数据集。
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
$link = pg_connect("dbname=metadata user=gis password=gispassword host=210.77.68.241");
|
||||||
|
$host='ftp2.westgis.ac.cn';
|
||||||
|
$sql="select d.uuid,sum(df.filesize) as volume,count(df.id) as fcount,d.path from dataset d left join mdstatus ms on d.uuid=ms.uuid
|
||||||
|
left join datafile df on d.id=df.dsid
|
||||||
|
where ms.status>4 and d.host='".$host."' group by d.id,d.uuid,d.path";
|
||||||
|
$result = pg_query($link, $sql);
|
||||||
|
$numrows = pg_num_rows($result);
|
||||||
|
$content='';
|
||||||
|
for($ri = 0; $ri < $numrows; $ri++)
|
||||||
|
{
|
||||||
|
$row = pg_fetch_array($result, $ri);
|
||||||
|
$content.=$row['uuid']."\t";
|
||||||
|
$content.=$row['volume']."\t";
|
||||||
|
$content.=$row['fcount']."\t";
|
||||||
|
$content.=$row['path']."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename='./dataset-0.txt';
|
||||||
|
if (!empty($content))
|
||||||
|
if (!file_put_contents($filename, $content, LOCK_EX))
|
||||||
|
{
|
||||||
|
sleep(1);
|
||||||
|
if (!file_put_contents($filename, $content, LOCK_EX))
|
||||||
|
{
|
||||||
|
sleep(1);
|
||||||
|
if (!file_put_contents($filename, $content, LOCK_EX))
|
||||||
|
die("error in write dataset-0.txt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pg_free_result($result);
|
||||||
|
pg_close($link);
|
|
@ -0,0 +1,15 @@
|
||||||
|
#!/bin/bash
|
||||||
|
rm dataset-1.txt
|
||||||
|
cat dataset-0.txt | while read oneline;
|
||||||
|
do
|
||||||
|
uuid=`echo $oneline | awk '{print $1}'`
|
||||||
|
datapath=`echo "$oneline" | awk -F'\t' '{print $4}'`
|
||||||
|
fcount=`find -L "$datapath"/* | wc -l`
|
||||||
|
if [ $fcount -gt 0 ]; then
|
||||||
|
volume=`du -sbL "$datapath"/* | awk '{a+=$1}END{print a}'`
|
||||||
|
echo -e $uuid'\t'$volume'\t'$fcount'\t'$datapath >> dataset-1.txt
|
||||||
|
else
|
||||||
|
echo $datapath;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exit 0
|
Loading…
Reference in New Issue