#!/bin/bash ################################################################# # Author: Alessandra Forti # Created: 14/01/2012 ################################################################# # Local settings fs_path=/raid head_node=bohr3226.tier2.hep.manchester.ac.uk dry_run='yes' # Variable necessary to the DPM admin tools export PATH=/opt/lcg/bin:$PATH export PYTHONPATH=/opt/lcg/lib64/python export DPNS_HOST="$head_node" export DPM_HOST=$DPNS_HOST ######################################### host=`hostname` date_ext=`date +%Y%m%d` # Creating DB files list echo "Creating DB files list" db_file=db-files-${date_ext}.txt dpm-list-disk -s $host |sed -r 's/.*://g'|sed -r 's/ .*//g' |grep -v Found> db.tmp # Checking if there are any entries if not something gone wrong exit if [ `grep $fs_path db.tmp |wc -l` != 0 ] ; then sort db.tmp > $db_file else echo "dpm-list-disk failed." exit fi # Creating FS files list echo "Creating FS files list" fs_file=fs-files-${date_ext}.txt # Checking mountpoint in case by some freak accident it's not mounted mountpoint -q $fs_path if [ $? -ne 0 ] ; then echo "The path $fs_path is not mounted" exit fi find $fs_path -name '*' -type f > fs.tmp # Checking if there are any entries if not something really wrong with the FS if [ `grep $fs_path fs.tmp |wc -l` -ne 0 ] ; then sort fs.tmp > $fs_file else echo "I can't get the file list in $fs_path" exit fi # Diffing the lists echo "Creating diff-dump-fs.txt" diff_file=diff-db-fs-${date_ext}.txt diff -bB $db_file $fs_file | grep -v lost+found |egrep '>|<' > $diff_file # Creating each separate list of orphane DB entries and orphan files echo "Creating indb-not-ondisk.txt and ondisk-not-indb.txt" grep '<' $diff_file | sed "s/< /$host:/g" > indb-not-ondisk.txt grep '>' $diff_file | sed 's/> //g' > ondisk-not-indb.txt # Cleaning up orphan files echo "Cleaning up orphan files" for a in `cat ondisk-not-indb.txt`; do # Dry run? if [ "$dry_run" == "yes" ]; then echo "To be deleted $dpns_path" elif [ "$dry_run" == "no" ]; then echo "Deleting $dpns_path" rm -f $a else echo "$dry_run option not understood" fi done # Cleaning up orphan DB entries echo "Cleaning up orphan DB entries" surl_file=`hostname -s`-surl-lost-${date_ext}.txt for a in `cat indb-not-ondisk.txt`; do dpns_path=`dpm-sql-pfn-to-dpns $a | awk '{print $2}' | sed -r 's%/$%%'` # Create SURL file for atlas surl="srm://$head_node${dpns_path}" echo $surl >> $surl_file # Dry run? if [ "$dry_run" == "yes" ]; then echo "To be deleted $dpns_path" elif [ "$dry_run" == "no" ]; then echo "Deleting $dpns_path" rfrm $dpns_path else echo "$dry_run option not understood" fi done wc -l indb-not-ondisk.txt ondisk-not-indb.txt rm -f db.tmp fs.tmp