-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup.py
executable file
·128 lines (106 loc) · 4.16 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os
import logging
import threading
from common import common
from library.backup import KBackup
def main():
common.setLoggingFormat()
try:
config = common.readJsonConfig(os.sys.argv[1])
except IndexError:
logging.error("backup.json is not passed")
exit(1)
b = KBackup(config)
common.setLoggingFormat(b.LOG_LEVEL)
for _r_thread in range(b.NUMBER_OF_KAFKA_THREADS):
_r_thread = threading.Thread(
target=b.backup,
name="Kafka Consumer " + str(_r_thread)
)
_r_thread.start()
if config['FILESYSTEM_TYPE'] == "S3":
# import only if FS TYPE is Selected
from cloud import aws
try:
bucket = config['BUCKET_NAME']
tmp_dir = config['FILESYSTEM_BACKUP_DIR']
topic_name = config['TOPIC_NAMES'][0]
try:
retry_upload_seconds = config['RETRY_UPLOAD_SECONDS']
logging.debug(f"RETRY_UPLOAD_SECONDS is set to {config['RETRY_UPLOAD_SECONDS']}")
except KeyError:
logging.debug("setting RETRY_UPLOAD_SECONDS to default 60")
retry_upload_seconds = 60
aws.Upload.s3_upload(
bucket,
tmp_dir,
topic_name,
retry_upload_seconds,
b.NUMBER_OF_KAFKA_THREADS + 1
)
except KeyError as e:
logging.error(f"unable to set s3 required variables {e}")
elif config['FILESYSTEM_TYPE'] == "AZURE":
connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
if connect_str is None:
logging.error("Env Azure Storage Connection string is missing")
exit(1)
# import only if FS TYPE is Selected
from cloud import azure
# update azure logger
logging.getLogger("azure").setLevel(b.LOG_LEVEL)
try:
container_name = config['CONTAINER_NAME']
tmp_dir = config['FILESYSTEM_BACKUP_DIR']
topic_name = config['TOPIC_NAMES'][0]
try:
retry_upload_seconds = config['RETRY_UPLOAD_SECONDS']
logging.debug(f"RETRY_UPLOAD_SECONDS is set to {config['RETRY_UPLOAD_SECONDS']}")
except KeyError:
logging.debug("setting RETRY_UPLOAD_SECONDS to default 60")
retry_upload_seconds = 60
azure.Upload.upload(
connect_str,
container_name,
tmp_dir,
topic_name,
retry_upload_seconds,
b.NUMBER_OF_KAFKA_THREADS + 1
)
except KeyError as e:
logging.error(f"unable to set azure required variables {e}")
elif config['FILESYSTEM_TYPE'] == "MINIO":
minio_access_key = os.getenv('MINIO_ACCESS_KEY')
minio_secret_key = os.getenv('MINIO_SECRET_KEY')
if (minio_access_key or minio_secret_key) is None:
logging.error("Minio Access and Secret Key envs are missing")
exit(1)
# import only if FS TYPE is Selected
from cloud import minio
try:
minio_url = config['MINIO_URL']
is_mino_secure = True if config['IS_MINIO_SECURE'] == "TRUE" else False
bucket = config['BUCKET_NAME']
tmp_dir = config['FILESYSTEM_BACKUP_DIR']
topic_name = config['TOPIC_NAMES'][0]
try:
retry_upload_seconds = config['RETRY_UPLOAD_SECONDS']
logging.debug(f"RETRY_UPLOAD_SECONDS is set to {config['RETRY_UPLOAD_SECONDS']}")
except KeyError:
logging.debug("setting RETRY_UPLOAD_SECONDS to default 60")
retry_upload_seconds = 60
minio.Upload.minio_upload(
minio_url,
is_mino_secure,
minio_access_key,
minio_secret_key,
bucket,
tmp_dir,
topic_name,
retry_upload_seconds,
b.NUMBER_OF_KAFKA_THREADS + 1
)
except KeyError as e:
logging.error(f"unable to set minio required variables {e}")
if __name__ == "__main__":
main()