# How to include only some files from folder?

**URL:** <https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946>\
**Category:** General Topics\
**Created:** [April 11, 2023, 11:09am UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946 "2023-04-11T11:09:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![iav](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/iav/32/662_2.png) [@iav](https://kopia.discourse.group/u/iav)\
**Post date:** [April 11, 2023, 11:09am UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/1 "2023-04-11T11:09:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ZebCorp](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@ZebCorp](https://kopia.discourse.group/u/ZebCorp)\
**Post date:** [April 11, 2023, 11:53am UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/2 "2023-04-11T11:53:09Z")

</div>

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](https://git-scm.com/docs/gitignore)

---

<div class="post-metadata">

**Author:** ![iav](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/iav/32/662_2.png) [@iav](https://kopia.discourse.group/u/iav)\
**Post date:** [April 11, 2023, 3:12pm UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/3 "2023-04-11T15:12:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ZebCorp](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@ZebCorp](https://kopia.discourse.group/u/ZebCorp)\
**Post date:** [April 11, 2023, 4:32pm UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/4 "2023-04-11T16:32:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iav](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/iav/32/662_2.png) [@iav](https://kopia.discourse.group/u/iav)\
**Post date:** [April 12, 2023, 2:20pm UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/5 "2023-04-12T14:20:03Z")

</div>

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

```auto
!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`.

---

<div class="post-metadata">

**Author:** ![ZebCorp](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@ZebCorp](https://kopia.discourse.group/u/ZebCorp)\
**Post date:** [April 12, 2023, 4:03pm UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/6 "2023-04-12T16:03:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iav](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/iav/32/662_2.png) [@iav](https://kopia.discourse.group/u/iav)\
**Post date:** [April 13, 2023, 3:44pm UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/7 "2023-04-13T15:44:06Z")

</div>

tthis

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

```

produces empty snapshot.  
this

```auto
/*
!/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”.

---

<div class="post-metadata">

**Author:** ![ZebCorp](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@ZebCorp](https://kopia.discourse.group/u/ZebCorp)\
**Post date:** [April 13, 2023, 9:25pm UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/8 "2023-04-13T21:25:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iav](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/iav/32/662_2.png) [@iav](https://kopia.discourse.group/u/iav)\
**Post date:** [April 13, 2023, 10:59pm UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/9 "2023-04-13T22:59:32Z")

</div>

It shouldn’t, because of [https://git-scm.com/docs/gitignore](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.

---

<div class="post-metadata">

**Author:** ![ZebCorp](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@ZebCorp](https://kopia.discourse.group/u/ZebCorp)\
**Post date:** [April 14, 2023, 9:07am UTC](https://kopia.discourse.group/t/how-to-include-only-some-files-from-folder/1946/10 "2023-04-14T09:07:26Z")

</div>

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).
