Errors when creating repo on external hard drive

Newbie. I’m running Ubuntu 21.04. Getting errors when I try to create a repo on an external hard drive ext4 and /dev/sda1/. I created a directory on the drive called ‘rr’. Here’s what I’ve tried and all failed. What is the correct command? Thanks

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /dev/sda1/rr-test
Fatal: create repository at /dev/sda1/rr-test failed: ReadDir: open /dev/sda1/rr-test/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /dev/sda1//rr/rr-test
Fatal: create repository at /dev/sda1//rr/rr-test failed: ReadDir: open /dev/sda1/rr/rr-test/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /sda1/rr/rr-test
Fatal: create repository at /sda1/rr/rr-test failed: MkdirAll: mkdir /sda1: permission denied

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /dev/sda1/rr/rr-test
Fatal: create repository at /dev/sda1/rr/rr-test failed: ReadDir: open /dev/sda1/rr/rr-test/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /sda1/rr/rrtest
Fatal: create repository at /sda1/rr/rrtest failed: MkdirAll: mkdir /sda1: permission denied

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /dev/sda1/rr/rrtest/
Fatal: create repository at /dev/sda1/rr/rrtest/ failed: ReadDir: open /dev/sda1/rr/rrtest/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ ^C
advait@advait-Bravo-15-A4DDR:~$ restic init --repo /dev/sda1/rr/
Fatal: create repository at /dev/sda1/rr/ failed: ReadDir: open /dev/sda1/rr/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /dev/sda1/rr/
Fatal: create repository at /dev/sda1/rr/ failed: ReadDir: open /dev/sda1/rr/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ restic init --repo /dev/sda1/
Fatal: create repository at /dev/sda1/ failed: ReadDir: open /dev/sda1/keys: not a directory

Hi @m3110w and welcome to the restic community! :slight_smile:

I think the underlying problem is this:

mkdir /sda1: permission denied

You have to check your fstab to see which mount options you gave the hard drive as normal users are prohibited from writing to the mountpoint.
I bet you that if you run the restic init command as root or with sudo, it will work.

1 Like

Sudo didn’t seem to work. Any ideas how to fix this? Does the mount point need to be set to root? See pic.

advait@advait-Bravo-15-A4DDR:~$ sudo restic init --repo /dev/sda1/rr/
[sudo] password for advait:
Fatal: create repository at /dev/sda1/rr/ failed: ReadDir: open /dev/sda1/rr/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ sudo restic init --repo /dev/sda1/
Fatal: create repository at /dev/sda1/ failed: ReadDir: open /dev/sda1/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ sudo restic init --repo /dev/sda1//rr/keys
Fatal: create repository at /dev/sda1//rr/keys failed: ReadDir: open /dev/sda1/rr/keys/keys: not a directory

advait@advait-Bravo-15-A4DDR:~$ sudo restic init --repo /dev/sda1//rr/
Fatal: create repository at /dev/sda1//rr/ failed: ReadDir: open /dev/sda1/rr/keys: not a directory
.
rr = restic repo
.

Can you provide what you think is the correct command? I really don’t know exactly what the command should be. That would be very helpful.

If I want to use restic to make a backup to an external USB hard drive, does the repository for that backup also need to be created and reside on that same external hard drive?

Or do restic repositories reside in /srv/repo while the backed up data reside on the external hard drive?

The path you need to specify is this one:

/media/advait/Nisgad500GB/

instead of /dev/sda1/.

1 Like

No, you can move or have the repository wherever you want. You can even have multiple copies.
For example this is a setup I use for my own PC.
I have two physical hard drives - one is my live Linux Mint system and the other is just a hard drive I have mounted which host’s my Restic repository for the backups I do of my Linux Mint installation. For fast recovery or fast access to the repo I have it there.
But additionally to this, I use the Software rclone to synchronize this Restic repository to Backblaze B2.

So your idea is totally valid and even makes sense. :slight_smile:

OK, thanks. So if I create a restic repository (RR) on my main internal drive, how do I connect that RR to a backup on an external USB drive (EUD)? From the restic documentation for local backups, it looks like the location of the RR and the location of the backup (EUD in my case) have to be the same. What am I missing?

Please give me 2 things: 1. An example of a command to create a RR on my main internal drive and 2. An example of a command to make a backup to an EUD that is connected to the RR in 1.

Thanks.

You’re thinking too complicated! A restic repository is simply a folder that has been initialized like so:

mkdir /srv/restic-backup
restic -r /srv/restic-backup init

It doesn’t matter where you create that but it has to be in your file system (like /srv), not directly on a device (like /dev/sda1). restic will then put a couple of files into that folder and more files later, when you start backing up which you do like so:

restic -r /srv/restic-backup backup /home/yourname

You can then check the result:

restic -r /srv/restic-backup snapshots

Or check out what’s in the repository:

restic -r /srv/restic-backup mount /mnt
ls -l /mnt

If you want to make sure you still have the backup when your internal drive dies, you could rsync it to your external drive:

mkdir /media/advait/Nisgad500GB/restic-backup
rsync -Prvth --delete /srv/restic-backup/ /media/advait/Nisgad500GB/restic-backup/ (make sure you have slashes after each path)

2 Likes

So you’re saying one single Restic Repository holds the data for ALL Restic backups that I create? I have that right?

You’re saying that I don’t need to create a separate Restic Repository for each Restic backup? I have that right?

Thanks for clarifying.

OK, Looks like this command tells Restic to use such and such repository to backup such and such location (/home/yourname). But where is the command to tell Restic to save the backup to my external USB drive? That’s the crucial part I’m missing.

So you’re saying one single Restic Repository holds the data for ALL Restic backups that I create? I have that right?

You can save as many snapshots in a repository as you have space on that disk. restic only adds the parts of the source files it doesn’t already have in one of the parent snapshots and it deduplicates files and also parts of files (see documentation). And you can add different sources to the same repository and still get the benefit of deduplication.

So say you have stored some files in different folders multiple times, they will only get stored once in the restic repository. I have repositories that are about half the size of the original source, because people using the system just store the same files over and over again.

You’re saying that I don’t need to create a separate Restic Repository for each Restic backup? I have that right?

Absolutely not! One repository is enough. But of course you’re free to create as many repos as you want. Just be aware that deduplication won’t work between different repositories.

OK, Looks like this command tells Restic to use such and such repository to backup such and such location (/home/yourname). But where is the command to tell Restic to save the backup to my external USB drive?

You don’t need to use restic for that. I gave you an example using the rsync command above. If you’ve changed your original local repository and re-execute rsync, it will itself just transfer the parts of the repository folder that have changed.

I recommend you check out the man pages and documentation for both commands and just play around with it a little. You can totally just backup an example folder with few files to play and see what happens.

1 Like

(My comments here only pertain to the very simple use case of using Restic to backup data from a desktop pc to a USB connected external hard drive. I know Restic can do much more complicated backup scenarios.)

Thanks for the details. Very helpful. I finally got it figured out (at least a little bit). I initialized the repo at /media/advait/drive-name/repo-name. It took a while before I realized that creating the repo here is actually putting the repo on the hard drive itself, and not on my internal drive.

Then I had to realize that the backup command backs up the data to the same location as the repo (in mycase, on my USB connected external drive). So, for my simple use case, it seems the repo must exist on the same drive as the backup.

I don’t see a way for the repo to reside on my internal hard drive while sending the backup data to an external drive. If there is, let me know.

These two points were not made clear in the Restic tuts (at least for me). After finally realizing this basic stuff, I was able to successfully do some small test backups. So I’m all set. Thanks again for your help.

Could you mark this thread as resolved. Thanks!

Cool, glad to hear it worked out! The repo IS the place (folder) where the backups go, exactly. I think you can select one of the answers above as the answer in the thread!

1 Like

Thanks for your help! :slight_smile: I’ve started my first real backup.

2 Likes