aiida.manage.backup package

Submodules

Base abstract Backup class for all backends.

class aiida.manage.backup.backup_base.AbstractBackup(backup_info_filepath, additional_back_time_mins)[source]

Bases: object

This class handles the backup of the AiiDA repository that is referenced by the current AiiDA database. The backup will start from the given backup timestamp (oldest_object_backedup) or the date of the oldest node/workflow object found and it will periodically backup (in periods of periodicity days) until the ending date of the backup specified by end_date_of_backup or days_to_backup.

BACKUP_DIR_KEY = 'backup_dir'
BACKUP_LENGTH_THRESHOLD_KEY = 'backup_length_threshold'
DAYS_TO_BACKUP_KEY = 'days_to_backup'
END_DATE_OF_BACKUP_KEY = 'end_date_of_backup'
OLDEST_OBJECT_BK_KEY = 'oldest_object_backedup'
PERIODICITY_KEY = 'periodicity'
__abstractmethods__ = frozenset({'_get_query_set_iterator', '_get_query_set_length', '_get_query_sets', '_get_source_directory', '_query_first_node'})
__dict__ = mappingproxy({'__module__': 'aiida.manage.backup.backup_base', '__doc__': '\n This class handles the backup of the AiiDA repository that is referenced\n by the current AiiDA database. The backup will start from the\n given backup timestamp (*oldest_object_backedup*) or the date of the\n oldest node/workflow object found and it will periodically backup\n (in periods of *periodicity* days) until the ending date of the backup\n specified by *end_date_of_backup* or *days_to_backup*.\n ', 'OLDEST_OBJECT_BK_KEY': 'oldest_object_backedup', 'BACKUP_DIR_KEY': 'backup_dir', 'DAYS_TO_BACKUP_KEY': 'days_to_backup', 'END_DATE_OF_BACKUP_KEY': 'end_date_of_backup', 'PERIODICITY_KEY': 'periodicity', 'BACKUP_LENGTH_THRESHOLD_KEY': 'backup_length_threshold', '_oldest_object_bk': None, '_backup_dir': None, '_days_to_backup': None, '_end_date_of_backup': None, '_periodicity': None, '_backup_length_threshold': None, '_internal_end_date_of_backup': None, '_additional_back_time_mins': None, '_ignore_backup_dir_existence_check': False, '__init__': <function AbstractBackup.__init__>, '_read_backup_info_from_file': <function AbstractBackup._read_backup_info_from_file>, '_read_backup_info_from_dict': <function AbstractBackup._read_backup_info_from_dict>, '_dictionarize_backup_info': <function AbstractBackup._dictionarize_backup_info>, '_store_backup_info': <function AbstractBackup._store_backup_info>, '_find_files_to_backup': <function AbstractBackup._find_files_to_backup>, '_get_repository_path': <staticmethod object>, '_backup_needed_files': <function AbstractBackup._backup_needed_files>, '_extract_parent_dirs': <staticmethod object>, 'run': <function AbstractBackup.run>, '_query_first_node': <function AbstractBackup._query_first_node>, '_get_query_set_length': <function AbstractBackup._get_query_set_length>, '_get_query_sets': <function AbstractBackup._get_query_sets>, '_get_query_set_iterator': <function AbstractBackup._get_query_set_iterator>, '_get_source_directory': <function AbstractBackup._get_source_directory>, '__dict__': <attribute '__dict__' of 'AbstractBackup' objects>, '__weakref__': <attribute '__weakref__' of 'AbstractBackup' objects>, '__abstractmethods__': frozenset({'_get_query_set_iterator', '_get_query_set_length', '_get_query_sets', '_query_first_node', '_get_source_directory'}), '_abc_impl': <_abc_data object>})
__init__(backup_info_filepath, additional_back_time_mins)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.backup.backup_base'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
_additional_back_time_mins = None
_backup_dir = None
_backup_length_threshold = None
_backup_needed_files(query_sets)[source]

Perform backup of a minimum-set of files

_days_to_backup = None
_dictionarize_backup_info()[source]

This dictionarises the backup information and returns the dictionary.

_end_date_of_backup = None
static _extract_parent_dirs(given_rel_dir, parent_dir_set)[source]

This method extracts the parent directories of the givenDir and populates the parent_dir_set.

_find_files_to_backup()[source]

Query the database for nodes that were created after the the start of the last backup. Return a query set.

abstract _get_query_set_iterator(query_set)[source]

Get query set iterator

abstract _get_query_set_length(query_set)[source]

Get query set length

abstract _get_query_sets(start_of_backup, backup_end_for_this_round)[source]

Get query set

static _get_repository_path()[source]
abstract _get_source_directory(item)[source]

Get source directory of item :param self: :return:

_ignore_backup_dir_existence_check = False
_internal_end_date_of_backup = None
_oldest_object_bk = None
_periodicity = None
abstract _query_first_node()[source]

Query first node

_read_backup_info_from_dict(backup_variables)[source]

This method reads the backup information from the given dictionary and sets the needed class variables.

_read_backup_info_from_file(backup_info_file_name)[source]

This method reads the backup information from the given file and passes the dictionary to the method responsible for the initialization of the needed class variables.

_store_backup_info(backup_info_file_name)[source]

This method writes the backup variables dictionary to a file with the given filename.

run()[source]

Run the backup

exception aiida.manage.backup.backup_base.BackupError(value, *args, **kwargs)[source]

Bases: Exception

General backup error

__init__(value, *args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.backup.backup_base'
__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

Backup implementation for any backend (using the QueryBuilder).

class aiida.manage.backup.backup_general.Backup(backup_info_filepath, additional_back_time_mins)[source]

Bases: aiida.manage.backup.backup_base.AbstractBackup

Backup for any backend

__abstractmethods__ = frozenset({})
__module__ = 'aiida.manage.backup.backup_general'
_abc_impl = <_abc_data object>
_get_query_set_iterator(query_set)[source]

Get query set iterator

Parameters

query_set (QueryBuilder) – QueryBuilder object

Returns

Generator, returning the results of the QueryBuilder query.

Return type

list

Raises

BackupError – if the number of yielded items in the list from iterall() is more than 1.

_get_query_set_length(query_set)[source]

Get query set length

_get_query_sets(start_of_backup, backup_end_for_this_round)[source]

Get Nodes and Worflows query set from start to end of backup.

Parameters
  • start_of_backup – datetime object with start datetime of Node modification times for backup.

  • backup_end_for_this_round – datetime object with end datetime of Node modification times for backup this round.

Returns

List of QueryBuilder queries/query.

Return type

QueryBuilder

_get_source_directory(item)[source]

Retrieve the node repository folder

Parameters

item (Node) – Subclasses of Node.

Returns

Normalized path to the Node’s repository folder.

Return type

str

_query_first_node()[source]

Query first node :return: The first Node object (return specific subclass thereof). :rtype: Node

Class to backup an AiiDA instance profile.

class aiida.manage.backup.backup_setup.BackupSetup[source]

Bases: object

This class setups the main backup script related information & files like:

- the backup parameter file. It also allows the user to set it up by answering questions.
- the backup folders.
- the script that initiates the backup.
__dict__ = mappingproxy({'__module__': 'aiida.manage.backup.backup_setup', '__doc__': '\n This class setups the main backup script related information & files like::\n\n - the backup parameter file. It also allows the user to set it up by answering questions.\n - the backup folders.\n - the script that initiates the backup.\n ', '__init__': <function BackupSetup.__init__>, 'construct_backup_variables': <staticmethod object>, 'create_dir': <function BackupSetup.create_dir>, 'print_info': <staticmethod object>, 'run': <function BackupSetup.run>, '__dict__': <attribute '__dict__' of 'BackupSetup' objects>, '__weakref__': <attribute '__weakref__' of 'BackupSetup' objects>})
__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.backup.backup_setup'
__weakref__

list of weak references to the object (if defined)

static construct_backup_variables(file_backup_folder_abs)[source]

Construct backup variables.

create_dir(question, dir_path)[source]

Create the directories for the backup folder and return its path.

static print_info()[source]

Write a string with information to stdout.

run()[source]

Run the backup.

Utilities for the backup functionality.

aiida.manage.backup.backup_utils.ask_question(question, reply_type, allow_none_as_answer=True)[source]

This method asks a specific question, tries to parse the given reply and then it verifies the parsed answer. :param question: The question to be asked. :param reply_type: The type of the expected answer (int, datetime etc). It is needed for the parsing of the answer. :param allow_none_as_answer: Allow empty answers? :return: The parsed reply.

aiida.manage.backup.backup_utils.query_string(question, default)[source]

Asks a question (with the option to have a default, predefined answer, and depending on the default answer and the answer of the user the following options are available: - If the user replies (with a non empty answer), then his answer is returned. - If the default answer is None then the user has to reply with a non-empty answer. - If the default answer is not None, then it is returned if the user gives an empty answer. In the case of empty default answer and empty reply from the user, None is returned. :param question: The question that we want to ask the user. :param default: The default answer (if there is any) to the question asked. :return: The returned reply.

aiida.manage.backup.backup_utils.query_yes_no(question, default='yes')[source]

Ask a yes/no question via input() and return their answer.

“question” is a string that is presented to the user. “default” is the presumed answer if the user just hits <Enter>. It must be “yes” (the default), “no” or None (meaning an answer is required of the user).

The “answer” return value is True for “yes” or False for “no”.