Share and sync files with zrok drives
The zrok drives CLI tools allow for simple, ergonomic management and synchronization of local and remote files.
Share a drive
Virtual drives are shared using the --backend-mode drive flag with either the public or private sharing mode.
-
Create a local directory to share:
mkdir /tmp/junk -
Share it as a private drive:
zrok2 share private --headless --backend-mode drive /tmp/junkThis creates an ephemeral private drive share pointed at
/tmp/junk. The share token (wkcfb58vj51lin this example) identifies the virtual drive in subsequent operations.
Work with a private drive share
Copy files into your private drive, organize them into directories, and remove them when done.
-
Copy a file into the virtual drive:
zrok2 copy LICENSE zrok://wkcfb58vj51lUse
zrok://<shareToken>URLs with the drives CLI to refer to the private virtual drive allocated withzrok2 share private. -
List the contents of the virtual drive:
zrok2 ls zrok://wkcfb58vj51l -
Create a directory on the virtual drive:
zrok2 mkdir zrok://wkcfb58vj51l/stuff -
Copy a local directory into the new directory:
zrok2 copy util/ zrok://wkcfb58vj51l/stuff -
Remove files and directories from the virtual drive:
zrok2 rm zrok://wkcfb58vj51l/LICENSE
zrok2 rm zrok://wkcfb58vj51l/stuff
Work with public shares
Public shares work the same way as private shares, but use an HTTPS URL instead of a zrok:// URL. Share a
directory as a public drive, then use the same drives CLI commands with the public HTTPS URL.
Share a directory as a public drive:
zrok2 share public --headless --backend-mode drive /tmp/junk
The same commands from the previous section work with the HTTPS URL:
-
Copy files:
zrok2 copy util/ https://6kiww4bn7iok.share.zrok.io -
List contents:
zrok2 ls https://6kiww4bn7iok.share.zrok.io
For basic authentication on public shares, the drives CLI offers the --basic-auth flag, which accepts a
<username>:<password> parameter. Alternatively, set the ZROK2_DRIVES_BASIC_AUTH environment variable:
export ZROK2_DRIVES_BASIC_AUTH=username:password
One-way synchronization
The --sync flag on zrok2 copy skips files that haven't changed, comparing modification timestamp and size. This
provides a convenience mechanism for resuming interrupted copies of large file trees and gives a reasonable guarantee
that the trees are in sync.
On the first run against an empty drive, --sync copies the entire contents:
zrok2 copy --sync docs/ https://glmv049c62p7.share.zrok.io
Running the same command again does nothing, because it's already in sync:
zrok2 copy --sync docs/ https://glmv049c62p7.share.zrok.io
If a directory is removed from the drive and you re-sync, --sync detects the missing files and copies them back:
zrok2 rm https://glmv049c62p7.share.zrok.io/images
zrok2 copy --sync docs/ https://glmv049c62p7.share.zrok.io
Drive-to-drive copies and synchronization
zrok2 copy can operate on pairs of virtual drives without storing files locally.
Specifying the same URL for both source and target of a --sync operation always results in nothing being
copied, because they're the same drive with the same state:
zrok2 copy --sync https://glmv049c62p7.share.zrok.io https://glmv049c62p7.share.zrok.io
You can copy files between two different virtual drives with a single command:
zrok2 copy --sync https://glmv049c62p7.share.zrok.io zrok://hsml272j3xzf
Running the same command again does nothing, because they're now in sync:
zrok2 copy --sync https://glmv049c62p7.share.zrok.io zrok://hsml272j3xzf
Copy from drives to the local filesystem
zrok2 copy always assumes the destination is a directory. There's no way to copy a file directly to a differently
named file. So, when using zrok2 copy, always take note of the destination:
zrok2 copy somefile someotherfile
The result on the local filesystem would be:
somefile
someotherfile/somefile
Copy without specifying a destination
zrok2 copy defaults the destination to file://. (the current directory), so you can omit the destination.
-
Check what's in the drive:
zrok2 ls https://azc47r3cwjds.share.zrok.io -
Copy a file without specifying a destination:
zrok2 copy https://azc47r3cwjds.share.zrok.io/LICENSE -
Verify the file landed in the current directory:
ls -l
Copy to a specific local folder
-
Copy a file to a local directory:
zrok2 copy https://azc47r3cwjds.share.zrok.io/LICENSE /tmp/inbox -
Verify the file landed in the destination:
ls -l /tmp/inbox
Use unique names and reserved shares
Reserved private shares with unique names are particularly convenient with the drives CLI, since you can use a human-readable name instead of a share token.
-
Share the directory with a unique name:
zrok2 share private -b drive --share-token mydrive /tmp/junk -
Use the human-readable name in any
zrok://URL instead of the generated share token:zrok2 ls zrok://mydrive