borgmatic-collective / docker-borgmatic

Borgmatic in Docker
GNU General Public License v3.0
354 stars 93 forks source link

Unable to make fresh install work #340

Closed Xitee1 closed 3 months ago

Xitee1 commented 3 months ago

After setting up the docker-compose.yaml and borgmatic.d/config.yaml I'm always getting errors when trying to init a repository.

When running docker exec borgmatic bash -c "borgmatic init -encryption=none" I'm getting this with the default config:

/etc/borgmatic/config.yaml /etc/borgmatic.d /root/.config/borgmatic/config.yaml /root/.config/borgmatic.d: No valid configuration files found

summary:
/etc/borgmatic.d/config.yaml: Error parsing configuration file
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
                 ~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'ValueError' and 'str'
Call stack:
  File "/usr/local/bin/borgmatic", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 935, in main
    logger.handle(log)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/usr/local/lib/python3.12/site-packages/borgmatic/logger.py", line 76, in emit
    self.log_level_to_handler[record.levelno].emit(record)
Message: ValueError('Cannot find variable BORG_HEALTHCHECK_URL in environment')
Arguments: ()
/etc/borgmatic/config.yaml /etc/borgmatic.d /root/.config/borgmatic/config.yaml /root/.config/borgmatic.d: No valid configuration files found

Need some help? https://torsion.org/borgmatic/#issues

I've outcommented the healthcheck from the config.yaml but when trying again I'm getting a different error:

/mnt/borg-repository is not a valid repository. Check repo config.
/mnt/borg-repository: Error running actions for repository
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 621, in log_error_records
    raise error
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 145, in run_configuration
    yield from run_actions(
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 310, in run_actions
    borgmatic.actions.rcreate.run_rcreate(
  File "/usr/local/lib/python3.12/site-packages/borgmatic/actions/rcreate.py", line 27, in run_rcreate
    borgmatic.borg.rcreate.create_repository(
  File "/usr/local/lib/python3.12/site-packages/borgmatic/borg/rcreate.py", line 42, in create_repository
    rinfo.display_repository_info(
  File "/usr/local/lib/python3.12/site-packages/borgmatic/borg/rinfo.py", line 55, in display_repository_info
    return execute_command_and_capture_output(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/borgmatic/execute.py", line 348, in execute_command_and_capture_output
    output = subprocess.check_output(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('borg', 'info', '--json', '/mnt/borg-repository')' returned non-zero exit status 15.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
                 ~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'CalledProcessError' and 'str'
Call stack:
  File "/usr/local/bin/borgmatic", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 922, in main
    or list(collect_configuration_run_summary_logs(configs, config_paths, arguments))
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 804, in collect_configuration_run_summary_logs
    results = list(run_configuration(config_filename, config, config_paths, arguments))
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 176, in run_configuration
    yield from log_error_records(
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 642, in log_error_records
    yield log_record(levelno=levelno, levelname=level_name, msg=error)
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 599, in log_record
    logger.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/usr/local/lib/python3.12/site-packages/borgmatic/logger.py", line 76, in emit
    self.log_level_to_handler[record.levelno].emit(record)
Message: CalledProcessError(15, ('borg', 'info', '--json', '/mnt/borg-repository'))
Arguments: ()
/etc/borgmatic.d/config.yaml: An error occurred

summary:
/etc/borgmatic.d/config.yaml: Configuration sections (like location:, storage:, retention:, consistency:, and hooks:) are deprecated and support will be removed from a future release. To prepare for this, move your options out of sections to the global scope.
/etc/borgmatic.d/config.yaml: An error occurred
/mnt/borg-repository: Error running actions for repository
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
                 ~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'CalledProcessError' and 'str'
Call stack:
  File "/usr/local/bin/borgmatic", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 935, in main
    logger.handle(log)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/usr/local/lib/python3.12/site-packages/borgmatic/logger.py", line 76, in emit
    self.log_level_to_handler[record.levelno].emit(record)
Message: CalledProcessError(15, ('borg', 'info', '--json', '/mnt/borg-repository'))
Arguments: ()

Need some help? https://torsion.org/borgmatic/#issues

docker-compose.yaml:

services:
  borgmatic:
    image: ghcr.io/borgmatic-collective/borgmatic
    container_name: borgmatic
    volumes:
      - ./source:/mnt/source:ro            # backup source
      - ./repository:/mnt/borg-repository      # backup target
      - ./data/borgmatic.d:/etc/borgmatic.d/  # borgmatic config file(s) + crontab.txt
      - ./data/.config/borg:/root/.config/borg   # config and keyfiles
      - ./data/.ssh:/root/.ssh                   # ssh key for remote repositories
      - ./data/.cache/borg:/root/.cache/borg     # checksums used for deduplication
    environment:
      #- BACKUP_CRON=0 1 * * *
      - RUN_ON_STARTUP=true
      - TZ=Europe/Berlin
      - BORG_PASSPHRASE=ReplaceWithYourSecretPassPhrase

data/borgmatic.d/config.yaml:

source_directories:
    - /mnt/source
repositories:
    - path: /mnt/borg-repository
one_file_system: true

#   Passphase is set in varibable $BORG_PASSPHRASE
#   encryption_passphrase: "DoNotForgetToChangeYourPassphrase"
compression: lz4
archive_name_format: 'backup-{now}'

keep_hourly: 2
keep_daily: 7
keep_weekly: 4
keep_monthly: 12
keep_yearly: 10

checks:
  - name: repository
    frequency: 2 weeks
  - name: archives
    frequency: always
  - name: extract
    frequency: 2 weeks
  - name: data
    frequency: 1 month

hooks:
    before_backup:
        - echo "Starting a backup job."
    after_backup:
        - echo "Backup created."
    on_error:
        - echo "Error while creating a backup."

before_everything:
    - echo "Starting a backup job."
after_everything:
    - echo "Backup created."
on_error:
    - echo "Error while creating a backup."

#healthchecks:
#    ping_url: ${BORG_HEALTHCHECK_URL}

I have tried it on two servers and it just doesn't work. Did I miss something? By the way, RUN_ON_STARTUP isn't working either. After starting the container nothing happens until the cronjob kicks in.

witten commented 3 months ago

I'm not sure exactly why you're getting this error, but here are a few comments/tips:

Xitee1 commented 3 months ago

Thank you very much for the tips.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.12/logging/init.py", line 1163, in emit stream.write(msg + self.terminator)


TypeError: unsupported operand type(s) for +: 'CalledProcessError' and 'str'
Call stack:
  File "/usr/local/bin/borgmatic", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 922, in main
    or list(collect_configuration_run_summary_logs(configs, config_paths, arguments))
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 804, in collect_configuration_run_summary_logs
    results = list(run_configuration(config_filename, config, config_paths, arguments))
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 176, in run_configuration
    yield from log_error_records(
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 642, in log_error_records
    yield log_record(levelno=levelno, levelname=level_name, msg=error)
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 599, in log_record
    logger.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/usr/local/lib/python3.12/site-packages/borgmatic/logger.py", line 76, in emit
    self.log_level_to_handler[record.levelno].emit(record)
Message: CalledProcessError(15, ('borg', 'info', '--json', '/mnt/borg-repository'))
Arguments: ()
/etc/borgmatic.d/config.yaml: An error occurred

summary:
/etc/borgmatic.d/config.yaml: Configuration sections (like location:, storage:, retention:, consistency:, and hooks:) are deprecated and support will be removed from a future release. To prepare for this, move your options out of sections to the global scope.
/etc/borgmatic.d/config.yaml: An error occurred
/mnt/borg-repository: Error running actions for repository
--- Logging error ---
/etc/borgmatic.d/config.yaml: Loading configuration file
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
                 ~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'CalledProcessError' and 'str'
Call stack:
  File "/usr/local/bin/borgmatic", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.12/site-packages/borgmatic/commands/borgmatic.py", line 935, in main
    logger.handle(log)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/usr/local/lib/python3.12/site-packages/borgmatic/logger.py", line 76, in emit
    self.log_level_to_handler[record.levelno].emit(record)
Message: CalledProcessError(15, ('borg', 'info', '--json', '/mnt/borg-repository'))
Arguments: ()

Need some help? https://torsion.org/borgmatic/#issues
```
witten commented 3 months ago

BORG_HEALTHCHECK_URL you're correct, I haven't configured it because it isn't documented at all in the readme. I don't really know what I have to set it to (I'm completely new to borg backup).

This would be the URL of a Healthchecks server that you want borgmatic to ping with backup success/failure. This is of course an optional feature you don't have to use.

I don't think that borgmatic init -encryption=none is invalid. Doing borgmatic init --encryption none is giving me this error: Unrecognized argument: none. The standard borg command (not the borgmatic one) also uses the = in between (https://borgbackup.readthedocs.io/en/stable/usage/init.html#examples). Nevertheless, doing -e none results in the same error as posted before.

The only thing I can think of is there must be a typo there somewhere. borgmatic and Borg do not use 100% of the same arguments, and in this case borgmatic expects either -e none or --encryption none.

Using the info command or verbosity flag sadly doesn't give me a more useful error message. docker exec borgmatic bash -c "borgmatic init -e none --verbosity 2"

FWIW, I've been able to reproduce the problem you're seeing when running borgmatic in the container image. Strangely, it doesn't repro outside of the container for me. Maybe this is a difference in Python versions (3.12.3 in the container and 3.12.4 outside)?

witten commented 3 months ago

Interesting.. I think there are at least two problems here:

witten commented 3 months ago

Also, you can likely work around the first issue until it's fixed with the following change to your borgmatic configuration..

Change this:

repositories:
    - path: /mnt/borg-repository

... to this:

repositories:
    - path: /mnt/borg-repository/repo

That will cause the repository to be created in a (not yet existent) subdirectory of your mounted repository path. That way, borgmatic doesn't get confused and think that because /mnt/borg-repository already exists, something must be wrong.

witten commented 3 months ago

https://projects.torsion.org/borgmatic-collective/borgmatic/issues/896

Xitee1 commented 3 months ago

Also, you can likely work around the first issue until it's fixed with the following change to your borgmatic configuration..

Change this:

repositories:
    - path: /mnt/borg-repository

... to this:

repositories:
    - path: /mnt/borg-repository/repo

That will cause the repository to be created in a (not yet existent) subdirectory of your mounted repository path. That way, borgmatic doesn't get confused and think that because /mnt/borg-repository already exists, something must be wrong.

Thank your very much, that works 👍

witten commented 3 months ago

Glad to hear that did it for now!