-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.py
46 lines (32 loc) · 1.08 KB
/
backup.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
import xml.etree.ElementTree as ET
import importlib
import sys
import os
if len(sys.argv) > 1:
xmlfile = sys.argv[1]
else:
xmlfile = os.path.normpath( os.getcwd() + "/backup.xml")
print(xmlfile)
tree = ET.parse(xmlfile)
root = tree.getroot()
modIncluded = []
configuration = root.find('configuration')
if configuration.findall('lib'):
for inc in configuration.findall('lib'):
modIncluded.append ( importlib.import_module(inc.text ) )
def FindFunction(name):
for mod in modIncluded:
if name in dir(mod):
return mod.__dict__[name]
backups = root.find('backups')
sources = root.find('sources')
destination = root.find('destinations')
for bck in backups:
source = bck.get('source')
dest = bck.get('destination')
nodeSource = sources.find("source[@name='" + source + "']")
nodeDestination = destination.find("destination[@name='" + dest + "']")
fun = FindFunction("Source_" + nodeSource.get('type').capitalize())
file = fun(nodeSource,configuration)
fun=FindFunction("Destination_" + nodeDestination.get('type').capitalize())
fun(file, nodeDestination,configuration)