How to include only some files from folder?

It’s comfortable to have home user directory as one snapshot.
But there are a lot of directories don’t need to be stored, but need to be stored partial.

For example, I have some git repositories — I don’t need to include git files and workfiles from git bases, but need some files and directories from that, placed inside.

Same for snap or flatpak packed apps: I want to exclude from snapshot upper level directory, but want to include some files and subtrees inside excluded directory.

How can I do it with Kopia?

Something like gitignore does, for example:

/* (exclude all)
!/Steam (but include Steam)
/Steam/* (but exclude Steam)
!/Steam/userdata (but include Steam/userdata only)

etc.

https://git-scm.com/docs/gitignore

And where I can write it, and what syntax should be?

Rules are set in KopiaUI, Policy/Files. Syntax is the same as gitignore site shows.

E.g My example was taken from my backup literally (minus comments in the bracket of course). Best way to test, is a set a few rules and use “Estimate” button, to see outcome.

Thank you.
now I trying to exclude all internal git stuff, but backup one file armbian/.git/config and folder userpatches.

  • git stuff excluded
  • userpatches directory included
    gitconfig not included
!armbian/.git/config
armbian/*
!armbian/userpatches

is it possible to do what I want?
for a while seems not…

same as to include /.var/app/com.nextcloud.desktopclient.nextcloud/config/Nextcloud/nextcloud.cfg, but exclude other /.var.

Something like this should work:

/*
!/armbian/
/armbian/*
!/armbian/userpatches
!/armbian/.git/
/armbian/.git/*
!/armbian/.git/config

and this should include only “!” /.var

/*
!/.var/app/com.nextcloud.desktopclient.nextcloud/config/Nextcloud/nextcloud.cfg

You can also include only .cfg files:

*
!**/
!*.cfg

… but this filter produces empty directories, for some reason.

tthis

/*
!/.var/app/com.nextcloud.desktopclient.nextcloud/config/Nextcloud/nextcloud.cfg

produces empty snapshot.
this

/*
!/armbian/
/armbian/*
!/armbian/userpatches
!/armbian/.git/
/armbian/.git/*
!/armbian/.git/config

work as I need: I got in snapshot file armbian/.git/config and armbian/userpatches folder with content.

Then, the border is more than one folder deep for exclusion:
if path is “a/b/c”, then it’s possible to exclude “a” but get back “b/c”. but impossible to exclude complete “a” but include “a/b/c”.

Hm, this filter should work. Kopia filters are case sensitive (even in the Windows) so if there are upper/lower cases in the path… filter should reflect that.

You can exclude or include any directory form given tree, but this may required more careful unrolling filter rules. So, sometime it is simpler to just add single directories, one by one, to the repository. Maybe not so elegant, but works.

It shouldn’t, because of https://git-scm.com/docs/gitignore:

An optional prefix “!” which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

Why, why .gitignore syntax there??! It was not designed for a backup set definition use.
Duplicati have much better format for source set.

Hm, yup, it doesn’t work, you are right. But this does work (if you don’t mind bunch of empty dirs…)

*
!**/
!/.var/app/com.nextcloud.desktopclient.nextcloud/config/Nextcloud/*.cfg

Also, you can always use .kopiaignore file for fine-tune your filters. I’m also using Duplicati, Kopia just “requires” different thinking about your backup “architecture”, because Kopia filters are exclude (ignore) ones (for now anyway).