# How to specify destination repository in the "snapshot create" command for consistent results? (and auto-create the repo if it doesn't exist)

**URL:** <https://kopia.discourse.group/t/how-to-specify-destination-repository-in-the-snapshot-create-command-for-consistent-results-and-auto-create-the-repo-if-it-doesnt-exist/180>\
**Category:** Support\
**Created:** [October 13, 2020, 3:13am UTC](https://kopia.discourse.group/t/how-to-specify-destination-repository-in-the-snapshot-create-command-for-consistent-results-and-auto-create-the-repo-if-it-doesnt-exist/180 "2020-10-13T03:13:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cups](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Cups](https://kopia.discourse.group/u/Cups)\
**Post date:** [October 13, 2020, 3:13am UTC](https://kopia.discourse.group/t/how-to-specify-destination-repository-in-the-snapshot-create-command-for-consistent-results-and-auto-create-the-repo-if-it-doesnt-exist/180/1 "2020-10-13T03:13:38Z")

</div>

I’m trying to generate `.bat` batch files (for Windows) and `.sh` shell scripts (for Linux) to perform automated backups.

Is there a `kopia snapshot create` command where I can actually specify the destination repo? i.e. Without it being reliant on whatever commands may or may not have been run before it? (and whether those previous commands succeeded or failed)

I’m concerned about race conditions and other issues in the case where the source servers have multiple repos they connect to, and it also just makes scripting a lot more complicated needing to to deal with this “modal” nature of running separate commands to “connect” to one repo at a time, and then actually do backups to which ever is the “current” repo is. Or maybe I’ve misunderstood how Kopia works?

Ideally I’m also looking for a command that can first check if the repo exists first, and auto-create it if it doesn’t. Is this possible?

I’d love a simple one-liner that gives consistent results like:

```auto
kopia snapshot create --auto-create-repo --repo="b2:bucketname/prefixpath/" /home/my-stuff-to-backup

```

This would greatly simplify the usage of Kopia without needing to write complicate scripts for this common use case.

Or could this somehow be done with environment variables? Are they documented somewhere?

Sorry if I’ve missed something! I’ve been trying to figure this out today and yesterday, but haven’t been able to figure out if it’s possible at all.

---

<div class="post-metadata">

**Author:** ![jkowalski](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/jkowalski/32/3_2.png) [@jkowalski](https://kopia.discourse.group/u/jkowalski)\
**Post date:** [October 13, 2020, 4:32am UTC](https://kopia.discourse.group/t/how-to-specify-destination-repository-in-the-snapshot-create-command-for-consistent-results-and-auto-create-the-repo-if-it-doesnt-exist/180/2 "2020-10-13T04:32:36Z")

</div>

Kopia parameters are all derived from a configuration file which is created when you do `repo connect`. If you want to avoid connecting (or have multiple connected repositories) you can specify config file yourself.

Basically you can create the config once (by repo create/repo connect) and bundle it together with your script using `--config-file ~/my.config` to point at it. The last thing you need to to do is passing the password which by default is not stored in the config but in OS-specific keychain. You can either always pass it using `KOPIA_PASSWORD` environment variable, alternatively you can persist it in a file:

For example:

`kopia repo create filesystem --config-file ~/myconfig --path /tmp/foo --no-use-keychain`

This wii create `~/myconfig` and `~/myconfig.kopia-password` which you can bundle together with your scripts.

Hope it helps.

---

<div class="post-metadata">

**Author:** ![Cups](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Cups](https://kopia.discourse.group/u/Cups)\
**Post date:** [October 13, 2020, 5:22am UTC](https://kopia.discourse.group/t/how-to-specify-destination-repository-in-the-snapshot-create-command-for-consistent-results-and-auto-create-the-repo-if-it-doesnt-exist/180/3 "2020-10-13T05:22:10Z")

</div>

Cheers, thanks for your help on this!

Really loving Kopia! Especially the fact that mounting even works on Windows!

A couple of follow up questions:

1. Any thoughts on the `--auto-create-repo` thing? Is it something you’d consider adding in the future? It would be amazing to just be able to deploy a single idempotent command out to my servers so that they can auto-create repos in a simple way. (password for the new repo can just be taken from the same `KOPIA_PASSWORD` environment variable)
2. Does Kopia have any environment variables other than `KOPIA_PASSWORD` ? Any doco anywhere on them?

Thanks once again!

---

<div class="post-metadata">

**Author:** ![mattzab](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/mattzab/32/276_2.png) [@mattzab](https://kopia.discourse.group/u/mattzab)\
**Post date:** [May 14, 2022, 10:11pm UTC](https://kopia.discourse.group/t/how-to-specify-destination-repository-in-the-snapshot-create-command-for-consistent-results-and-auto-create-the-repo-if-it-doesnt-exist/180/4 "2022-05-14T22:11:18Z")

</div>

Is `--no-use-keychain` deprecated?

It doesn’t work on

```auto
kopia --version
0.10.7-1 build: unofficial from: ARCH_USER_REPOSITORY
```
