Commit 7cb557ca authored by Jonathan Schaeffer's avatar Jonathan Schaeffer
Browse files

Création du script de dump

parent 7eeb89bb
# datadump
Export des données RESIF
\ No newline at end of file
Export des données RESIF
## Workflow
Description du workflow dans notre wiki : https://wiki.osug.fr/!isterre-geodata/resif/systemes/services/datadump
#!/bin/bash
# Auteur: Jonathan Schaeffer <jonathan.schaeffer@univ-grenoble-alpes.fr>
# Tests de l'environnement
# Il faut que les variables d'environnements suivantes soient positionnées sur des valeurs valides
# - RESIFDD_DATADIR
# - RESIFDD_WORKDIR
# Print a message using logger
# Arguments:
# $1 : message
# $2 : severity (optionnal, default is INFO)
log(){
[[ -z $2 ]] && severity="info" || severity=$2
logger -t resifdd -p local3.$severity $1
}
# Test for working directory
if [[ ! -w $RESIFDD_WORKDIR ]] ; then
log "RESIFDD_WORKDIR $RESIFDD_WORKDIR not writable. Check permissions"
exit 1
fi
# Go to the data directory where to dump everything from
if [[ -z $RESIFDD_DATADIR ]]; then
log "Variable RESIFDD_DATADIR must be set to the RESIF mountpoint" "error"
exit 1
fi
if [[ ! -d $RESIFDD_DATADIR ]]; then
log "Variable RESIFDD_DATADIR set to $RESIFDD_DATADIR must be a directory" "error"
exit 1
fi
# Get the snapshot name for this month
MONTH=$(date +%Y-%m)
SNAPSHOT_DIR="${RESIFDD_DATADIR}/validated_seismic_data/.snapshot/monthly.${MONTH}-01_0000"
if [[ ! -d $SNAPSHOT_DIR ]]; then
log "Snapshot directory $SNAPSHOT_DIR does not exist" "error"
exit 1
fi
# Checking IRODS environment
# TODO
# Start dumping validated data
DATADIR=${RESIFDD_DATADIR}/validated_seismic_data/${SNAPSHOT_DIR}
cd $DATADIR
for dir in $(find . -type d -maxdepth 3); do
IFS='/' read -r -a YNS <<< $dir
YEAR=YNS[0]
NETWORK=YNS[1]
STATION=YNS[2]
logger "Going to tar data from $YEAR $NETWORK.$STATION"
tar cf $RESIFDD_WORKDIR/$YEAR_$NETWORK_$STATION.tar -C $DATADIR $dir
# Check if file exists on irods server
# Check hash on irods server
# Compare to local hash
# If the hashes differs, then move distant file and push this one
logger "Cleaning generated tar $RESIFDD_WORKDIR/$YEAR_$NETWORK_$STATION.tar"
done
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