API

grebakker - greyrat's backupper for hackers.

Log

Handles logging of performed actions in CSV or JSON format.

__init__(name, restart, log_format, off)

Initialize the Log object.

Parameters:
  • name (str) –

    Path to the log file

  • restart (bool) –

    If True, overwrites the existing log file

  • log_format (str) –

    Format of the log ('csv' or 'json')

  • off (bool) –

    If True, disables logging

write(act, src, dst, duration)

Write a log entry about a performed action.

Parameters:
  • act (str) –

    Action performed

  • src (str) –

    Source path

  • dst (str) –

    Destination path

  • duration (str) –

    Duration of the action

error(error)

Write a log entry about an error.

Parameters:
  • error (str) –

    The error occured

close()

Close the log file.

Grebakker

Perform backup operations.

__init__(dest, log, verbosity)

Initialize the Grebakker object.

Parameters:
  • dest (str) –

    Destination directory for backups

  • log (Log) –

    Log object for recording actions

  • verbosity (int) –

    Verbosity level for output

_action_begin(mml_action, path, level)

Report the beginning of an action, return starting time.

Parameters:
  • mml_action (str) –

    Description of the action

  • path (str) –

    Path involved in the action

  • level (int) –

    Indentation level

Returns:
  • datetime

    Start time of the action.

_action_end(action, path, dst, level, t1)

Report the end of an action and logs it.

Parameters:
  • action (str) –

    Action performed

  • path (str) –

    Source path

  • dst (str) –

    Destination path

  • level (int) –

    Indentation level

  • t1 (datetime) –

    Start time of the action

_yield_files(src, exclude)

Yield files from the source directory, excluding specified patterns.

Parameters:
  • src (str) –

    Source directory.

  • exclude (List[str]) –

    List of patterns to exclude.

Yields:
  • source_path( str ) –

    Relative path to each file

_i(level)

Return indentation spaces for the given output level.

Parameters:
  • level (int) –

    Indentation level.

Returns:
  • str

    Indentation spaces

_destination_exists(action, src, dst, level)

Determine the destination path for an action.

Parameters:
  • action (str) –

    Action being performed

  • src (str) –

    Source path

  • dst (str) –

    Destination path

  • level (int) –

    Indentation level

Returns:
  • str or None

    Destination path or None if the destination file exists.

copy(src_root, item, dst_root, level)

Copy files or directories from source to destination.

Parameters:
  • src_root (str) –

    Root source directory

  • item (Union[str, Dict[str, str]]) –

    Item to copy. If dict, may contain 'name' and 'exclude'

  • dst_root (str) –

    Root destination directory

  • level (int) –

    Reporting level

Raises:
  • FileNotFoundError

    If the source path does not exist.

compress(root, item, dst_root, level)

Compress files or directories into a ZIP archive.

Parameters:
  • root (str) –

    Root source directory

  • item (Union[str, Dict[str, str]]) –

    Item to compress. If dict, may contain 'name' and 'exclude'

  • dst_root (str) –

    Root destination directory

  • level (int) –

    Reporting level

Raises:
  • FileNotFoundError

    If the source path does not exist

decompress(root, item, dst_root, level)

Decompress ZIP archives.

Parameters:
  • root (str) –

    Root source directory

  • item (Union[str, Dict[str, str]]) –

    Item to compress. If dict, may contain 'name' and 'exclude'

  • dst_root (str) –

    Root destination directory

  • level (int) –

    Reporting level

Raises:
  • FileNotFoundError

    If the source path does not exist

run(action, root, level=0)

Perform an action.

Parameters:
  • action (str) –

    The action to perform

  • root (str) –

    Root source directory

  • level (int, default: 0 ) –

    Reporting level

main(arguments=[])

Run grebaker using the given parameters.

Parameters:
  • arguments (List[str], default: [] ) –

    A list of command line arguments

Returns:
  • int

    The exit code (0 for success)

script_run()

Execute from command line.