How to use repository create from-config

Hi there,

I have a config file like this:

{
  "storage": {
    "type": "s3",
    "config": {
      "bucket": "mybucket",
      "endpoint": "s3.amazonaws.com",
      "accessKeyID": "AKIxyxyxyx",
      "secretAccessKey": "keykeykey",
      "sessionToken": "",
      "region": "ap-southeast-2"
    }
  },
  "caching": {
    "cacheDirectory": "E:\\kopia\\jobs\\mgmt\\cache",
    "maxCacheSize": 5242880000,
    "maxMetadataCacheSize": 5242880000,
    "maxListCacheDuration": 30
  },
  "hostname": "mgmt01",
  "username": "iac",
  "description": "Repository in S3: xyxyxyx",
  "enableActions": false,
  "formatBlobCacheDuration": 900000000000
}

I thought I should be able to do something like:

kopia repository create from-config --config-file=“.\config\repository_mgmt.config” -p repopwd’

But it complains about token:
ERROR can't connect to storage: one of --token-file, --token-stdin or --token must be provided
I’m not sure what the --token or --token-file option is for. Does this relate to the repo password?

I did try pointing the --token-file to config\repository_mgmt.config.kopia-password which contains the bas64 encoded repo password. but no go.

It seems to me that between the config file and provided repo password I have everything required to create a repo but I’m clearly doing something wrong.

The use case here is that I’m generating kopia packages using Ansible. I.e. the config file is being built from a template.

Any guidance would be much apricated.

Cheers.
Rhys

Did you find a solution? I am trying to do same thing but with connecting a repository. This page does not tell how it is done and no help is found arond the web

No, I haven’t unfortunately. I’ve worked around it by writing out the repository.config to its target location then my python deployment script reads the file with json load and builds a “create repo” command which then writes back to the same config file.

The doco could use some improvement. I’ve really no idea what --token or --token-file mean.

Ngā mihi
Rhys

I actually found a solution finally, brought to you by bing chat :frowning:

Basically " --config-file" is wrong in this context.

kopia.exe repository connect from-config --file=CONFIG-FILE

In my case the repo doesn’t exist. Will the above create it?

Take a look at this, Getting Started Guide | Kopia

Maybe you need to pass the kopia password in the terminal, then create the repo and use the lines I used to connect and create additional snapshots on the command line using a config.

Yes, that’s what I’m doing, but in the documentation, there is a repository create from-config command as per this link:
repository create from-config | Kopia

And I would have thought this would allow creating the repo from a config file. Afterall, the config file contains all the required info to do so but I can’t get it to work. Or am I misunderstanding what the command is for?

That was the intention of my post try --file instead of --config-file

Thanks Wayland. I’m 99% sure I have dried --file and a whole range of variations but I think the main hang up was the token options which are required. I thought token-file might be the base64 encoded version of the repo password, but suspect I’m way off.

That was what I was trying to get at, the connect option (which was what I needed) seemed to require a token with --config-file until I discarded that and used the --file option, then it stopped complaining about token related stuff and relied only on the actual config file.

Searching the documentation for “token”, the second hit is this: Command Line | Kopia (Quick Reconnection To Repository), which shows where to find the token in the output of the kopia repo status -t command.

If you want to extract the token programmatically, you can use: kopia repository status -t -s | grep token | head -1 | awk '{print $7}'

Hope this helps!