Skip to content

Commit 6941e5d

Browse files
restore from backup script added
1 parent 6b84919 commit 6941e5d

File tree

5 files changed

+76
-23
lines changed

5 files changed

+76
-23
lines changed

pcor_tools/CedarBackupDockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from python:3.9
2+
3+
ADD . pcor_tools
4+
5+
WORKDIR pcor_tools
6+
7+
RUN pip install -r requirements.txt
8+
9+
ENV CEDAR_PROPERTIES=/etc/irods-ext/cedar.properties
10+
11+
CMD python cedar_backup_tool.py -t f6d5c357-beab-421c-93d3-0498a582acfd -i e355737f-3f47-4001-9ae4-67c1ca5bca75 -o /backup michaelconway/cedarbackup:latest
12+
13+
14+
# docker run -i --rm -v /commons/infrastructure/prod/irods-ext/cedar.properties:/etc/irods-ext/cedar.properties -v /commons/infrastructure/prod/backup/cedar:/backup --name cedar_backup michaelconway/cedarbackup:latest > /var/log/ods/cedar_backup.log 2>&1
15+
16+
17+
18+
# docker run -i --rm -v /Users/conwaymc/temp/cedar.properties:/etc/irods-ext/cedar.properties -v /Users/conwaymc/temp/cedarbk:/backup michaelconway/cedarbackup:latest
19+
20+
21+
# docker build -t michaelconway/cedarbackup:latest -f CedarBackupDockerfile .
22+
23+
24+
# /Users/conwaymc/temp/cedar.properties
25+
26+
27+
# 0 4 * * * /commons/infrastructure/prod/cedar_backup.sh
28+
29+
30+

pcor_tools/cedar_backup_tool.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ a = Analysis(
66
pathex=[],
77
binaries=[],
88
datas=[],
9-
hiddenimports=[],
9+
hiddenimports=["requests"],
1010
hookspath=[],
1111
hooksconfig={},
1212
runtime_hooks=[],

pcor_tools/cedar_loading_tool.py

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
import logging
1+
"""
2+
Tool to migrate a given cedar template from one version to another.
3+
4+
Requites an env variable "CEDAR_PROPERTIES" to be set. see ./tests/test_resources/cedar_config_file.properties
5+
The env variable would be the absolute path to the location of that properties file
6+
7+
run parameters
8+
9+
-r - the url copied from CEDAR for the instance
10+
-s - source version, e.g. 1_5_0
11+
-t - target version, e.g. 1_5_1
12+
13+
restored = https://repo.metadatacenter.org/folders/f71236e0-fa24-42eb-bb98-a9bd8f6b2586
14+
15+
"""
16+
import json
217
import logging
318
import os
419
import sys
520
from optparse import OptionParser
621

7-
from pcor_cedar.loader_cedar import LoaderCedar
8-
from pcor_ingest.ingest_context import PcorIngestConfiguration
22+
from pcor_cedar.cedar_access import CedarAccess
23+
from pcor_cedar.migration import CedarMigrate
924

1025
logging.basicConfig(
1126
level=logging.DEBUG,
@@ -14,38 +29,46 @@
1429
)
1530
logger = logging.getLogger(__name__)
1631

17-
1832
def setup_arguments():
1933
parser = OptionParser()
20-
parser.add_option('-r', "--resource_url", action='store', dest='resource_url', default=None)
21-
parser.add_option('-d', "--directory", action='store', dest='directory', default=None)
22-
parser.add_option('-v', "--cedar_version", action='store', dest='cedar_version', default="1_5_1")
34+
parser.add_option('-f', "--resource_file", action='store', dest='resource_file', default=None)
35+
parser.add_option('-t', "--target_folder_id", action='store', dest='target_folder_id', default=None)
2336

2437
return parser.parse_args()[0]
2538

26-
2739
def main():
28-
logger.info('Main function execution started.')
40+
logger.info('Main function execution started. Load a backup json into CEDAR')
2941
global args
3042
args = setup_arguments()
3143

3244
if "CEDAR_PROPERTIES" not in os.environ:
3345
logger.error("CEDAR_PROPERTIES not found in env. System exiting...")
3446
sys.exit()
3547

36-
if "PCOR_GEN3_CONFIG_LOCATION" not in os.environ:
37-
logger.error("PCOR_GEN3_CONFIG_LOCATION not found in env. System exiting...")
38-
sys.exit()
48+
cedar_config_file = os.environ.get("CEDAR_PROPERTIES")
49+
cedar_access = CedarAccess(cedar_config_file)
50+
51+
resource_file = args.resource_file
52+
target_folder_id = args.target_folder_id
53+
54+
if not resource_file:
55+
logger.error("no resource_file, specify this parameter with -f")
56+
raise Exception("no -s parameter specified")
57+
58+
if not target_folder_id:
59+
logger.error("no target_folder_id, specify this parameter with -t")
60+
raise Exception("no -t parameter specified")
61+
62+
cedar_config_file = os.environ.get("CEDAR_PROPERTIES")
63+
logger.info('resource to load :: %s' % resource_file)
64+
logger.info('target_folder_id :: %s' % target_folder_id)
65+
66+
with open(resource_file, 'r') as f:
67+
contents_json = json.loads(f.read())
3968

40-
resource_url = args.resource_url
41-
directory = args.directory
42-
cedar_version = args.cedar_version
69+
id = cedar_access.create_resource(json.dumps(contents_json), target_folder_id)
70+
logger.info("complete..id: {id}".format(id=id))
4371

44-
pcor_ingest_configuration = PcorIngestConfiguration(os.environ.get("PCOR_GEN3_CONFIG_LOCATION"))
45-
cedar_loader = LoaderCedar(pcor_ingest_configuration, cedar_version)
46-
logger.info("loading...")
47-
cedar_loader.main_load_process(resource_url, directory)
48-
logger.info("loading complete")
4972

5073
if __name__ == "__main__":
51-
main()
74+
main()

pcor_tools/cedar_restore_tool.py

Whitespace-only changes.

pcor_tools/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mypy-extensions==1.0.0
5757
nbclient==0.10.0
5858
nbconvert==7.16.4
5959
nbformat==5.10.4
60-
numpy==2.1.2
60+
numpy
6161
openpyxl==3.1.5
6262
packaging==24.1
6363
pandas==2.2.3

0 commit comments

Comments
 (0)