Skip to content

Commit 9830319

Browse files
committed
[minor] Add backup.py
1 parent e444c1d commit 9830319

2 files changed

Lines changed: 440 additions & 0 deletions

File tree

src/mas/devops/backup.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2026 IBM Corporation and other Contributors.
3+
#
4+
# All rights reserved. This program and the accompanying materials
5+
# are made available under the terms of the Eclipse Public License v1.0
6+
# which accompanies this distribution, and is available at
7+
# http://www.eclipse.org/legal/epl-v10.html
8+
#
9+
# *****************************************************************************
10+
import logging
11+
import os
12+
import yaml
13+
14+
logger = logging.getLogger(name=__name__)
15+
16+
17+
def createBackupDirectories(paths: list) -> bool:
18+
"""
19+
Create backup directories if they do not exist
20+
"""
21+
try:
22+
for path in paths:
23+
os.makedirs(path, exist_ok=True)
24+
logger.info(msg=f"Created backup directory: {path}")
25+
return True
26+
except Exception as e:
27+
logger.error(msg=f"Error creating backup directories: {e}")
28+
return False
29+
30+
31+
def copyContentsToYamlFile(file_path: str, content: dict) -> bool:
32+
"""
33+
Write dictionary content to a YAML file
34+
"""
35+
try:
36+
with open(file_path, 'w') as yaml_file:
37+
yaml.dump(content, yaml_file, default_flow_style=False)
38+
return True
39+
except Exception as e:
40+
logger.error(f"Error writing to YAML file {file_path}: {e}")
41+
return False
42+
43+
44+
def filterResourceData(data: dict) -> dict:
45+
"""
46+
Filter metadata from Resource data and create minimal dict
47+
"""
48+
metadata_fields_to_remove = [
49+
'annotations',
50+
'creationTimestamp',
51+
'generation',
52+
'resourceVersion',
53+
'selfLink',
54+
'uid',
55+
'managedFields'
56+
]
57+
filteredCopy = data.copy()
58+
if 'metadata' in filteredCopy:
59+
for field in metadata_fields_to_remove:
60+
if field in filteredCopy['metadata']:
61+
del filteredCopy['metadata'][field]
62+
63+
if 'status' in filteredCopy:
64+
del filteredCopy['status']
65+
66+
return filteredCopy

0 commit comments

Comments
 (0)