Backing up/restoring relative paths

I’m trying to understand behavior that I’m seeing with restic during backup and restore.

Let’s say I have a data directory that I want to back up, /Users/steve/tmp/restic-test/data.

Scenario #1

  1. Change pwd to my data dir: cd /Users/steve/tmp/restic-test/data
  2. Take backup: restic backup .
  3. See backup has full directory stored: restic snapshots -> /Users/steve/tmp/restic-test/data
  4. Restore into a new directory: restic restore --target /Users/steve/tmp/restic-test/restored-data <snapshotID>
  5. See contents of /Users/steve/tmp/restic-test/data restored into /Users/steve/tmp/restic-test/restored-data.

So far, so good.

Scenario #2

  1. Change pwd to the parent of my data dir: cd /Users/steve/tmp/restic-test
  2. Take backup: restic backup data/
  3. See backup has full directory stored: restic snapshots -> /Users/steve/tmp/restic-test/data
  4. Restore into a new directory: restic restore --target /Users/steve/tmp/restic-test/restored-data <snapshotID>
  5. See the data dir itself restored into /Users/steve/tmp/restic-test/restored-data, i.e. now I see /Users/steve/tmp/restic-test/restored-data.

OK, so it seems that restic is internally keeping track of the relative path I used when I took the backup, and restoring based on that.

Scenario #3

  1. (from any pwd) take backup specifying absolute path: restic backup /Users/steve/tmp/restic-test/data
  2. See backup has full directory stored: restic snapshots -> /Users/steve/tmp/restic-test/data
  3. Restore into a new directory: restic restore --target /Users/steve/tmp/restic-test/restored-data <snapshotID>
  4. See the full tree of the backed up dir’s path itself restored into /Users/steve/tmp/restic-test/restored-data, i.e. now I see /Users/steve/tmp/restic-test/Users/steve/tmp/restic-test/data.

So, it seems that restic is retaining info about the relative or absolute path that I’m using when backing up, even though it only displays the absolute path when looking at restic snapshots.

Is this expected behavior? If so, is it documented anywhere? It is actually useful for use to have, but if it is intended, it would be really useful to be able to view the relative paths somewhere in the restic snapshots output so we know ahead of time what will happen when we restore a given snapshot.

This is indeed expected behavior, and I agree that it isn’t obvious when you’re only looking at the output of restic snapshots. restic’s behavior is modeled after what tar does. The program logic here is still pretty simple, the idea is that in a snapshot, the absolute path to the data is saved, so on a subsequent backup we can find it again.

Did you know that you can list a snapshot with restic ls <id>?

Oh, great, that definitely helps make it clear. Thanks for the quick response!