API

runner

Runner.

dothebackup.runner.builder(config, name)[source]

Builds a dict of commands.

Parameters:
  • config (Dict[str, Dict[str, Dict[~KT, ~VT]]]) – YAML config
  • name (Optional[str]) – Name of a specific job to run
Return type:

Dict[str, List[List[str]]]

Returns:

A dict with all commands needed commands

dothebackup.runner.check_config_keys(config, key_list)[source]

Aborts if keys are not set in config.

Parameters:
  • config (dict) – Config
  • key_list (list) – List of used keys
Return type:

None

dothebackup.runner.check_if_already_running()[source]

Aborts if other DoTheBackup process is running.

Return type:None
dothebackup.runner.check_plugin(name)[source]

Aborts and throw an error if plugin is not there as defined as type in config.

Parameters:name (str) – Name of plugin that is defined in the config
Return type:None
dothebackup.runner.get_started(configfile, name, test)[source]

The entrypoint for the UI.

This is used to get everything started up. It will read the config, check the keys, build the command dictionary and run them.

Parameters:
  • configfile (IO[AnyStr]) – The config file
  • name (str) – A name of a specific job
  • test (bool) – Switch for only printing the commands
Return type:

None

dothebackup.runner.parse_config(configfile)[source]

Read config file.

Parameters:configfile (_io.TextIOWrapper) – YAML config file
Returns:loaded configfile
Return type:dict
dothebackup.runner.print_commands(commands)[source]

Prints the commands that would be used.

Parameters:commands (Dict[str, List[List[str]]]) – Command dictionary
Return type:None
dothebackup.runner.run_commands(commands, test, log_dir, log_keep)[source]

Running the commands.

The actual runner. It will take the commands dictionary and run it one after another. There is also a test key. With this enabled it will only print the commands it would run.

Parameters:
  • commands (Dict[str, List[List[str]]]) – Commands dictionary
  • test (bool) – If test the commands only will be printed
  • log_dir (str) – Dictionary for logfiles
  • log_keep (int) – How many logs to keep from one job
Return type:

None

logger

Logger.

class dothebackup.logger.Logger(log_dir, name, keep)[source]

A logger for handling stdout logging.

Parameters:
  • log_dir (str) – Directory to store logfiles in
  • name (str) – Name of the backup job
  • keep (int) – Number of logs to keep
create_log_dir()[source]

Create logdir if its not there.

Return type:None
logfile()[source]

A logfile handler.

This is used in a context to write to a logfile:

with logger.logfile() as logfile:
    logfile.write('foobar')
Yields:Opened logfile
Return type:Iterator[IO[str]]
rotate()[source]

A logfile rotator.

This function moves old logfiles around.

Example:

foo.log

gets:

foo.log.0001

and so on.

Return type:None

plugins

Plugins.

dothebackup.plugins.load_plugins()[source]

Load plugins from plugin directory.

This function reads the plugs directory and loads all plugins.

Return type:Dict[str, Callable]
dothebackup.plugins.required_executables(dep_list)[source]

Decorator to check required executables.

Parameters:dep_list (List[str]) – Dependency list
Return type:Callable
Returns:Decorated function
dothebackup.plugins.required_keys(key_list)[source]

Decorator to check against key list.

Parameters:key_list (List[str]) – List of keys that needs to be in the config
Return type:Callable
Returns:Decorated function

utils

Utils.

dothebackup.utils.absolutenormpath(path)[source]

Returns a absolute normalized path.

Parameters:path (str) – Path
Return type:str
Returns:Absolute path
dothebackup.utils.git_cloned_yet(path)[source]

Returns if path contains a git repository.

Parameters:path (str) – A path
Return type:bool
Returns:If path contains a git repositoy
dothebackup.utils.git_something_to_commit(path)[source]

Returns if path has something to commit.

Parameters:path (str) – A path
Return type:bool
Returns:If path has something to commit
dothebackup.utils.pidfile()[source]

Contextmanager to create a Pidfile for the DoTheBackup process and removes it afterwards.

Return type:Iterator[None]
dothebackup.utils.return_code(exitcodes)[source]

Get overalls exitcode out of a list of exitcodes.

Parameters:exitcodes (List[int]) – List of exitcodes
Return type:int
Returns:Return exit code 1 if something different than 0 is in the list
dothebackup.utils.today()[source]

Returns todays day string.

Return type:str
Returns:Today day string