Borg Backup configuration service - a repository already exists

I’m trying to set up Borg Backup to automatically make backups on an encrypted drive which I manually mount on /dev/mapper/backups, but I haven’t been able to create a full backup. It doesn’t matter if I create or delete the directory at /dev/mapper/backups/home-rocky/.

Here is the relevant portion of my configuration:

services.borgbackup.jobs = {
    homeBackup = {
      paths = "/home/rockyw/";
      exclude = [
        # Generate new SSH keys for every machine.
        "/home/rockyw/.ssh"
        "/home/rockyw/.cache/"
        "/home/rockyw/Documents/borg_passphrase"
      ];

      # Reference the disk where I mount it.
      repo = "/dev/mapper/backups/home-rocky";

      # Create the repo if it doesn’t exist.
      # doInit = true;

      encryption = {
        # repokey is for manual password entry.
        mode = "repokey";

        # Keep the actual password out of the store.
        passCommand = "cat /home/rockyw/Documents/borg_passphrase";
      };

      # Compress heavily and slowly. This is a good idea right now on my small
      # USB drive.
      compression = "lzma,6";

      # From the BorgBackup documentation:

      # Giving levels above 6 is pointless and counterproductive because it does
      # not compress better due to the buffer size used by borg - but it wastes
      # lots of CPU cycles and RAM.

      startAt = "hourly";
    };

Here is the status of the systemd service:

systemctl status borgbackup-job-homeBackup.service:

× borgbackup-job-homeBackup.service - BorgBackup job homeBackupLoaded: loaded (/etc/systemd/system/borgbackup-job-homeBackup.service; linked; preset: ignored)Active: failed (Result: exit-code) since Sat 2026-02-07 14:00:03 MST; 30min agoDuration: 3.239sInvocation: 5497ef50556f4be8a119a029c85fb52dTriggeredBy: ● borgbackup-job-homeBackup.timerProcess: 59491 ExecStart=/nix/store/ajkywf8yk59jvzbyabmip42j9qq0i38g-unit-script-borgbackup-job-homeBackup-start/bin/borgbacku>   Main PID: 59491 (code=exited, status=2)IP: 0B in, 0B outIO: 13.5M read, 600K writtenMem peak: 74MCPU: 1.539s

Feb 07 14:00:00 nixos systemd[1]: Started BorgBackup job homeBackup.Feb 07 14:00:02 nixos borgbackup-job-homeBackup-start[59501]: Failed to create/acquire the lock /dev/mapper/backups/home-rocky/loc>Feb 07 14:00:03 nixos borgbackup-job-homeBackup-start[59511]: A repository already exists at /dev/mapper/backups/home-rocky.Feb 07 14:00:03 nixos systemd[1]: borgbackup-job-homeBackup.service: Main process exited, code=exited, status=2/INVALIDARGUMENTFeb 07 14:00:03 nixos systemd[1]: borgbackup-job-homeBackup.service: Failed with result ‘exit-code’.

Have a look into borgmatic which has options for the thinsg you are trying to set above. You can additionally use pre-backup hooks to check whether the backup disk is mounted etc.

2 Likes

Thank you :smiley: I switched to Restic, which I am now having a problem with.