forked from NOAA-EMC/global-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexglobal_archive_tars.py
More file actions
executable file
·51 lines (35 loc) · 1.66 KB
/
exglobal_archive_tars.py
File metadata and controls
executable file
·51 lines (35 loc) · 1.66 KB
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
#!/usr/bin/env python3
import os
from pygfs.task.archive import Archive
from pygfs.utils.archive_tar_vars import ArchiveTarVars
from wxflow import AttrDict, Logger, cast_strdict_as_dtypedict, logit, chdir
# initialize root logger
logger = Logger(level=os.environ.get("LOGGING_LEVEL", "DEBUG"), colored_log=True)
@logit(logger)
def main():
config = cast_strdict_as_dtypedict(os.environ)
# Instantiate the Archive object
archive = Archive(config)
# update these keys to be 3 digits if they are part of archive.task_config.keys
for key in ['OCNRES', 'ICERES']:
try:
archive.task_config[key] = f"{archive.task_config[key]:03d}"
except KeyError:
logger.info(f"key ({key}) not found in archive.task_config!")
# Collect all variables for YAML templates (config keys, COM paths, cycle vars, member paths)
# Note: COM paths are relative to ROTDIR for portability in tar archives
archive_dict = ArchiveTarVars.get_all_yaml_vars(archive.task_config)
with chdir(config.ROTDIR):
logger.debug(f"Changed working directory to {config.ROTDIR}")
# Determine which archives to create
atardir_sets = archive.configure_tars(archive_dict)
# Create the backup tarballs and store in ATARDIR
for atardir_set in atardir_sets:
logger.debug(f"Processing archive set: {atardir_set['name']}")
archive.execute_backup_dataset(atardir_set)
# Clean up any temporary files
logger.debug("Cleaning up temporary files and directories")
archive.clean()
logger.info(f"Returned to working directory {os.getcwd()}")
if __name__ == '__main__':
main()