-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_wallops_rawacfs.py
executable file
·63 lines (50 loc) · 1.99 KB
/
sync_wallops_rawacfs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
"""
Script: Sync Wallops rawACFs
Description: This script syncs yesterday's files from Wallops to APL
"""
import sys
import subprocess
import datetime
import os
def parse_date(date_str):
try:
return datetime.datetime.strptime(date_str, "%Y%m%d").date()
except ValueError:
print("Invalid date format. Please use YYYYMMDD.")
sys.exit(1)
# Get the date argument if provided, or default to yesterday's date
if len(sys.argv) > 1:
date_str = sys.argv[1]
target_date = parse_date(date_str)
else:
target_date = datetime.date.today() - datetime.timedelta(days=1)
# Format the date components
year = target_date.strftime('%Y')
month = target_date.strftime('%m')
day = target_date.strftime('%d')
# Define the server and path components
borealis_server = "[email protected]"
path = f"/borealis_nfs/borealis_data/rawacf_dmap/{year}{month}{day}*"
# Create the source and destination paths
source_path = f"{borealis_server}:{path}"
destination_path = f"/project/superdarn/data/rawacf/{year}/{month}"
# Create the destination directory if it doesn't exist
os.makedirs(destination_path, exist_ok=True)
# Get a list of the files to sync
files_to_sync = subprocess.check_output(f"ssh {borealis_server} 'ls {
path}'", shell=True, stderr=subprocess.DEVNULL)
files_to_sync = files_to_sync.decode().strip().split("\n")
# Iterate over the files to sync and only sync them if they don't already exist at APL
for file_to_sync in files_to_sync:
filename = os.path.basename(file_to_sync)
destination_file = os.path.join(destination_path, filename)
if not os.path.exists(destination_file):
# Construct the scp command
command = f"scp -r {borealis_server}:{file_to_sync} {destination_path}"
# Execute the command
subprocess.call(command, shell=True, stderr=subprocess.DEVNULL)
print(f"Synced file: {filename}")
else:
print(f"File already exists: {filename}")
print("Sync completed.")