2019-11-19 04:43:23 -08:00
|
|
|
#!/usr/bin/env python3
|
2019-11-19 04:41:38 -08:00
|
|
|
|
|
|
|
|
2023-03-27 18:50:11 -07:00
|
|
|
from domain.BackupRotator import BackupRotator
|
|
|
|
|
2019-11-19 04:41:38 -08:00
|
|
|
|
2022-01-31 12:35:08 -08:00
|
|
|
import argparse
|
|
|
|
|
2019-11-19 04:41:38 -08:00
|
|
|
|
|
|
|
def main():
|
|
|
|
|
2022-01-31 12:35:08 -08:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Mike's Backup Rotator. Helps automatically remove old backup files or folders."
|
|
|
|
)
|
|
|
|
|
2023-03-27 19:59:45 -07:00
|
|
|
parser.add_argument(
|
|
|
|
"--debug", "--verbose",
|
|
|
|
dest="debug",
|
|
|
|
default=False,
|
|
|
|
action="store_true",
|
|
|
|
help="Verbose/Debug logging mode"
|
|
|
|
)
|
|
|
|
|
2024-06-09 06:51:51 -07:00
|
|
|
parser.add_argument(
|
|
|
|
"--systemd",
|
|
|
|
default=False,
|
|
|
|
dest="systemd",
|
|
|
|
action="store_true",
|
|
|
|
help=(
|
|
|
|
"Pass if this program will be spawned inside systemd"
|
|
|
|
" or another system that already adds timestamps to log messages."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--syslog", "--write-to-syslog",
|
|
|
|
default=False,
|
|
|
|
dest="write_to_syslog",
|
|
|
|
action="store_true",
|
|
|
|
help=(
|
|
|
|
"Pass if you'd like this program to write to syslog."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-06-22 15:31:31 -07:00
|
|
|
parser.add_argument(
|
|
|
|
"--no-test-logs",
|
|
|
|
default=True,
|
|
|
|
dest="do_test_logs",
|
|
|
|
action="store_false",
|
|
|
|
help=(
|
|
|
|
"Pass if you do not want to see test logs for all log levels."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--test-logs",
|
|
|
|
default=True,
|
|
|
|
dest="do_test_logs",
|
|
|
|
action="store_true",
|
|
|
|
help=(
|
|
|
|
"Pass if you want to see test logs for all log levels."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-01-31 12:35:08 -08:00
|
|
|
parser.add_argument(
|
|
|
|
"--config", "-c",
|
2024-06-09 09:22:48 -07:00
|
|
|
dest="config_paths",
|
2022-01-31 12:35:08 -08:00
|
|
|
default=[],
|
|
|
|
action="append",
|
|
|
|
type=str,
|
2024-06-09 09:22:48 -07:00
|
|
|
help="Specify a configuration file or configuration directory. Can be called multiple times."
|
2022-01-31 12:35:08 -08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--dry-run", "-d",
|
2024-06-09 09:22:48 -07:00
|
|
|
dest="global_dry_run",
|
2022-01-31 12:35:08 -08:00
|
|
|
default=False,
|
|
|
|
action="store_true",
|
2024-06-09 09:22:48 -07:00
|
|
|
help=(
|
|
|
|
"Only perform an analysis;"
|
|
|
|
" Don't delete anything no matter what configs say (configs can specify dry run, too)."
|
|
|
|
)
|
2022-01-31 12:35:08 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-03-27 19:59:45 -07:00
|
|
|
rotator = BackupRotator(
|
2024-06-09 09:22:48 -07:00
|
|
|
config_paths=args.config_paths,
|
2024-06-09 06:51:51 -07:00
|
|
|
debug=args.debug,
|
|
|
|
systemd=args.systemd,
|
|
|
|
write_to_syslog=args.write_to_syslog,
|
2024-06-22 15:31:31 -07:00
|
|
|
do_test_logs=args.do_test_logs,
|
2023-03-27 19:59:45 -07:00
|
|
|
)
|
2022-01-31 12:35:08 -08:00
|
|
|
rotator.run(
|
2024-06-09 09:22:48 -07:00
|
|
|
global_dry_run=args.global_dry_run
|
2022-01-31 12:35:08 -08:00
|
|
|
)
|
|
|
|
|
2019-11-19 04:41:38 -08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
2022-01-31 12:35:08 -08:00
|
|
|
|