grebakker

API

API

grebakker - greyrat's backupper for hackers

Log

Handles logging of performed actions in CSV or JSON format.

__init__(name, restart, log_format, off)

Initializes the Log object.

Parameters:

Name Type Description Default
name str

Path to the log file.

required
restart bool

If True, overwrites the existing log file.

required
log_format str

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

required
off bool

If True, disables logging.

required

write(act, src, dst, duration)

Writes a log entry about a performed action.

Parameters:

Name Type Description Default
act str

Action performed.

required
src str

Source path.

required
dst str

Destination path.

required
duration str

Duration of the action.

required

error(error)

Writes a log entry about an error.

Parameters:

Name Type Description Default
error str

The error occured.

required

close()

Closes the log file.

Grebakker

Performs backup operations.

__init__(dest, log, verbosity)

Initializes the Grebakker object.

Parameters:

Name Type Description Default
dest str

Destination directory for backups.

required
log Log

Log object for recording actions.

required
verbosity int

Verbosity level for output.

required

_action_begin(mml_action, path, level)

Marks the beginning of an action.

Parameters:

Name Type Description Default
mml_action str

Description of the action.

required
path str

Path involved in the action.

required
level int

Indentation level.

required

Returns:

Type Description
datetime

Start time of the action.

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

Marks the end of an action and logs it.

Parameters:

Name Type Description Default
action str

Action performed.

required
path str

Source path.

required
dst str

Destination path.

required
level int

Indentation level.

required
t1 datetime

Start time of the action.

required

_yield_files(src, exclude)

Yields files from the source directory, excluding specified patterns.

Parameters:

Name Type Description Default
src str

Source directory.

required
exclude List[str]

List of patterns to exclude.

required

Yields:

Name Type Description
source_path str

Relative path to each file.

_i(level)

Returns indentation spaces for the given output level.

Parameters:

Name Type Description Default
level int

Indentation level.

required

Returns:

Type Description
str

Indentation spaces.

_destination_exists(action, src, dst, level)

Determines the destination path for an action.

Parameters:

Name Type Description Default
action str

Action being performed.

required
src str

Source path.

required
level int

Indentation level.

required

Returns:

Type Description
str or None

Destination path or None if the destination file exists.

copy(src_root, item, dst_root, level)

Copies files or directories from source to destination.

Parameters:

Name Type Description Default
src_root str

Root source directory.

required
item str or Dict[str, str]

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

required
dst_root str

Root destination directory.

required
level int

Reporting level.

required

Raises:

Type Description
FileNotFoundError

If the source path does not exist.

compress(root, item, dst_root, level)

Compresses files or directories into a ZIP archive.

Parameters:

Name Type Description Default
root str

Root source directory.

required
item str or Dict[str, str]

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

required
dst_root str

Root destination directory.

required
level int

Reporting level.

required

Raises:

Type Description
FileNotFoundError

If the source path does not exist.

decompress(root, item, dst_root, level)

Compresses files or directories into a ZIP archive.

Parameters:

Name Type Description Default
root str

Root source directory.

required
item str or Dict[str, str]

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

required
dst_root str

Root destination directory.

required
level int

Reporting level.

required

Raises:

Type Description
FileNotFoundError

If the source path does not exist.

run(action, root, level=0)

Performs an action

Parameters:

Name Type Description Default
action str

The action to perform.

required
root str

Root source directory.

required
level int

Reporting level.

0

main(arguments=None)

The main method using parameters from the command line.

Parameters:

Name Type Description Default
arguments List[str]

A list of command line arguments.

None

Returns:

Type Description
int

The exit code (0 for success).