Fatal: create key in repository at /mnt/backup/backup failed

Hi. I’m trying to get started using the restic tool (v0.9.6). My goal is to do a full backup of my linux (lubuntu 18.04) partition to a local external USB NTFS hard drive.

I’m following the example here (https://restic.readthedocs.io/en/stable/080_examples.html#backing-up-your-system-without-running-restic-as-root) of “backing up your system without running restic as root”. So I’ve performed the chown, chmod, and setcap steps as outlined in the example.

I’m currently getting hung up when I try to init the repo on the external drive.
sudo -u restic ~restic/bin/restic init -r /mnt/backup/backup
I get the following error:

Fatal: create key in repository at /mnt/backup/backup failed: chmod /mnt/backup/backup/keys/b4954085f64adb61b4835276b207644550abd3ce71a144c02307eb1977159ad3: operation not permitted

It seems to be some kind of permissions problem, but I don’t know how to resolve it. By default, lubuntu was auto mounting the external drive. After some searching on the web, I tried to mount the external drive with the following options:
mount -t ntfs -o umask=000 /dev/sdb1 /mnt/backup
mount -t ntfs -o umask=000,allow_other /dev/sdb1 /mnt/backup
All of them give the same error.

If I init a directory in my home directory, that works okay. Can I copy the repository created in my home folder to the external drive and continue from there?

Thanks.

Try to switch to restic user with:

sudo su - restic -s /bin/bash

and check if you can create files under /mnt/backup. If not, you might want to check your mount options (maybe rw or similar? I am not using ntfs for very long time).

Moving the initialized repo should theoretically work, but you can have same issue under the subfolders so you might want to fix the underlying problem instead.

Hello gurkan.
Thanks for your reply. As you suspected, copying over the initialized repo runs into an issue with the subfolders (because the ownership is not preserved). I also tried your suggestion:

but I get the same fatal error as before.

I found this stack exchange link that might be relevant: https://askubuntu.com/questions/11840/how-do-i-use-chmod-on-an-ntfs-or-fat32-partition
As you hinted, ownership/permissions are determined by the mount options. The link also elaborates that you can’t run chmod on a ntfs partition (hence the fatal error).
When, lubuntu auto-mounts the external drive, all files/folders on the drive are owned by $USER.
If I mount using “mount -t ntfs -o umask=000 /dev/sdb1 /mnt/backup”, then all files are owned by root. Changing to su restic doesn’t affect the file ownerships on the external drive i.e. files created by ‘restic’ still belongs to $USER (in the case of the auto-mount). From a cursory reading of some of the posts on that link, it seems it may be possible to support multiple users on the NTFS partition, but I’m not interested in going down that road.

Initializing the repo as root works (once the drive is mounted appropriately), however the restic documentation discourages running as root.

Best Regards.

Didn’t want to struggle with loop device so I’ve searched and found my old USB drive. Formatted with NTFS, now I can emulate what you’re doing.

What about getting user and group ids of restic user with id restic command and mounting the volume like:

sudo mount -t ntfs -o uid=9999,gid=9999,umask=000,users,allow_other /dev/sdb1 /mnt/backup

(ofc real uid & gid values instead of 9999)

This way restic user will be able to write into that. On my test I’ve succeed to initialize the repo, also other users were able to write to the partition too.

Oh wow, thanks for doing this @gurkan.
I can confirm that it works on my end as well.
Many thanks.

1 Like