check.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import logging
  2. import borgmatic.borg.check
  3. import borgmatic.config.validate
  4. import borgmatic.hooks.command
  5. logger = logging.getLogger(__name__)
  6. def run_check(
  7. config_filename,
  8. repository,
  9. location,
  10. storage,
  11. consistency,
  12. hooks,
  13. hook_context,
  14. local_borg_version,
  15. check_arguments,
  16. global_arguments,
  17. local_path,
  18. remote_path,
  19. ):
  20. '''
  21. Run the "check" action for the given repository.
  22. '''
  23. if check_arguments.repository and not borgmatic.config.validate.repositories_match(
  24. repository, check_arguments.repository
  25. ):
  26. return
  27. borgmatic.hooks.command.execute_hook(
  28. hooks.get('before_check'),
  29. hooks.get('umask'),
  30. config_filename,
  31. 'pre-check',
  32. global_arguments.dry_run,
  33. **hook_context,
  34. )
  35. logger.info(f'{repository.get("label", repository["path"])}: Running consistency checks')
  36. borgmatic.borg.check.check_archives(
  37. repository['path'],
  38. location,
  39. storage,
  40. consistency,
  41. local_borg_version,
  42. global_arguments,
  43. local_path=local_path,
  44. remote_path=remote_path,
  45. progress=check_arguments.progress,
  46. repair=check_arguments.repair,
  47. only_checks=check_arguments.only,
  48. force=check_arguments.force,
  49. )
  50. borgmatic.hooks.command.execute_hook(
  51. hooks.get('after_check'),
  52. hooks.get('umask'),
  53. config_filename,
  54. 'post-check',
  55. global_arguments.dry_run,
  56. **hook_context,
  57. )