From 10f2e06c20a294b6cb7491875441ea9a2e9b0bf8 Mon Sep 17 00:00:00 2001 From: Justin Henderson Date: Fri, 10 Dec 2021 12:27:42 -0600 Subject: [PATCH] a --- __pycache__/es.cpython-39.pyc | Bin 19084 -> 19000 bytes backup.py | 68 +++++++++++++++------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/__pycache__/es.cpython-39.pyc b/__pycache__/es.cpython-39.pyc index 8474d406d8b0406d11a2d38056e1f75e607d4fe1..252bc19c0f1e76dd2d7e0f0f0b9e1da5685f640e 100644 GIT binary patch delta 550 zcmZ8dF=!M)6rDG_-i>Q^&)b}L5=nv>!Y!u|FpyJ0JU5p$&4F4-Vi68!BM}pI_EIQT zCWVCx@hd0@Vs(&8*+viq1w}*zjg2YotOSW-XJ)pMIG_JMGw;9mKXdCop5KGpc3p?* z!|$f;aK-J%+h?^yycAn;AoodM4&AooNqK6SErBlZ>Q-V(PG`geegv=6FZ|3XF4O+8 z^WF_iu?0TDBs5rq|fEIl|)~H>#mas)_ zwZ0E%L4fswimxojNoS@rHy>YG?9k)JUTyiR5$^UgOAY}~XHJLEp?Ercd=%hxHf-T3 zt%ifh)BEs6&Xs=VRKcc zwFy}%>Fyw}{x_snR6&tuqXU(%|Ms@c-tdjOk5;29HfSw+gForR6J-o?ZKd)CgaOw; nuYt0GKKeL0f;;qgG8xc26huMzx}MXyLwLdww%8_w*zRBxEEIg0 delta 729 zcmZuvO=uHA6rMNPZYQz3t()2u`{UL>8j6^M(D(zgG)M5P~_>=lPGx86coXW;7Jc&yi~mO=1C7$(UWh|VlVE%H}m-3``&!B@6`ji_Yf@K zvJ#BGiPabW`}@`aJbONJnwxS;POmY%&WBAoBWLNj!Oy~z=68PS6fEP!=zKS@874)E zu*x$`vJy+j@y%!mdCX)-;4xmw=K6cJHgFKo1rC_d0X7&EnOs2gb+%x_pC&)Q1!k4< zR*vFOZwkRXc3Z|)0a#=Nv%t4w{`pE*Flm%n;hKWjDdT%lqcsAK7VX37!Z2*( z&B8nQ-Sj4U;82XjmCz8^U~8a3V{`$6K3pzl;4VHbh6hEL=oAiJuuLagB!nT_gb?ur F`~~SinPdO} diff --git a/backup.py b/backup.py index 295f5ae..0016699 100644 --- a/backup.py +++ b/backup.py @@ -18,12 +18,13 @@ special_indices_to_backup = [".kibana",".opendistro",".opensearch"] @retry(Exception, tries=6, delay=10) -def validate_backup_repo_exists(client_config): +def validate_backup_repo_exists(client_config, repository): """[summary] Validates backup repository exists in ES/OS Args: client_config ([dict]): [Client configuration] + repository ([str]): [Repository to verify exists] Raises: Exception: [On error, print error and retry] @@ -31,25 +32,20 @@ def validate_backup_repo_exists(client_config): Returns: [bool]: [Does backup repository exist] """ - if 'backup' in settings: - if 'backup_repo' in settings['backup']: - repo = settings['backup']['backup_repo'] - else: - print("No backup repository defined in settings.toml") - return False - try: - elastic_connection = es.build_es_connection(client_config) - repositories = elastic_connection.cat.repositories(format='json') - elastic_connection.close() - for repository in repositories: - if repo == repository['id']: - return True - except Exception as e: - elastic_connection.close() - print("Operation failed - Validate backup repo exists") - raise Exception(e) + try: + elastic_connection = es.build_es_connection(client_config) + repositories = elastic_connection.cat.repositories(format='json') + elastic_connection.close() + for record in repositories: + if repository == record['id']: + print(f"Backup repository {repository} exists and is registered") + return True + except Exception as e: + elastic_connection.close() + print("Operation failed - Validate backup repo exists") + raise Exception(e) # If it makes it this far the repo does not exist, fail - print(f"Backup repository {repo} not registered") + print(f"Backup repository {repository} not registered") return False def get_backup_policy(client_config, repository): @@ -76,23 +72,19 @@ def get_repositories(client_config): repositories.append(repository) return repositories -def validate_backup_enabled(): +def validate_backup_enabled(client_config): """[summary] - Validates backup configuration found in settings.toml + Validates backup configuration found in client_info.json Returns: [bool]: [Does backup section exist] """ - if 'backup' in settings: - if settings['backup']['enabled']: - if 'health_check_level' in settings['backup']: - return True - else: - return False + if 'policy' in client_config: + if 'backup' in client_config['policy']: + return True else: return False - else: - return False + return False @retry(Exception, tries=6, delay=10) def get_snapshots_in_repository(client_config, repository): @@ -121,7 +113,7 @@ def get_snapshots_in_repository(client_config, repository): elastic_connection.close() return snapshots -@retry(Exception, tries=360, delay=10) +@retry(Exception, tries=60, delay=10) def delete_snapshot_in_repository(client_config, repository, snapshot): """[summary] Deletes a snapshot from a backup repository @@ -201,7 +193,7 @@ def apply_backup_retention_policies(client_config, job, retention, repository): print(message) send_notification(client_config, "backup", "Failed", message, teams=settings['backup']['ms-teams'], jira=settings['backup']['jira']) -@retry(Exception, tries=360, delay=10) +@retry(Exception, tries=60, delay=10) def take_snapshot(client_config, repository, snapshot, body): """[summary] Creates a backup snapshot @@ -246,7 +238,7 @@ def take_snapshot(client_config, repository, snapshot, body): print("Operation failed - Create snapshot " + snapshot + " for repo " + repository) raise Exception(e) -@retry(Exception, tries=12, delay=1) +@retry(Exception, tries=12, delay=10) def get_indices_within_limit_age(client_config, indices, limit_age): """[summary] Takes a list of indices and looks to see if the most recent document @@ -369,12 +361,12 @@ def run_backup(manual_client): if settings['settings']['limit_to_client'] == client or settings['settings']['limit_to_client'] == "": client_config = clients[client] - if validate_backup_enabled(): - if validate_backup_repo_exists(client_config): - # Get repositories listed in backup policy section - repositories = get_repositories(client_config) - # Loop through each repository to process backups - for repository in repositories: + if validate_backup_enabled(client_config): + # Get repositories listed in backup policy section + repositories = get_repositories(client_config) + # Loop through each repository to process backups + for repository in repositories: + if validate_backup_repo_exists(client_config, repository): # Get Backup policy for each repository backup_policy = get_backup_policy(client_config, repository) # Loop through each backup job found in policy