I’ve been thinking about expanding the snapshot creation feature (both CLI and Snapshot).
There are couple important scenarios I’d like to factor in, ideally without breaking the CLI.
Snapshot of data piped through stdin (single file)
This was requested by several folks here and on GitHub. I’m thinking something like:
mysqldump .... | kopia snapshot create --stdin-file=/some/virtual/path
Kopia would upload output of mysqldump and record snapshot manifest as if it came from file /some/virtual/path
.
Snapshot from data piped through stdin (directory in a TAR format)
This is similar to #1 by the input contains a TAR-formatted directory stream:
tar cf something/ | kopia snapshot create --stdin-tar=/some/path
This would save the (directory) manifest as /some/path
.
Problems with standard input
There however is a problem with stdin. When we run kopia snapshot create --all
Kopia can’t really snapshot /some/path
in the example above because it was virtual to begin with, and we need to re-run the original command but Kopia never had knowledge of it.
We can either:
a) put special marker on stdin-sourced snapshots and ignore them when --all
is passed.
b) remember the command that produced data to snapshot and run it ourselves
If kopia were to launch extra commands before/after snapshotting, it would open up a lot of interesting new cases, including:
- creating FS-specific consistent snapshots (e.g. ZFS) and unmounting them at the end of snapshots.
- launching external backup tools (mysqldump)
- custom notifications scripts
I have 2 questions:
-
Is this a good idea to allow Kopia to launch external commands or should we rely on outside scripting for that?
-
How do we specify the commands to run? I’m thinking using policies, where you can attach scripts to each file/directory that run before/after the file/directory is snapshotted or to provide content:
The before
script would be able to:
a) provide data (mysqldump
or tar
) to upload by writing it to stdout
b) provide alternative location of data (file or directory), so the script can take a snapshot and mount it somewhere and redirect Kopia to read from the mounted dir.
c) do something unrelated (send notifications, etc.)
There will be corresponding after
script that can clean up after before
.
For example:
kopia policy set /sqldump --data-provider-command "mysqldump ..."
kopia snapshot create /sqldump
kopia policy set /some/dir \
--before-command "zfs snapshot ... && zfs mount && echo REDIRECT /new/dir" \
--after-command "zfs unmount ..."
kopia snapshot create /some/dir
There’s obviously a ton of more details to figure out, but I’d love to hear your reaction and any more suggestions.