From 959edbaef15aa063912f6a77e1e75e2f4eacf696 Mon Sep 17 00:00:00 2001 From: diaz Date: Mon, 22 Jun 2026 14:52:08 +0200 Subject: [PATCH] script to copy data from the e-account to the p-group --- rsync_on_pgroup | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 rsync_on_pgroup diff --git a/rsync_on_pgroup b/rsync_on_pgroup new file mode 100755 index 0000000..1fb1065 --- /dev/null +++ b/rsync_on_pgroup @@ -0,0 +1,77 @@ +#!/bin/bash + +if [ ! $# -ge 2 ]; then { + echo "1. Log in to ra.psi.ch as yourself" + echo "2. cd to /sls/x12sa/data//raw/bin" + echo "3. Run this script there" + echo "Usage: $0 <0-skip nexus data files, 1-copy nexus data files><*optional* source directory><*optional* target directory>" + echo "Example: $0 p16000 0" + echo "Example: $0 p16000 0 /sls/x12sa/data/p16000/raw/ /das/work/p16/p16000" + echo "The script runs into a timeout if there have not been any changes for 3 days." + exit +} fi + +# make sure we are on DaaS +host_full=`hostname` +host=`echo $host_full | awk -F'-' '{print $1}'` +if [ $host != 'ra' ]; then + echo 'Unknown host. Please login to ra.psi.ch as yourself and run the script again.' + exit +fi + +eaccount=$1 + +# source directory +sourceDir="/sls/x12sa/data/$1/raw" + + +subDir="p${eaccount:1:2}" +destDir="/das/work/$subDir/$eaccount/online_data" + + +if [ ! -z "$3" ]; then + sourceDir=$3 +fi +if [ ! -z "$4" ]; then + destDir=$4 +fi + +cd /sls/x12sa/data/$1/raw/bin + +# create destination directory + +if [ ! -d "$destDir" ]; then { + mkdir "$destDir" +}; fi + +if [ $2 == 0 ]; then { + echo skipping data nexus directory +} else { + echo copying data nexus directory +}; fi + +# endless loop to be stopped by CTRL-C +while (true); do { + + if [ $2 == 0 ]; then { + echo "rsync all data except the nexus data" + rsync --chmod=ug=rwx -p --verbose --modify-window=1 --times --recursive --exclude='data' $sourceDir/* "$destDir" + } else { + echo "rsync all files from raw" + rsync --chmod=ug=rwx -p --verbose --modify-window=1 --times --recursive $sourceDir/* "$destDir" + }; fi + df -h "$1" + date + # sleep half an hour + #chmod -R ug=r "$destDir" + old_time="$(find $destDir -type f -exec stat \{} --printf="%y\n" \; | sort -n -r | head -n 1)" + old_time="$(date -d "$old_time" "+%s")" + current_time="$(date -d '3 days ago' '+%s')" + if [ "$current_time" -ge "$old_time" ]; then + echo "Could not find any changes in the last few days." + exit + fi + sleep 1800 + +}; done +