[CLI] - Restore a single file

Hi all, I’ve been having trouble restoring a single file using Kopia for a couple of hours now.

Basically when I do:
kopia restore object-path/Contacts/

Kopia restores all the files contained in Contacts by creating the folder object-path/Contacts/ and here are all the restored files.

But if I try to restore only one file, for example test.zip:

kopia restore object-path/Contacts/test.zip

I get the error:
unable to initialize output: unable to create output file: open object-path/Contacts/test.zip: no such file or directory

Then I tried to specify a folder where to restore the file:

kopia restore object-path/Contacts/test.zip /myFolder

But i get:
ERROR error restoring: restore error: error copying: copy file: error creating file: open /myFolder: read-only file system

Surely there is something I am wrong but trying with the GUI I can download all single files where I want without any problem, while with the CLI I can only download the folders with all the files but not a specific file.

Some notes that may be helpful:

  • MacOS Ventura 13.4 (22F66) system
  • I tried to create by myself the folder where to restore the file and also to set all the permissions with chmod
  • Kopia version 0.13.0

you can kopia mount then copy one file

or pure CLI way:

kopia ls -l <snapshotID>/path/to/fileFolder
<fileID> myFile.txt
kopia snapshot restore <fileID> /path/where/to/restore/myRestoredFile.txt

It would be nice if documentation is more clear about it - but somebody has to update it:)

Thanks for the rapid response but apparently I believe it’s a software problem.

The command you gave me works perfectly:

  • On snapshot where I choose to restore a folder with all files
  • On single files that are not .zip

I didn’t think about it until I realized that all the files I tried to download individually are all .zip.

So I decided to uninstall everything, CLI and GUI, clean the paths from any leftover files, deleted the bucket and all the files.

I start from scratch.

This time I create a single snapshot composed of one folder with various files: image, audio, various text files and a .zip.

Kopia allows me to download all the files individually without problems while the .zip is downloaded but the size is almost zero (from a 5mb .zip to a 1mb .zip is downloaded).

In addition to this problem all files with IDs starting with I cannot be downloaded individually. However, I found an open issue on GitHub that has just been commented.

Buy the problem of individually downloaded .zip files remains

seems like one the many other issues - well… everybody can decide what to do

Try using kopia restore <fileID> /path/to/restore.zip --mode=local
Basically whats happening here is that the default auto restore mode sees the .zip file extension on the destination and is assuming (incorrectly) that you want to compress the restored files into a .zip file. This would usually be used to restore an entire directory in a tidy way by outputting a .zip with the contents of that directory. Passing --mode=local will override this and restore the file as normal.

I had to look at the source code to figure this out as it’s not documented behavior. It will also do the same thing with a .tar, .tar.gz extension given as the destination.

2 Likes

Thanks, it works perfectly! :yellow_heart: