#!/bin/bash
#SBATCH -n 1
#SBATCH -t 01:00:00
#SBATCH -J gfasftp
#SBATCH -e /esarchive/recon/ecmwf/gfas/scripts/i535-marc-hourly/out-logs/format-ftp-%j.err
#SBATCH -o /esarchive/recon/ecmwf/gfas/scripts/i535-marc-hourly/out-logs/format-ftp-%j.out

# change permissions
chmod -R 770 $3/$1/$4/$2/
            #dl_root/network/original_files:metadata/version/

if [ $4 == 'metadata' ] # sync all metadata
then
        # sync data
    ssh transfer1 << EOF 
        dtrsync -rvzh --groupmap=*:bsc32 /gpfs/archive/bsc32$3/$1/$4/ /gpfs/projects/bsc32/AC_cache/obs/ghost/$1/$4

EOF

else # sync only data of current version
    ssh transfer1 << EOF 
        dtrsync -rvzh --groupmap=*:bsc32 /gpfs/archive/bsc32$3/$1/$4/$2/ /gpfs/projects/bsc32/AC_cache/obs/ghost/$1/$4/$2

EOF
fi