NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.09k stars 14.14k forks source link

Paperless document_exporter failing because of `read-only file system` #323602

Closed MartiniMoe closed 4 months ago

MartiniMoe commented 4 months ago

Describe the bug

I'm trying to create backups of paperless with the builtin document_exporter command. The command fails because it reports config.services.paperless.dataDir as a read-only file system, even when running as the paperless user.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install paperless
  2. Configure a backup job, for example with borg
  3. Backup job fails because the dataDir is reported as being read-only

Expected behavior

Backup job succeeds. The path should be writeable by paperless, because uploading documents etc all works.

Example backup configuration

This is a part of the borg backup job configuration I am using:

  services.borgbackup.jobs = {
    paperless = {
      user = config.services.paperless.user;
      group = config.services.paperless.user;
      paths = [ "/tmp/paperless_backup" ];
      preHook = ''
        mkdir -p /tmp/paperless_backup
        ${config.services.paperless.dataDir}/paperless-manage document_exporter /tmp/paperless_backup --delete
      '';

Output of failed backup service

Jun 30 14:02:16 capricanix systemd[1]: Started BorgBackup job paperless.
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]: Traceback (most recent call last):
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/vanp2k3y385mhqljkdxqzq5zckznjss8-paperless-ngx-2.9.0/lib/paperless-ngx/src/manage.py", line 10, in <mo>
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     execute_from_command_line(sys.argv)
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/yg459j7gxrxj2apfxnszacks0cg05dwp-python3.11-django-4.2.12/lib/python3.11/site-packages/django/core/man>
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     utility.execute()
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/yg459j7gxrxj2apfxnszacks0cg05dwp-python3.11-django-4.2.12/lib/python3.11/site-packages/django/core/man>
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     self.fetch_command(subcommand).run_from_argv(self.argv)
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/yg459j7gxrxj2apfxnszacks0cg05dwp-python3.11-django-4.2.12/lib/python3.11/site-packages/django/core/man>
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     self.execute(*args, **cmd_options)
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/yg459j7gxrxj2apfxnszacks0cg05dwp-python3.11-django-4.2.12/lib/python3.11/site-packages/django/core/man>
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     self.check()
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/yg459j7gxrxj2apfxnszacks0cg05dwp-python3.11-django-4.2.12/lib/python3.11/site-packages/django/core/man>
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     all_issues = checks.run_checks(
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:                  ^^^^^^^^^^^^^^^^^^
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/yg459j7gxrxj2apfxnszacks0cg05dwp-python3.11-django-4.2.12/lib/python3.11/site-packages/django/core/che>
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     new_errors = check(app_configs=app_configs, databases=databases)
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/vanp2k3y385mhqljkdxqzq5zckznjss8-paperless-ngx-2.9.0/lib/paperless-ngx/src/paperless/checks.py", line >
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     path_check("PAPERLESS_DATA_DIR", settings.DATA_DIR)
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:   File "/nix/store/vanp2k3y385mhqljkdxqzq5zckznjss8-paperless-ngx-2.9.0/lib/paperless-ngx/src/paperless/checks.py", line >
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:     with open(test_file, "w"):
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]:          ^^^^^^^^^^^^^^^^^^^^
Jun 30 14:02:18 capricanix borgbackup-job-paperless-start[1072236]: OSError: [Errno 30] Read-only file system: '/var/lib/paperless/__paperless_write_test_1072236__'
Jun 30 14:02:19 capricanix systemd[1]: borgbackup-job-paperless.service: Main process exited, code=exited, status=1/FAILURE
Jun 30 14:02:19 capricanix systemd[1]: borgbackup-job-paperless.service: Failed with result 'exit-code'.
Jun 30 14:02:19 capricanix systemd[1]: borgbackup-job-paperless.service: Triggering OnFailure= dependencies.
Jun 30 14:02:19 capricanix systemd[1]: borgbackup-job-paperless.service: Consumed 2.609s CPU time, no IP traffic.

Notify maintainers

@lukegb @erikarvstedt @leona-ya

Metadata

[root@capricanix:~]# nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.9.1, NixOS, 24.05 (Uakari), 24.05.20240626.89c4987`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/store/f0ddmw6s86y567yg06h5019z72szbzch-source`

Add a :+1: reaction to issues you find important.

erikarvstedt commented 4 months ago

borgbackup-job-paperless.service sets ProtectSystem = strict, so /var is read-only. Try adding this to your config:

services.borgbackup.jobs = {
  paperless = {
    readWritePaths = [ config.services.paperless.dataDir ];
    # ...
  };
};
MartiniMoe commented 4 months ago

Thank you very much, that was it! It works now! :)