mentat.module.cleanup module

This Mentat module is a script providing database and cache cleanup functions and features.

This script is implemented using the pyzenkit.zenscript framework and so it provides all of its core features. See the documentation for more in-depth details.

It is further based on mentat.script.fetcher module, which provides database fetching and message post-processing capabilities.

Usage examples

# Display help message and exit.
mentat-cleanup.py --help

# Run in debug mode (enable output of debugging information to terminal).
mentat-cleanup.py --debug

# Run with increased logging level.
mentat-cleanup.py --log-level debug

Available script commands

cleanup (default)

Perform cleanup of configured database collections and directory caches.

Custom configuration

Custom command line options

--db-path dir-name

Path to database files (for disk usage measurements).

Type: string, default: /var/lib/postgresql/10/main

--simulate

Perform simulation, do not remove anything (flag).

Type: boolean, default: False

Available cleanup thresholds

  • 3y: items older than three years

  • 2y: items older than two years

  • y: items older than one year

  • 9m: items older than nine months

  • 6m: items older than six months

  • 4m: items older than four months

  • 3m: items older than three months

  • 16w: items older than sixteen weeks

  • 12w: items older than twelwe weeks

  • 8w: items older than eight weeks

  • 4w: items older than four weeks

  • 2w: items older than two weeks

  • w: items older than one week

  • 6d: items older than six days

  • 5d: items older than five days

  • 4d: items older than four days

  • 3d: items older than three days

  • 2d: items older than two days

  • d: items older than one day

  • 12h: items older than twelve hours

  • 8h: items older than eight hours

  • 6h: items older than six hours

  • 4h: items older than four hours

  • 3h: items older than three hours

  • 2h: items older than two hours

  • h: items older than one hour

class mentat.module.cleanup.MentatCleanupScript[source]

Bases: mentat.script.fetcher.FetcherScript

Implementation of Mentat module (script) providing database and cache cleanup functions and features.

CONFIG_CACHES = 'caches'
CONFIG_DB_PATH = 'db_path'
CONFIG_EVENTS = 'events'
CONFIG_RUNLOGS = 'runlogs'
CONFIG_SIMULATE = 'simulate'
CONFIG_TABLES = 'tables'
cbk_command_cleanup()[source]

Implementation of the cleanup command (default).

Perform cleanup of configured database collections and directory caches.

get_default_command()[source]

Return the name of the default script command. This command will be executed in case it is not explicitly selected either by command line option, or by configuration file directive.

Returns

Name of the default command.

Return type

str

mentat.module.cleanup.SECS_YEAR = 31556926

Number of seconds in a year (approximate).

mentat.module.cleanup.THRESHOLDS = {'12h': {'d': datetime.timedelta(0, 43200), 'l': 'items older than twelve hours'}, '12w': {'d': datetime.timedelta(84), 'l': 'items older than twelve weeks'}, '16w': {'d': datetime.timedelta(112), 'l': 'items older than sixteen weeks'}, '2d': {'d': datetime.timedelta(2), 'l': 'items older than two days'}, '2h': {'d': datetime.timedelta(0, 7200), 'l': 'items older than two hours'}, '2w': {'d': datetime.timedelta(14), 'l': 'items older than two weeks'}, '2y': {'d': datetime.timedelta(730, 41852), 'l': 'items older than two years'}, '3d': {'d': datetime.timedelta(3), 'l': 'items older than three days'}, '3h': {'d': datetime.timedelta(0, 10800), 'l': 'items older than three hours'}, '3m': {'d': datetime.timedelta(91, 26831), 'l': 'items older than three months'}, '3y': {'d': datetime.timedelta(1095, 62778), 'l': 'items older than three years'}, '4d': {'d': datetime.timedelta(4), 'l': 'items older than four days'}, '4h': {'d': datetime.timedelta(0, 14400), 'l': 'items older than four hours'}, '4m': {'d': datetime.timedelta(121, 64575), 'l': 'items older than four months'}, '4w': {'d': datetime.timedelta(28), 'l': 'items older than four weeks'}, '5d': {'d': datetime.timedelta(5), 'l': 'items older than five days'}, '6d': {'d': datetime.timedelta(6), 'l': 'items older than six days'}, '6h': {'d': datetime.timedelta(0, 21600), 'l': 'items older than six hours'}, '6m': {'d': datetime.timedelta(182, 53663), 'l': 'items older than six months'}, '8h': {'d': datetime.timedelta(0, 28800), 'l': 'items older than eight hours'}, '8w': {'d': datetime.timedelta(56), 'l': 'items older than eight weeks'}, '9m': {'d': datetime.timedelta(273, 80494), 'l': 'items older than nine months'}, 'd': {'d': datetime.timedelta(1), 'l': 'items older than one day'}, 'h': {'d': datetime.timedelta(0, 3600), 'l': 'items older than one hour'}, 'w': {'d': datetime.timedelta(7), 'l': 'items older than one week'}, 'y': {'d': datetime.timedelta(365, 20926), 'l': 'items older than one year'}}

List of possible cleanup thresholds.

mentat.module.cleanup.json_dump_cbk(obj)[source]

Callback method for serializing objects into JSON.