2018-08-26 15:17:15 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-02-01 21:44:51 +01:00
|
|
|
"log/syslog"
|
2018-08-26 16:44:34 +02:00
|
|
|
"os"
|
|
|
|
"time"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2022-04-12 01:26:41 +02:00
|
|
|
"github.com/robfig/cron/v3"
|
2019-03-22 19:41:12 +01:00
|
|
|
"github.com/zrepl/yaml-config"
|
2020-09-07 01:20:57 +02:00
|
|
|
|
2021-07-09 16:30:44 +02:00
|
|
|
"github.com/zrepl/zrepl/util/datasizeunit"
|
2020-09-07 01:20:57 +02:00
|
|
|
zfsprop "github.com/zrepl/zrepl/zfs/property"
|
2018-08-26 15:17:15 +02:00
|
|
|
)
|
|
|
|
|
2022-03-30 04:39:10 +02:00
|
|
|
type ParseFlags uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
ParseFlagsNone ParseFlags = 0
|
|
|
|
ParseFlagsNoCertCheck ParseFlags = 1 << iota
|
|
|
|
)
|
|
|
|
|
2018-08-26 16:44:34 +02:00
|
|
|
type Config struct {
|
2024-05-14 19:18:22 +02:00
|
|
|
Jobs []JobEnum `yaml:"jobs,optional"`
|
2018-08-31 21:51:44 +02:00
|
|
|
Global *Global `yaml:"global,optional,fromdefaults"`
|
2018-08-26 16:44:34 +02:00
|
|
|
}
|
|
|
|
|
2018-10-13 15:53:52 +02:00
|
|
|
func (c *Config) Job(name string) (*JobEnum, error) {
|
|
|
|
for _, j := range c.Jobs {
|
|
|
|
if j.Name() == name {
|
|
|
|
return &j, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("job %q not defined in config", name)
|
|
|
|
}
|
|
|
|
|
2018-08-26 16:44:34 +02:00
|
|
|
type JobEnum struct {
|
2018-08-26 15:17:15 +02:00
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
2018-10-13 15:53:52 +02:00
|
|
|
func (j JobEnum) Name() string {
|
|
|
|
var name string
|
|
|
|
switch v := j.Ret.(type) {
|
2019-03-22 19:41:12 +01:00
|
|
|
case *SnapJob:
|
|
|
|
name = v.Name
|
|
|
|
case *PushJob:
|
|
|
|
name = v.Name
|
|
|
|
case *SinkJob:
|
|
|
|
name = v.Name
|
|
|
|
case *PullJob:
|
|
|
|
name = v.Name
|
|
|
|
case *SourceJob:
|
|
|
|
name = v.Name
|
2018-10-13 15:53:52 +02:00
|
|
|
default:
|
2019-02-01 21:44:51 +01:00
|
|
|
panic(fmt.Sprintf("unknown job type %T", v))
|
2018-10-13 15:53:52 +02:00
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2018-09-23 23:04:31 +02:00
|
|
|
type ActiveJob struct {
|
2022-05-01 14:46:38 +02:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
Connect ConnectEnum `yaml:"connect"`
|
|
|
|
Pruning PruningSenderReceiver `yaml:"pruning"`
|
|
|
|
Replication *Replication `yaml:"replication,optional,fromdefaults"`
|
|
|
|
ConflictResolution *ConflictResolution `yaml:"conflict_resolution,optional,fromdefaults"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConflictResolution struct {
|
|
|
|
InitialReplication string `yaml:"initial_replication,optional,default=most_recent"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 23:04:31 +02:00
|
|
|
type PassiveJob struct {
|
2022-12-22 17:59:41 +01:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
Serve ServeEnum `yaml:"serve"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-11-20 19:30:15 +01:00
|
|
|
type SnapJob struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
Pruning PruningLocal `yaml:"pruning"`
|
|
|
|
Snapshotting SnapshottingEnum `yaml:"snapshotting"`
|
|
|
|
Filesystems FilesystemsFilter `yaml:"filesystems"`
|
2018-11-20 19:30:15 +01:00
|
|
|
}
|
|
|
|
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
type SendOptions struct {
|
2020-09-07 01:20:57 +02:00
|
|
|
Encrypted bool `yaml:"encrypted,optional,default=false"`
|
|
|
|
Raw bool `yaml:"raw,optional,default=false"`
|
|
|
|
SendProperties bool `yaml:"send_properties,optional,default=false"`
|
|
|
|
BackupProperties bool `yaml:"backup_properties,optional,default=false"`
|
|
|
|
LargeBlocks bool `yaml:"large_blocks,optional,default=false"`
|
|
|
|
Compressed bool `yaml:"compressed,optional,default=false"`
|
2021-11-10 18:49:10 +01:00
|
|
|
EmbeddedData bool `yaml:"embedded_data,optional,default=false"`
|
2020-09-07 01:20:57 +02:00
|
|
|
Saved bool `yaml:"saved,optional,default=false"`
|
2021-07-09 16:30:44 +02:00
|
|
|
|
|
|
|
BandwidthLimit *BandwidthLimit `yaml:"bandwidth_limit,optional,fromdefaults"`
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type RecvOptions struct {
|
|
|
|
// Note: we cannot enforce encrypted recv as the ZFS cli doesn't provide a mechanism for it
|
|
|
|
// Encrypted bool `yaml:"may_encrypted"`
|
|
|
|
// Future:
|
|
|
|
// Reencrypt bool `yaml:"reencrypt"`
|
2020-09-07 01:20:57 +02:00
|
|
|
|
|
|
|
Properties *PropertyRecvOptions `yaml:"properties,fromdefaults"`
|
2021-07-09 16:30:44 +02:00
|
|
|
|
|
|
|
BandwidthLimit *BandwidthLimit `yaml:"bandwidth_limit,optional,fromdefaults"`
|
2021-11-21 21:16:37 +01:00
|
|
|
|
|
|
|
Placeholder *PlaceholderRecvOptions `yaml:"placeholder,fromdefaults"`
|
2021-07-09 16:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ yaml.Unmarshaler = &datasizeunit.Bits{}
|
|
|
|
|
|
|
|
type BandwidthLimit struct {
|
|
|
|
Max datasizeunit.Bits `yaml:"max,default=-1 B"`
|
|
|
|
BucketCapacity datasizeunit.Bits `yaml:"bucket_capacity,default=128 KiB"`
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
}
|
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
type Replication struct {
|
2021-02-28 23:33:28 +01:00
|
|
|
Protection *ReplicationOptionsProtection `yaml:"protection,optional,fromdefaults"`
|
|
|
|
Concurrency *ReplicationOptionsConcurrency `yaml:"concurrency,optional,fromdefaults"`
|
2020-06-27 23:53:33 +02:00
|
|
|
}
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
type ReplicationOptionsProtection struct {
|
|
|
|
Initial string `yaml:"initial,optional,default=guarantee_resumability"`
|
|
|
|
Incremental string `yaml:"incremental,optional,default=guarantee_resumability"`
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 23:33:28 +01:00
|
|
|
type ReplicationOptionsConcurrency struct {
|
|
|
|
Steps int `yaml:"steps,optional,default=1"`
|
|
|
|
SizeEstimates int `yaml:"size_estimates,optional,default=4"`
|
|
|
|
}
|
|
|
|
|
2020-09-07 01:20:57 +02:00
|
|
|
type PropertyRecvOptions struct {
|
|
|
|
Inherit []zfsprop.Property `yaml:"inherit,optional"`
|
|
|
|
Override map[zfsprop.Property]string `yaml:"override,optional"`
|
|
|
|
}
|
|
|
|
|
2021-11-21 21:16:37 +01:00
|
|
|
type PlaceholderRecvOptions struct {
|
|
|
|
Encryption string `yaml:"encryption,default=unspecified"`
|
|
|
|
}
|
|
|
|
|
2018-09-23 23:04:31 +02:00
|
|
|
type PushJob struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
ActiveJob `yaml:",inline"`
|
|
|
|
Snapshotting SnapshottingEnum `yaml:"snapshotting"`
|
|
|
|
Filesystems FilesystemsFilter `yaml:"filesystems"`
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
Send *SendOptions `yaml:"send,fromdefaults,optional"`
|
2018-09-23 23:04:31 +02:00
|
|
|
}
|
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
func (j *PushJob) GetFilesystems() FilesystemsFilter { return j.Filesystems }
|
|
|
|
func (j *PushJob) GetSendOptions() *SendOptions { return j.Send }
|
|
|
|
|
2018-08-26 23:11:50 +02:00
|
|
|
type PullJob struct {
|
2018-09-23 23:04:31 +02:00
|
|
|
ActiveJob `yaml:",inline"`
|
2019-03-22 19:41:12 +01:00
|
|
|
RootFS string `yaml:"root_fs"`
|
2019-03-16 14:24:05 +01:00
|
|
|
Interval PositiveDurationOrManual `yaml:"interval"`
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
Recv *RecvOptions `yaml:"recv,fromdefaults,optional"`
|
2019-03-16 14:24:05 +01:00
|
|
|
}
|
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
func (j *PullJob) GetRootFS() string { return j.RootFS }
|
|
|
|
func (j *PullJob) GetAppendClientIdentity() bool { return false }
|
|
|
|
func (j *PullJob) GetRecvOptions() *RecvOptions { return j.Recv }
|
|
|
|
|
2019-03-16 14:24:05 +01:00
|
|
|
type PositiveDurationOrManual struct {
|
|
|
|
Interval time.Duration
|
|
|
|
Manual bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ yaml.Unmarshaler = (*PositiveDurationOrManual)(nil)
|
|
|
|
|
|
|
|
func (i *PositiveDurationOrManual) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
var s string
|
|
|
|
if err := u(&s, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch s {
|
|
|
|
case "manual":
|
|
|
|
i.Manual = true
|
|
|
|
i.Interval = 0
|
|
|
|
case "":
|
|
|
|
return fmt.Errorf("value must not be empty")
|
|
|
|
default:
|
|
|
|
i.Manual = false
|
2022-10-09 15:27:17 +02:00
|
|
|
i.Interval, err = parsePositiveDuration(s)
|
2019-03-16 14:24:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2018-09-23 23:04:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SinkJob struct {
|
|
|
|
PassiveJob `yaml:",inline"`
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
RootFS string `yaml:"root_fs"`
|
|
|
|
Recv *RecvOptions `yaml:"recv,optional,fromdefaults"`
|
2018-08-26 23:11:50 +02:00
|
|
|
}
|
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
func (j *SinkJob) GetRootFS() string { return j.RootFS }
|
|
|
|
func (j *SinkJob) GetAppendClientIdentity() bool { return true }
|
|
|
|
func (j *SinkJob) GetRecvOptions() *RecvOptions { return j.Recv }
|
|
|
|
|
2018-08-26 23:11:50 +02:00
|
|
|
type SourceJob struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
PassiveJob `yaml:",inline"`
|
|
|
|
Snapshotting SnapshottingEnum `yaml:"snapshotting"`
|
|
|
|
Filesystems FilesystemsFilter `yaml:"filesystems"`
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
Send *SendOptions `yaml:"send,optional,fromdefaults"`
|
2018-08-26 23:11:50 +02:00
|
|
|
}
|
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
func (j *SourceJob) GetFilesystems() FilesystemsFilter { return j.Filesystems }
|
|
|
|
func (j *SourceJob) GetSendOptions() *SendOptions { return j.Send }
|
|
|
|
|
2018-09-04 23:44:45 +02:00
|
|
|
type FilesystemsFilter map[string]bool
|
2018-08-26 23:29:57 +02:00
|
|
|
|
2018-10-11 15:22:52 +02:00
|
|
|
type SnapshottingEnum struct {
|
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type SnapshottingPeriodic struct {
|
2022-10-09 15:27:17 +02:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Prefix string `yaml:"prefix"`
|
|
|
|
Interval *PositiveDuration `yaml:"interval"`
|
|
|
|
Hooks HookList `yaml:"hooks,optional"`
|
|
|
|
TimestampFormat string `yaml:"timestamp_format,optional,default=dense"`
|
2018-10-11 15:22:52 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 01:26:41 +02:00
|
|
|
type CronSpec struct {
|
|
|
|
Schedule cron.Schedule
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ yaml.Unmarshaler = &CronSpec{}
|
|
|
|
|
|
|
|
func (s *CronSpec) UnmarshalYAML(unmarshal func(v interface{}, not_strict bool) error) error {
|
|
|
|
var specString string
|
|
|
|
if err := unmarshal(&specString, false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use standard cron format.
|
|
|
|
// Disable the various "descriptors" (@daily, etc)
|
|
|
|
// They are just aliases to "top of hour", "midnight", etc.
|
|
|
|
parser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.SecondOptional)
|
|
|
|
|
|
|
|
sched, err := parser.Parse(specString)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "cron syntax invalid")
|
|
|
|
}
|
|
|
|
s.Schedule = sched
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type SnapshottingCron struct {
|
2022-10-17 19:02:21 +02:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Prefix string `yaml:"prefix"`
|
|
|
|
Cron CronSpec `yaml:"cron"`
|
|
|
|
Hooks HookList `yaml:"hooks,optional"`
|
|
|
|
TimestampFormat string `yaml:"timestamp_format,optional,default=dense"`
|
2022-04-12 01:26:41 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 15:22:52 +02:00
|
|
|
type SnapshottingManual struct {
|
|
|
|
Type string `yaml:"type"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 23:11:50 +02:00
|
|
|
type PruningSenderReceiver struct {
|
|
|
|
KeepSender []PruningEnum `yaml:"keep_sender"`
|
|
|
|
KeepReceiver []PruningEnum `yaml:"keep_receiver"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PruningLocal struct {
|
|
|
|
Keep []PruningEnum `yaml:"keep"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-31 21:50:59 +02:00
|
|
|
type LoggingOutletEnumList []LoggingOutletEnum
|
|
|
|
|
|
|
|
func (l *LoggingOutletEnumList) SetDefault() {
|
|
|
|
def := `
|
|
|
|
type: "stdout"
|
|
|
|
time: true
|
|
|
|
level: "warn"
|
|
|
|
format: "human"
|
|
|
|
`
|
2018-10-18 15:43:50 +02:00
|
|
|
s := &StdoutLoggingOutlet{}
|
2018-08-31 21:50:59 +02:00
|
|
|
err := yaml.UnmarshalStrict([]byte(def), &s)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
*l = []LoggingOutletEnum{LoggingOutletEnum{Ret: s}}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ yaml.Defaulter = &LoggingOutletEnumList{}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type Global struct {
|
2018-08-31 21:50:59 +02:00
|
|
|
Logging *LoggingOutletEnumList `yaml:"logging,optional,fromdefaults"`
|
2018-08-31 21:51:44 +02:00
|
|
|
Monitoring []MonitoringEnum `yaml:"monitoring,optional"`
|
|
|
|
Control *GlobalControl `yaml:"control,optional,fromdefaults"`
|
|
|
|
Serve *GlobalServe `yaml:"serve,optional,fromdefaults"`
|
2018-08-31 21:50:59 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type ConnectEnum struct {
|
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
2018-08-31 21:51:44 +02:00
|
|
|
type ConnectCommon struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
Type string `yaml:"type"`
|
2018-08-31 21:51:44 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type TCPConnect struct {
|
2018-08-31 21:51:44 +02:00
|
|
|
ConnectCommon `yaml:",inline"`
|
2019-09-28 14:21:05 +02:00
|
|
|
Address string `yaml:"address,hostport"`
|
2018-12-11 21:54:36 +01:00
|
|
|
DialTimeout time.Duration `yaml:"dial_timeout,zeropositive,default=10s"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type TLSConnect struct {
|
2018-08-31 21:51:44 +02:00
|
|
|
ConnectCommon `yaml:",inline"`
|
2019-09-28 14:21:05 +02:00
|
|
|
Address string `yaml:"address,hostport"`
|
2018-08-31 21:51:44 +02:00
|
|
|
Ca string `yaml:"ca"`
|
|
|
|
Cert string `yaml:"cert"`
|
|
|
|
Key string `yaml:"key"`
|
|
|
|
ServerCN string `yaml:"server_cn"`
|
2018-12-11 21:54:36 +01:00
|
|
|
DialTimeout time.Duration `yaml:"dial_timeout,zeropositive,default=10s"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 23:46:59 +02:00
|
|
|
type SSHStdinserverConnect struct {
|
2018-08-31 21:51:44 +02:00
|
|
|
ConnectCommon `yaml:",inline"`
|
2018-08-27 15:18:08 +02:00
|
|
|
Host string `yaml:"host"`
|
|
|
|
User string `yaml:"user"`
|
|
|
|
Port uint16 `yaml:"port"`
|
|
|
|
IdentityFile string `yaml:"identity_file"`
|
|
|
|
TransportOpenCommand []string `yaml:"transport_open_command,optional"` //TODO unused
|
|
|
|
SSHCommand string `yaml:"ssh_command,optional"` //TODO unused
|
2018-09-05 01:41:54 +02:00
|
|
|
Options []string `yaml:"options,optional"`
|
2018-12-11 21:54:36 +01:00
|
|
|
DialTimeout time.Duration `yaml:"dial_timeout,zeropositive,default=10s"`
|
2018-08-26 23:46:59 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 14:43:53 +02:00
|
|
|
type LocalConnect struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
ConnectCommon `yaml:",inline"`
|
2019-09-29 16:58:18 +02:00
|
|
|
ListenerName string `yaml:"listener_name"`
|
|
|
|
ClientIdentity string `yaml:"client_identity"`
|
|
|
|
DialTimeout time.Duration `yaml:"dial_timeout,zeropositive,default=2s"`
|
2018-09-24 14:43:53 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type ServeEnum struct {
|
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
2018-08-31 21:51:44 +02:00
|
|
|
type ServeCommon struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
Type string `yaml:"type"`
|
2018-08-31 21:51:44 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type TCPServe struct {
|
2019-12-30 19:42:17 +01:00
|
|
|
ServeCommon `yaml:",inline"`
|
|
|
|
Listen string `yaml:"listen,hostport"`
|
|
|
|
ListenFreeBind bool `yaml:"listen_freebind,default=false"`
|
|
|
|
Clients map[string]string `yaml:"clients"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type TLSServe struct {
|
2018-08-31 21:51:44 +02:00
|
|
|
ServeCommon `yaml:",inline"`
|
2019-09-28 14:21:05 +02:00
|
|
|
Listen string `yaml:"listen,hostport"`
|
2019-12-30 19:42:17 +01:00
|
|
|
ListenFreeBind bool `yaml:"listen_freebind,default=false"`
|
2018-08-27 22:21:45 +02:00
|
|
|
Ca string `yaml:"ca"`
|
|
|
|
Cert string `yaml:"cert"`
|
|
|
|
Key string `yaml:"key"`
|
2018-09-05 01:41:54 +02:00
|
|
|
ClientCNs []string `yaml:"client_cns"`
|
2018-12-11 21:54:36 +01:00
|
|
|
HandshakeTimeout time.Duration `yaml:"handshake_timeout,zeropositive,default=10s"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 23:46:59 +02:00
|
|
|
type StdinserverServer struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
ServeCommon `yaml:",inline"`
|
2018-09-05 01:41:54 +02:00
|
|
|
ClientIdentities []string `yaml:"client_identities"`
|
2018-08-26 23:46:59 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 14:43:53 +02:00
|
|
|
type LocalServe struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
ServeCommon `yaml:",inline"`
|
2018-10-11 13:06:47 +02:00
|
|
|
ListenerName string `yaml:"listener_name"`
|
2018-09-24 14:43:53 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type PruningEnum struct {
|
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PruneKeepNotReplicated struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
KeepSnapshotAtCursor bool `yaml:"keep_snapshot_at_cursor,optional,default=true"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PruneKeepLastN struct {
|
2018-08-26 16:44:34 +02:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Count int `yaml:"count"`
|
2020-08-31 14:05:32 +02:00
|
|
|
Regex string `yaml:"regex,optional"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-30 11:44:43 +02:00
|
|
|
type PruneKeepRegex struct { // FIXME rename to KeepRegex
|
2019-03-22 19:41:12 +01:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Regex string `yaml:"regex"`
|
2018-11-16 11:32:24 +01:00
|
|
|
Negate bool `yaml:"negate,optional,default=false"`
|
2018-08-27 15:18:08 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type LoggingOutletEnum struct {
|
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
2018-08-26 16:44:34 +02:00
|
|
|
type LoggingOutletCommon struct {
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
Level string `yaml:"level"`
|
|
|
|
Format string `yaml:"format"`
|
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
type StdoutLoggingOutlet struct {
|
2018-08-26 16:44:34 +02:00
|
|
|
LoggingOutletCommon `yaml:",inline"`
|
2018-08-27 22:21:45 +02:00
|
|
|
Time bool `yaml:"time,default=true"`
|
2018-09-05 02:25:10 +02:00
|
|
|
Color bool `yaml:"color,default=true"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SyslogLoggingOutlet struct {
|
2018-08-26 16:44:34 +02:00
|
|
|
LoggingOutletCommon `yaml:",inline"`
|
2019-03-15 17:44:41 +01:00
|
|
|
Facility *SyslogFacility `yaml:"facility,optional,fromdefaults"`
|
2019-03-22 19:41:12 +01:00
|
|
|
RetryInterval time.Duration `yaml:"retry_interval,positive,default=10s"`
|
2018-08-26 16:44:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type TCPLoggingOutlet struct {
|
|
|
|
LoggingOutletCommon `yaml:",inline"`
|
2019-09-28 14:21:05 +02:00
|
|
|
Address string `yaml:"address,hostport"`
|
2018-08-26 23:11:50 +02:00
|
|
|
Net string `yaml:"net,default=tcp"`
|
2018-08-27 22:21:45 +02:00
|
|
|
RetryInterval time.Duration `yaml:"retry_interval,positive,default=10s"`
|
2018-08-26 21:37:29 +02:00
|
|
|
TLS *TCPLoggingOutletTLS `yaml:"tls,optional"`
|
2018-08-26 16:44:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type TCPLoggingOutletTLS struct {
|
|
|
|
CA string `yaml:"ca"`
|
|
|
|
Cert string `yaml:"cert"`
|
|
|
|
Key string `yaml:"key"`
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 20:25:06 +02:00
|
|
|
type MonitoringEnum struct {
|
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrometheusMonitoring struct {
|
2019-12-30 19:42:17 +01:00
|
|
|
Type string `yaml:"type"`
|
|
|
|
Listen string `yaml:"listen,hostport"`
|
|
|
|
ListenFreeBind bool `yaml:"listen_freebind,default=false"`
|
2018-08-26 20:25:06 +02:00
|
|
|
}
|
|
|
|
|
2019-03-15 17:44:41 +01:00
|
|
|
type SyslogFacility syslog.Priority
|
2019-02-01 21:44:51 +01:00
|
|
|
|
2019-03-15 17:44:41 +01:00
|
|
|
func (f *SyslogFacility) SetDefault() {
|
|
|
|
*f = SyslogFacility(syslog.LOG_LOCAL0)
|
2019-02-01 21:44:51 +01:00
|
|
|
}
|
|
|
|
|
2019-03-15 17:44:41 +01:00
|
|
|
var _ yaml.Defaulter = (*SyslogFacility)(nil)
|
|
|
|
|
2018-08-26 23:11:50 +02:00
|
|
|
type GlobalControl struct {
|
|
|
|
SockPath string `yaml:"sockpath,default=/var/run/zrepl/control"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type GlobalServe struct {
|
2018-08-31 21:50:59 +02:00
|
|
|
StdinServer *GlobalStdinServer `yaml:"stdinserver,optional,fromdefaults"`
|
2018-08-26 23:11:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type GlobalStdinServer struct {
|
|
|
|
SockDir string `yaml:"sockdir,default=/var/run/zrepl/stdinserver"`
|
|
|
|
}
|
|
|
|
|
2019-07-26 21:12:21 +02:00
|
|
|
type HookList []HookEnum
|
|
|
|
|
|
|
|
type HookEnum struct {
|
|
|
|
Ret interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HookCommand struct {
|
|
|
|
Path string `yaml:"path"`
|
|
|
|
Timeout time.Duration `yaml:"timeout,optional,positive,default=30s"`
|
|
|
|
Filesystems FilesystemsFilter `yaml:"filesystems,optional,default={'<': true}"`
|
|
|
|
HookSettingsCommon `yaml:",inline"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type HookPostgresCheckpoint struct {
|
|
|
|
HookSettingsCommon `yaml:",inline"`
|
|
|
|
DSN string `yaml:"dsn"`
|
|
|
|
Timeout time.Duration `yaml:"timeout,optional,positive,default=30s"`
|
|
|
|
Filesystems FilesystemsFilter `yaml:"filesystems"` // required, user should not CHECKPOINT for every FS
|
|
|
|
}
|
|
|
|
|
|
|
|
type HookMySQLLockTables struct {
|
|
|
|
HookSettingsCommon `yaml:",inline"`
|
|
|
|
DSN string `yaml:"dsn"`
|
|
|
|
Timeout time.Duration `yaml:"timeout,optional,positive,default=30s"`
|
|
|
|
Filesystems FilesystemsFilter `yaml:"filesystems"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type HookSettingsCommon struct {
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
ErrIsFatal bool `yaml:"err_is_fatal,optional,default=false"`
|
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
func enumUnmarshal(u func(interface{}, bool) error, types map[string]interface{}) (interface{}, error) {
|
|
|
|
var in struct {
|
|
|
|
Type string
|
|
|
|
}
|
|
|
|
if err := u(&in, true); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if in.Type == "" {
|
2018-09-05 02:25:10 +02:00
|
|
|
return nil, &yaml.TypeError{Errors: []string{"must specify type"}}
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
v, ok := types[in.Type]
|
|
|
|
if !ok {
|
2018-09-05 02:25:10 +02:00
|
|
|
return nil, &yaml.TypeError{Errors: []string{fmt.Sprintf("invalid type name %q", in.Type)}}
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|
|
|
|
if err := u(v, false); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
2018-08-26 16:44:34 +02:00
|
|
|
func (t *JobEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
2018-08-26 15:17:15 +02:00
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
2018-11-20 19:30:15 +01:00
|
|
|
"snap": &SnapJob{},
|
2018-08-26 23:11:50 +02:00
|
|
|
"push": &PushJob{},
|
|
|
|
"sink": &SinkJob{},
|
|
|
|
"pull": &PullJob{},
|
|
|
|
"source": &SourceJob{},
|
2018-08-26 15:17:15 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ConnectEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
2018-08-27 15:18:08 +02:00
|
|
|
"tcp": &TCPConnect{},
|
|
|
|
"tls": &TLSConnect{},
|
2018-08-26 23:46:59 +02:00
|
|
|
"ssh+stdinserver": &SSHStdinserverConnect{},
|
2019-03-22 19:41:12 +01:00
|
|
|
"local": &LocalConnect{},
|
2018-08-26 15:17:15 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ServeEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
2018-08-27 15:18:08 +02:00
|
|
|
"tcp": &TCPServe{},
|
|
|
|
"tls": &TLSServe{},
|
2018-08-26 23:46:59 +02:00
|
|
|
"stdinserver": &StdinserverServer{},
|
2019-03-22 19:41:12 +01:00
|
|
|
"local": &LocalServe{},
|
2018-08-26 15:17:15 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *PruningEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
|
|
|
"not_replicated": &PruneKeepNotReplicated{},
|
2018-08-26 16:44:34 +02:00
|
|
|
"last_n": &PruneKeepLastN{},
|
|
|
|
"grid": &PruneGrid{},
|
2018-10-11 13:07:52 +02:00
|
|
|
"regex": &PruneKeepRegex{},
|
2018-08-26 15:17:15 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-11 15:22:52 +02:00
|
|
|
func (t *SnapshottingEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
|
|
|
"periodic": &SnapshottingPeriodic{},
|
2019-03-22 19:41:12 +01:00
|
|
|
"manual": &SnapshottingManual{},
|
2022-04-12 01:26:41 +02:00
|
|
|
"cron": &SnapshottingCron{},
|
2018-10-11 15:22:52 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
func (t *LoggingOutletEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
|
|
|
"stdout": &StdoutLoggingOutlet{},
|
|
|
|
"syslog": &SyslogLoggingOutlet{},
|
2018-08-26 16:44:34 +02:00
|
|
|
"tcp": &TCPLoggingOutlet{},
|
2018-08-26 15:17:15 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-26 20:25:06 +02:00
|
|
|
func (t *MonitoringEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
|
|
|
"prometheus": &PrometheusMonitoring{},
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-15 17:44:41 +01:00
|
|
|
func (t *SyslogFacility) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
var s string
|
|
|
|
if err := u(&s, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var level syslog.Priority
|
|
|
|
switch s {
|
2019-03-22 19:41:12 +01:00
|
|
|
case "kern":
|
|
|
|
level = syslog.LOG_KERN
|
|
|
|
case "user":
|
|
|
|
level = syslog.LOG_USER
|
|
|
|
case "mail":
|
|
|
|
level = syslog.LOG_MAIL
|
|
|
|
case "daemon":
|
|
|
|
level = syslog.LOG_DAEMON
|
|
|
|
case "auth":
|
|
|
|
level = syslog.LOG_AUTH
|
|
|
|
case "syslog":
|
|
|
|
level = syslog.LOG_SYSLOG
|
|
|
|
case "lpr":
|
|
|
|
level = syslog.LOG_LPR
|
|
|
|
case "news":
|
|
|
|
level = syslog.LOG_NEWS
|
|
|
|
case "uucp":
|
|
|
|
level = syslog.LOG_UUCP
|
|
|
|
case "cron":
|
|
|
|
level = syslog.LOG_CRON
|
|
|
|
case "authpriv":
|
|
|
|
level = syslog.LOG_AUTHPRIV
|
|
|
|
case "ftp":
|
|
|
|
level = syslog.LOG_FTP
|
|
|
|
case "local0":
|
|
|
|
level = syslog.LOG_LOCAL0
|
|
|
|
case "local1":
|
|
|
|
level = syslog.LOG_LOCAL1
|
|
|
|
case "local2":
|
|
|
|
level = syslog.LOG_LOCAL2
|
|
|
|
case "local3":
|
|
|
|
level = syslog.LOG_LOCAL3
|
|
|
|
case "local4":
|
|
|
|
level = syslog.LOG_LOCAL4
|
|
|
|
case "local5":
|
|
|
|
level = syslog.LOG_LOCAL5
|
|
|
|
case "local6":
|
|
|
|
level = syslog.LOG_LOCAL6
|
|
|
|
case "local7":
|
|
|
|
level = syslog.LOG_LOCAL7
|
2019-03-15 17:44:41 +01:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("invalid syslog level: %q", s)
|
|
|
|
}
|
|
|
|
*t = SyslogFacility(level)
|
2019-03-22 19:41:12 +01:00
|
|
|
return nil
|
2019-02-01 21:44:51 +01:00
|
|
|
}
|
|
|
|
|
2019-07-26 21:12:21 +02:00
|
|
|
func (t *HookEnum) UnmarshalYAML(u func(interface{}, bool) error) (err error) {
|
|
|
|
t.Ret, err = enumUnmarshal(u, map[string]interface{}{
|
|
|
|
"command": &HookCommand{},
|
|
|
|
"postgres-checkpoint": &HookPostgresCheckpoint{},
|
|
|
|
"mysql-lock-tables": &HookMySQLLockTables{},
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-26 15:17:15 +02:00
|
|
|
var ConfigFileDefaultLocations = []string{
|
|
|
|
"/etc/zrepl/zrepl.yml",
|
|
|
|
"/usr/local/etc/zrepl/zrepl.yml",
|
|
|
|
}
|
|
|
|
|
2018-08-31 21:50:59 +02:00
|
|
|
func ParseConfig(path string) (i *Config, err error) {
|
2018-08-26 15:17:15 +02:00
|
|
|
|
|
|
|
if path == "" {
|
|
|
|
// Try default locations
|
|
|
|
for _, l := range ConfigFileDefaultLocations {
|
|
|
|
stat, statErr := os.Stat(l)
|
|
|
|
if statErr != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !stat.Mode().IsRegular() {
|
|
|
|
err = errors.Errorf("file at default location is not a regular file: %s", l)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
path = l
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var bytes []byte
|
|
|
|
|
2024-09-08 15:15:26 +02:00
|
|
|
if bytes, err = os.ReadFile(path); err != nil {
|
2018-08-26 15:17:15 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-31 21:50:59 +02:00
|
|
|
return ParseConfigBytes(bytes)
|
|
|
|
}
|
2018-08-26 15:17:15 +02:00
|
|
|
|
2018-08-31 21:50:59 +02:00
|
|
|
func ParseConfigBytes(bytes []byte) (*Config, error) {
|
|
|
|
var c *Config
|
|
|
|
if err := yaml.UnmarshalStrict(bytes, &c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-05-14 19:18:22 +02:00
|
|
|
if c != nil {
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
// There was no yaml document in the file, deserialize from default.
|
|
|
|
// => See TestFromdefaultsEmptyDoc in yaml-config package.
|
|
|
|
if err := yaml.UnmarshalStrict([]byte("{}"), &c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-31 21:50:59 +02:00
|
|
|
if c == nil {
|
2024-05-14 19:18:22 +02:00
|
|
|
panic("the fallback to deserialize from `{}` should work")
|
2018-08-31 21:50:59 +02:00
|
|
|
}
|
|
|
|
return c, nil
|
2018-08-26 15:17:15 +02:00
|
|
|
}
|