Skip to content

Commit

Permalink
add ssh_key explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdenhollander committed May 23, 2024
1 parent 2ad9ecb commit 2bc0b65
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions amstrax/auto_processing/copy_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def parse_args():
help='The minimum run number to start copying from')
parser.add_argument('--production', action='store_true', default=False,
help='If you want to run the script in production mode')
parser.add_argument('--ssh_key', type=str, default="/home/xams/.ssh/xams_key",
help='Path to the ssh-key used to ssh to remote location')
return parser.parse_args()


Expand Down Expand Up @@ -105,7 +107,7 @@ def process_query(query):

return list(rundocs)

def copy_data(run_id, live_data_path, location, hostname, production, ssh_host):
def copy_data(run_id, live_data_path, location, hostname, production, ssh_host, ssh_key):
"""
Copy data to the specified location using rsync.
"""
Expand All @@ -120,7 +122,7 @@ def copy_data(run_id, live_data_path, location, hostname, production, ssh_host):
return

log.info(f"Copying run {run_id} to {location}")
copy_cmd = ['rsync', '-av', live_data_path, f'{ssh_host}:{location}']
copy_cmd = ['rsync', '-av','-e', f"ssh -i {ssh_key}", live_data_path, f'{ssh_host}:{location}']
copy = subprocess.run(copy_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if copy.returncode != 0:
Expand Down Expand Up @@ -156,7 +158,7 @@ def handle_runs(rundocs, args):
# Check if data is on stoomboot and copy if not
copied_stomboot = False
if not any(d['type'] == 'live' and d['host'] == 'stbc' for d in rd['data']):
exit_code = copy_data(run_id, live_data_path, STORAGE_PATHS['stbc'], 'stbc', args.production, args.ssh_host)
exit_code = copy_data(run_id, live_data_path, STORAGE_PATHS['stbc'], 'stbc', args.production, args.ssh_host, args.ssh_key)
copied_stomboot = (exit_code == 0)
else:
# it was already on stoomboot
Expand All @@ -165,7 +167,7 @@ def handle_runs(rundocs, args):
if copied_stomboot:
# Check if data is on dcache and copy if not (and if not only_stoomboot)
if not args.only_stoomboot and (not any(d['type'] == 'live' and d['host'] == 'dcache' for d in rd['data'])):
copy_data(run_id, live_data_path, STORAGE_PATHS['dcache'], 'dcache', args.production, args.ssh_host)
copy_data(run_id, live_data_path, STORAGE_PATHS['dcache'], 'dcache', args.production, args.ssh_host, args.ssh_key)
runs_copied = True

return runs_copied
Expand Down

0 comments on commit 2bc0b65

Please sign in to comment.