File inclusion seems to fail, no matter how I try to configure it


I am trying to back up my home directory.
I am using systemd-homed, which uses the following structure in /home:
/home/user.home (this is the image file which is mounted when the user is authenticated)
/home/user (this is the temporary mount of /home/user.home, which is empty when the user is not authenticated and is only readable for the user)
I am using a systemd service to initiate the Kopia backup for /home.
This all means that I want to backup each .home file in /home, but ignore the content or the created mount folder of each mounted directory.

So in my example /home/user.home would be backed up, but /home/user’s contents would not be attempted to be backup up, so ignored. This would be true for user2, user3 and so on.

Now, I looked at the docs and forum posts, but the solutions I have tried or were posted there, seems to not backup anything.

I have created the following ignore policy for /home:
Files policy:
Ignore cache directories: true inherited from (global)
Ignore rules: (defined for this target)
Read ignore rules from files: inherited from (global)

As far as I understand, this should ignore everything, but the .home files in /home.

Then I call: sudo kopia snapshot create /home (for now root is the user doing the backup, maybe I will make an unprivilaged readonly user which can access everything):

Snapshotting root@minefpc:/home …

  • 0 hashing, 0 hashed (0 B), 0 cached (0 B), uploaded 0 B, estimating…
    Created snapshot with root k7f976c0894948354dcee4943670fda05 and ID e471effae9701b1fae2f527ed1f8d23f in 0s

So nothing…

What am I missing? I feel like I am going crazy, this should be such a simple thing to do.

Relevant posts:

As a stopby solution, I manually specified the folders to be excluded, but that is not viable when users could dynamically be added or removed.

Have a look at this post. Maybe it will give you some clue how to proceed.

At the end it is just about using right exclusion/inclusion patterns.

1 Like

Hi, thanks for the answer.

So I took a look at the post you linked the only difference I see is that you used the exclude-all pattern only on the root of the backup, so /* instead of *.

I changed my policy to:
Files policy:
Ignore cache directories: true inherited from (global)
Ignore rules: (defined for this target)
I do not see how this would affect btw anything, because there this only means that by default not all, but patterns only in the root should be ignored, but I changed it to your suggestion.

However, the problem persists still.

I even tried specifying !/admin.home, but it is still not being backed up.

It is like if Kopia did not match files with the pattern /something.home.

If too complex to create exclusions maybe set --one-file-system policy. It will skip all mounts.

1 Like

Multiple problems with this:

  • This is a non-solution, even if it would work. It does not solve the underlying problem. I encourage you to try to replicate my directory structure and check if it works on your machine, if you are unsure what the problem is and are interested enough to help.
  • The other issue is that homed home directories are loopback devices. This means that they are still on the same filesystem, but just looped to a file.
  • It would not be a general solution. What if I have a similar structure, but not for homed stuff? I am still stuck.

If you think this is a bug, I can open a GH issue.

I do not think there is any bug in exclusion logic. It is just a bit tricky to get it right first time. I have no time now to replicate your issue in details.

kopia just follows your instructions - what you ask for is to ignore all but /*.home and then to ignore all /* - so correctly nothing is backed up.

Try it other way around - first exclude all and then reverse it for specific items.

1 Like

I see, I did not know that order matters. When using kopia policy set --add-ignore=..., in which order does it save it? Is there a way to manually edit this policy?

Use kopiaUI

if no success please post your /home structure - not description but something like $ tree /home or similar with key elements and what is your expectation in terms of applied rule results (in similar format).

I will then try to replicate it and create required rule in the next few days - sorry but do not have right device now (ipad is not good for that).

I can’t use KopiaUI, because the user is a headless one (either root, or a specific service user), not a human-user. Also, I would like to be able to do this in the cli.
The tree output:

admin@minefpc ~ [2]> tree /home -L 2
├── admin
│ ├── Desktop
│ ├──
│ ├── Documents
│ ├── Downloads
│ ├── go
│ ├── kernel
│ ├── kernel-build
│ ├── kopia-config.txt
│ ├── Music
│ ├── pacman-hooks → /etc/pacman.d/hooks
│ ├── Pictures
│ ├── Public
│ ├── snap
│ ├── Templates
│ ├── usr-local-bin → /usr/local/bin/
│ └── Videos
├── admin.home
├── gaming.home
├── personal [error opening dir]
└── personal.home

(Kinda offtopic:You can also see here btw. how systemd-homed separates the user dir personal, so no other user, even root would be able to peek in it :smiley: .)
I do not think that the policy order should matter, gitignore doesn’t care about order, so this should not as well AFAIK, am I wrong there?

Also, I tried issuing the commands in both orders:

  1. sudo kopia policy set --add-ignore "/*" /home
  2. sudo kopia policy set --add-ignore "!/*.home" /home
  3. sudo kopia policy set --add-ignore "!/*.home" /home
  4. sudo kopia policy set --add-ignore "/*" /home

In both cases sudo kopia policy show /home produces the same output:

Ignore rules: (defined for this target)

I think it just prints the ignore rules in alphabetical order…
Anyway, thanks for helping and putting up with me. I will stick for the time being to manually specifying folders, but it would be awesome if you as a more experienced Kopia user could figure out what is happening here. Or someone else, I am really out of ideas.

You can connect remotely to the UI

something like this

where did you find that kopia is using .gitignore logic?

I still would like to solve it without involving UI, but thanks for the tip.

Here you are, test data:

$ tree  /Users/kptsky/Temp/test1
├── user1
│   └── test
├── user1.home
├── user2
│   └── test1
└── user2.home

3 directories, 4 files

with ignore patterns:

$ kopia policy show /Users/kptsky/Temp/test1
Files policy:
  Ignore cache directories:          true   inherited from (global)
  Ignore rules:                             (defined for this target)
  Read ignore rules from files:             inherited from (global)
  Scan one filesystem only:         false   inherited from (global)

now backup:

kopia snapshot create /Users/kptsky/Temp/test1


$ kopia ls -l k4b592f2c3555cabd5ea6373f67ced2f3
-rw-r--r--            6 2024-02-24 08:19:42 GMT e54f1cf2ca56a2f26f2351e27dd77bf9   user1.home
-rw-r--r--            7 2024-02-24 08:20:02 GMT b63251c6810df3815fef3e4e5aae1bad   user2.home

for ignore patterns


as expected snapshot does not contain any data as all is excluded.

Maybe kopia policy set --add-ignore limitation… maybe not documented clearly… so do not use it.


kopia policy edit /home

and arrange order manually:

  # Which files to include in snapshots. Options include:
  #   "ignore": ["*.ext", "*.ext2"]
  #   "ignoreDotFiles": [".gitignore", ".kopiaignore"]
  #   "maxFileSize": number
  #   "noParentDotFiles": true
  #   "noParentIgnore": true
  #   "oneFileSystem": false
  "files": {
    "ignore": [
  "errorHandling": {},

Negation pattern is a bit different - from man gitignore page:

An optional prefix “!” which negates the pattern; any matching file excluded by a previous pattern will become included again.

The word “previous” clearly implies order…


Thanks so much!
It is partly me to blame, because I did not know there is kopia policy edit and I clearly skipped over the part explaining the order’s importance.
It seems like this worthy a GH issue, because if kopia policy set --add-ignore does not care about the order the command is issued or there is no parameter the define the priority, it makes it impossible to create some policies with it. There is also no indication of it in the manual. I will create one.

1 Like

Not really. I was for a moment confused too. Especially that I use UI for many things - and then it works out of the box.

This is the right attitude. And only way to make documentation better.

1 Like

@kapitainsky it also looks like this created an unexpected bug(?) as well:

I am also snapshotting the real root directory of the system, separately from snapshotting the /home directory of the system.
In the ignore there is /home/*. This added the global /home directory to the snapshot, but not the files.
Now, after applying the policy we discussed to snapshotting /home the /home directory’s files are redundantly added to the root’s (so /'s) snapshot, unless I specify /home for the real root’s ignore.
Any idea why is this? This results in no /home directory being created for the system’s root. This is easily solvable when restoring by manually adding the /home directory, but this is incorrect…

Unfortunately no idea:) Not sure if it is by design or by mistake. I do not understand really how rules interact in such situations. I have noticed it myself and as a result I just backup one path only (e.g. /) and use one set of rules to control it.

It would require kopia creator to document it in more details. Or somebody to try to understand logic from the source code.

You could try to use .kopiaignore files maybe instead?

I see, I will file a bug for this as well.