Commit caa6153b authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

indentation

parent b6957199
......@@ -18,34 +18,34 @@ workdir=/scratch/resif_datadump/test_restore
archivedir=/osug-dc/resif/validated_seismic_data
if [[ $# -eq 0 ]]; then
# Pas de clé en paramètre, récupère un channel au hasard dans les métadonnées
line=$(wget -q -O - "http://ws.resif.fr/fdsnws/station/1/query?level=channel&format=text" | shuf -n 1)
echo $line
[[ $line =~ ^(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|([1-2][0-9][0-9][0-9]).*\|([1-2][0-9][0-9][0-9]).*$ ]]
net=${BASH_REMATCH[1]}
sta=${BASH_REMATCH[2]}
start=${BASH_REMATCH[16]}
end=${BASH_REMATCH[17]}
echo "$start $end"
if [[ $start -eq $end ]]; then
year=$start
else
if [[ "$end" = "2500" ]]; then
# Les canaux permanents finissenten 2500, on ramène à l'année de 6 mois plus tôt (le dernier dump)
end=$(date +%Y -d '6 months ago')
fi
year=$(( ( RANDOM % (( $end - $start )) ) + $start ))
fi
key="${year}_${net}_${sta}"
# Pas de clé en paramètre, récupère un channel au hasard dans les métadonnées
line=$(wget -q -O - "http://ws.resif.fr/fdsnws/station/1/query?level=channel&format=text" | shuf -n 1)
echo $line
[[ $line =~ ^(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|([1-2][0-9][0-9][0-9]).*\|([1-2][0-9][0-9][0-9]).*$ ]]
net=${BASH_REMATCH[1]}
sta=${BASH_REMATCH[2]}
start=${BASH_REMATCH[16]}
end=${BASH_REMATCH[17]}
echo "$start $end"
if [[ $start -eq $end ]]; then
year=$start
else
if [[ "$end" = "2500" ]]; then
# Les canaux permanents finissenten 2500, on ramène à l'année de 6 mois plus tôt (le dernier dump)
end=$(date +%Y -d '6 months ago')
fi
year=$(( ( RANDOM % (( $end - $start )) ) + $start ))
fi
key="${year}_${net}_${sta}"
else
key=$1
key=$1
fi
# On teste pour vérifier que cette donnée existe (c'est pas forcé)
dir_to_test=$(echo $key | tr '_' '/')
stat $archivedir/$dir_to_test
if [[ $? -ne 0 ]]; then
printf "\033[1;33mWARNING\033[0m no data for this channel on archive\n"
exit 0
printf "\033[1;33mWARNING\033[0m no data for this channel on archive\n"
exit 0
fi
workdir=$workdir/$key
mkdir -p $workdir
......@@ -54,24 +54,21 @@ cd $workdir
echo === Trying to retrieve $key ===
ils -L $key/latest.tar
if [[ $? -ne 0 ]]; then
printf "\033[0;31mError\033[0m Remote file not found.\n"
exit 1
printf "\033[0;31mError\033[0m Remote file not found.\n"
exit 1
else
printf "\033[0;32mOK\033[0m\n"
printf "\033[0;32mOK\033[0m\n"
fi
echo === Retrieving $key ===
iget $key/latest.tar
if [[ $? -ne 0 ]]; then
printf "\033[0;31mError\033[0m iget command failed\n"
exit 1
printf "\033[0;31mError\033[0m iget command failed\n"
exit 1
else
printf "\033[0;32mOK\033[0m\n"
printf "\033[0;32mOK\033[0m\n"
fi
echo === Listing archive content ===
tar tvf latest.tar
echo === Extracting one random file ===
target_line=$(tar tvf latest.tar | grep -e '[0-9]$' | shuf -n 1)
target_file=$(echo "$target_line"| awk '{print $NF}')
......@@ -83,47 +80,41 @@ echo $fname
regex="([A-Z0-9]+)\.([A-Z]+)\.[0-9]*\.([A-Z0-9]{3}\.D)\.([12][0-9]{3})\.[0-3][0-9]{2}"
archive_file=""
if [[ $fname =~ $regex ]]; then
archive_file="$archivedir/${BASH_REMATCH[4]}/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/${BASH_REMATCH[3]}/$fname";
archive_file="$archivedir/${BASH_REMATCH[4]}/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/${BASH_REMATCH[3]}/$fname";
if [[ ! -r $archive_file ]]; then
printf "\033[1;33mWARNING\033[0m $archive_file not preset\n"
exit 1
fi
printf "\033[1;33mWARNING\033[0m $archive_file not preset\n"
exit 1
fi
fi
echo $archive_file
archive_file_date=$(date +%s -d $(stat $archive_file --print %z | awk '{print $1}'))
if [ $archive_file_date -gt $target_file_date ]; then
echo "File in archive is newer than remote file. Skipping md5 test"
echo "File in archive is newer than remote file. Skipping md5 test"
else
echo === Checking md5 ===
dumped_md5=$(md5sum $target_file | awk '{print $1}')
data_md5=$(md5sum $archive_file | awk '{print $1}')
echo $dumped_md5 $target_file
echo $data_md5 $archive_file
if [[ $dumped_md5 == $data_md5 ]]; then
printf "\033[0;32mOK\033[0m $target_file md5 sum is correct\n"
else
printf "\033[0;31mError\033[0m Files $target_file and $archive_file mismatch\n"
exit 1
fi
echo === Checking md5 ===
dumped_md5=$(md5sum $target_file | awk '{print $1}')
data_md5=$(md5sum $archive_file | awk '{print $1}')
echo $dumped_md5 $target_file
echo $data_md5 $archive_file
if [[ $dumped_md5 == $data_md5 ]]; then
printf "\033[0;32mOK\033[0m $target_file md5 sum is correct\n"
else
printf "\033[0;31mError\033[0m Files $target_file and $archive_file mismatch\n"
exit 1
fi
fi
echo === Compare msi traces ===
dumped_msi=$(msi $target_file)
data_msi=$(msi $archive_file)
echo "Traces of remote file $target_file"
echo "$dumped_msi"
echo "Traces of local file $archive_file"
echo "$data_msi"
if [[ $(md5sum <<< $dumped_msi | awk '{print $1}') == $(md5sum <<< $data_msi | awk '{print $1}') ]]; then
printf "\033[0;32mOK\033[0m Traces match\n"
printf "\033[0;32mOK\033[0m Traces match\n"
else
printf "\033[1;33mWARNING\033[0m Traces mismatch\n"
echo "Traces of remote file $target_file"
echo "$dumped_msi"
echo "Traces of local file $archive_file"
echo "$data_msi"
printf "\033[1;33mWARNING\033[0m Traces mismatch\n"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment