def get_backup_directory(self, session_key, lookup_file, namespace, owner=None, resolved_lookup_path=None): """ Get the backup directory where the lookup should be stored """ if owner is None: owner = 'nobody' # Identify the current path of the given lookup file if resolved_lookup_path is None: resolved_lookup_path = SplunkLookupTableFile.get( SplunkLookupTableFile.build_id(lookup_file, namespace, owner), sessionKey=session_key).path # Determine what the backup directory should be backup_directory = make_splunkhome_path([ os.path.dirname(resolved_lookup_path), "lookup_file_backups", namespace, owner, escape_filename(lookup_file) ]) # Make the backup directory, if necessary if not os.path.exists(backup_directory): os.makedirs(backup_directory) return backup_directory
def get_backup_files(self, session_key, lookup_file, namespace, owner): """ Get a list of backup files for a given file """ # Escape the file name so that we find the correct file escaped_filename = escape_filename(lookup_file) # Get the backup directory and determine the path to the backups backup_directory = self.get_backup_directory(session_key, escaped_filename, namespace, owner) # Get the backups backups = [f for f in os.listdir(backup_directory) if os.path.isfile(os.path.join(backup_directory, f))] return backups
def get_backup_files(self, session_key, lookup_file, namespace, owner): """ Get a list of backup files for a given file """ # Escape the file name so that we find the correct file escaped_filename = escape_filename(lookup_file) # Get the backup directory and determine the path to the backups backup_directory = self.get_backup_directory(session_key, escaped_filename, namespace, owner) # Get the backups backups = [ f for f in os.listdir(backup_directory) if os.path.isfile(os.path.join(backup_directory, f)) ] return backups
def get_backup_directory(self, session_key, lookup_file, namespace, owner=None, resolved_lookup_path=None): """ Get the backup directory where the lookup should be stored """ if owner is None: owner = 'nobody' # Identify the current path of the given lookup file if resolved_lookup_path is None: resolved_lookup_path = SplunkLookupTableFile.get(SplunkLookupTableFile.build_id(lookup_file, namespace, owner), sessionKey=session_key).path # Determine what the backup directory should be backup_directory = make_splunkhome_path([os.path.dirname(resolved_lookup_path), "lookup_file_backups", namespace, owner, escape_filename(lookup_file)]) # Make the backup directory, if necessary if not os.path.exists(backup_directory): os.makedirs(backup_directory) return backup_directory