def restore_backup(system_id='local', backup_type='configuration', backup_name='', backup_pass=''): """ Restore backup in the system """ success, system_ip = get_system_ip_from_system_id(system_id) if not success: api_log.error(str(system_ip)) error_msg = "Error retrieving the system ip for the system id %s -> %s" % (system_id, str(system_ip)) return False, error_msg backup_name = os.path.basename(backup_name) success, backup_path = secure_path_join(BACKUP_PATH, backup_name) if not success: api_log.error("restore backup: %s '%s'" % (backup_path, backup_name)) return False, "" try: success, msg = run_restore(target=system_ip, backup_type=backup_type, backup_file=backup_path, backup_pass=backup_pass) if not success: api_log.error("restore_backup: %s" % msg) error_msg = "Error trying to restore the backup '%s': %s" % (backup_name, msg) return False, error_msg except Exception as e: api_log.info("restore_backup Error: %s" % str(e)) error_msg = "Error trying to restore the backup '%s': %s" % (backup_name, str(e)) return False, error_msg return success, msg
def delete_backups(system_id='local', backup_type='configuration', backup_list=[]): """ Delete backups from the system """ success, system_ip = get_system_ip_from_system_id(system_id) if not success: api_log.error(str(system_ip)) error_msg = "Error retrieving the system ip for the system id " error_msg = error_msg + "%s -> %s" % (system_id, str(system_ip)) return False, error_msg success, files = get_files_in_path(system_ip=system_ip, path=BACKUP_PATH) if not success: return False, files # Report warnings for non-existing backup files existing_backup_list = [] for backup_name in backup_list: backup_name = os.path.basename(backup_name) success, backup_path = secure_path_join(BACKUP_PATH, backup_name) if not success: api_log.error("delete_backups: %s '%s'" % (backup_path, backup_name)) elif backup_path not in files.keys(): api_log.error("delete_backups: %s does not exist" % backup_path) else: existing_backup_list.append(backup_path) # Removing existing backups for backup_path in existing_backup_list: try: success, msg = remove_file(host_list=[system_ip], file_name=backup_path) if not success: api_log.error(str(msg)) error_msg = "Error removing %s " % backup_path error_msg = error_msg + "from system %s" % system_ip return False, error_msg except Exception as e: api_log.error("delete_backups Error: %s" % str(e)) error_msg = "Error trying to delete the backup '%s'" % backup_name error_msg = ": %s" % str(e) return False, error_msg try: get_backup_list(system_id=system_id, backup_type=backup_type, no_cache=True) except Exception as e: error_msg = "Error when trying to flush the cache " \ "after deleting backups: %s" % str(e) api_log.error(error_msg) return success, ''
def delete_backups(system_id='local', backup_type='configuration', backup_list=None): """ Delete backups from the system """ if backup_list is None: backup_list = [] success, system_ip = get_system_ip_from_system_id(system_id) if not success: api_log.error(str(system_ip)) error_msg = "Error retrieving the system ip for the system id %s -> %s" % (system_id, str(system_ip)) return False, error_msg success, files = get_files_in_path(system_ip=system_ip, path=BACKUP_PATH) if not success: return False, files # Report warnings for non-existing backup files existing_backup_list = [] backup_name = '' for backup_name in backup_list: backup_name = os.path.basename(backup_name) success, backup_path = secure_path_join(BACKUP_PATH, backup_name) if not success: api_log.error("delete_backups: %s '%s'" % (backup_path, backup_name)) elif backup_path not in files.keys(): api_log.error("delete_backups: %s does not exist" % backup_path) else: existing_backup_list.append(backup_path) # Removing existing backups for backup_path in existing_backup_list: try: success, msg = remove_file(host_list=[system_ip], file_name=backup_path) if not success: api_log.error(str(msg)) error_msg = "Error removing %s from system %s " % (backup_path, system_ip) return False, error_msg except Exception as e: api_log.error("delete_backups Error: %s" % str(e)) error_msg = "Error trying to delete the backup '%s': %s" % (backup_name, str(e)) return False, error_msg try: get_backup_list(system_id=system_id, backup_type=backup_type, no_cache=True) except Exception as e: error_msg = "Error when trying to flush the cache after deleting backups: %s" % str(e) api_log.error(error_msg) return success, ''
def get_backup_file(backup_name, system_id='local', backup_type='configuration'): """ Get a backup file from a remote system. """ success, system_ip = get_system_ip_from_system_id(system_id) if not success: return False backup_path = "/var/alienvault/backup/" backup_download_path = "/var/alienvault/backup/downloaded/" success, src_file_path = secure_path_join(backup_path, backup_name) if not success: notifier.warning("Invalid backup name %s" % backup_name) return False success, dst_file_path = secure_path_join(backup_download_path, backup_name) if not success: notifier.warning("Invalid backup name %s" % backup_name) return False return fetch_file(system_ip, src_file_path, dst_file_path, flat=True)
def restore_backup(system_id='local', backup_type='configuration', backup_name=''): """ Restore backup in the system """ success, system_ip = get_system_ip_from_system_id(system_id) if not success: api_log.error(str(system_ip)) error_msg = "Error retrieving the system ip for the system id " error_msg = error_msg + "%s -> %s" % (system_id, str(system_ip)) return False, error_msg backup_name = os.path.basename(backup_name) success, backup_path = secure_path_join(BACKUP_PATH, backup_name) if not success: api_log.error("restore backup: %s '%s'" % (backup_path, backup_name)) return False, "" try: success, msg = run_restore(target=system_ip, backup_type=backup_type, backup_file=backup_path) if not success: api_log.error("restore_backup: %s" % msg) error_msg = "Error trying to restore the backup " error_msg = error_msg + "'%s': %s" % (backup_name, msg) return False, error_msg except Exception as e: api_log.info("restore_backup Error: %s" % str(e)) error_msg = "Error trying to restore the backup " error_msg = error_msg + "'%s': %s" % (backup_name, str(e)) return False, error_msg return success, msg