A wrapper script for Borg backup software that creates and prunes backups
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
988B

  1. import logging
  2. import subprocess
  3. logger = logging.getLogger(__name__)
  4. def initialize_repository(
  5. repository,
  6. encryption_mode,
  7. append_only=None,
  8. storage_quota=None,
  9. local_path='borg',
  10. remote_path=None,
  11. ):
  12. '''
  13. Given a local or remote repository path, a Borg encryption mode, whether the repository should
  14. be append-only, and the storage quota to use, initialize the repository.
  15. '''
  16. full_command = (
  17. (local_path, 'init', repository)
  18. + (('--encryption', encryption_mode) if encryption_mode else ())
  19. + (('--append-only',) if append_only else ())
  20. + (('--storage-quota', storage_quota) if storage_quota else ())
  21. + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
  22. + (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
  23. + (('--remote-path', remote_path) if remote_path else ())
  24. )
  25. logger.debug(' '.join(full_command))
  26. subprocess.check_call(full_command)