From d09484e94f2e9dc8e980aa328a5f4739085a07c3 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 7 Jul 2020 17:55:15 +0000 Subject: [PATCH] backupccl: make basic BACKUP and RESTORE free to use The removes the enterprise license check from RESTORE as well as from the basic form of BACKUP, making these free to use without an enterprise licsense. Advanced BACKUP options like incremental backups, backups to partitioned storage destinations, or backups that capture revision history or use file-level encryption all continue to require an enterprise license, but basic backups can now be run without a license. RESTORE now never requires a license regardless of the options passed to it or to the backup it is restoring. Release note (enterprise change): Basic BACKUP and RESTORE no longer require an enterprise license. --- pkg/ccl/backupccl/backup_planning.go | 51 +++++++++++++++++++++------ pkg/ccl/backupccl/restore_planning.go | 7 ---- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/pkg/ccl/backupccl/backup_planning.go b/pkg/ccl/backupccl/backup_planning.go index 79f455b484bc..c24409193bb3 100644 --- a/pkg/ccl/backupccl/backup_planning.go +++ b/pkg/ccl/backupccl/backup_planning.go @@ -10,13 +10,13 @@ package backupccl import ( "context" + "fmt" "net/url" "sort" "github.com/cockroachdb/cockroach/pkg/build" "github.com/cockroachdb/cockroach/pkg/ccl/storageccl" "github.com/cockroachdb/cockroach/pkg/ccl/utilccl" - "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/jobs/jobsprotectedts" @@ -285,12 +285,6 @@ func backupPlanHook( ctx, span := tracing.ChildSpan(ctx, stmt.StatementTag()) defer tracing.FinishSpan(span) - if err := utilccl.CheckEnterpriseEnabled( - p.ExecCfg().Settings, p.ExecCfg().ClusterID(), p.ExecCfg().Organization(), "BACKUP", - ); err != nil { - return err - } - if err := p.RequireAdminRole(ctx, "BACKUP"); err != nil { return err } @@ -299,13 +293,29 @@ func backupPlanHook( return errors.Errorf("BACKUP cannot be used inside a transaction without DETACHED option") } + var isEnterprise bool + requireEnterprise := func(feature string) error { + if isEnterprise { + return nil + } + if err := utilccl.CheckEnterpriseEnabled( + p.ExecCfg().Settings, p.ExecCfg().ClusterID(), p.ExecCfg().Organization(), + fmt.Sprintf("BACKUP with %s", feature), + ); err != nil { + return err + } + isEnterprise = true + return nil + } + to, err := toFn() if err != nil { return err } - if len(to) > 1 && - !p.ExecCfg().Settings.Version.IsActive(ctx, clusterversion.VersionPartitionedBackup) { - return errors.Errorf("partitioned backups can only be made on a cluster that has been fully upgraded to version 19.2") + if len(to) > 1 { + if err := requireEnterprise("partitoned destinations"); err != nil { + return err + } } incrementalFrom, err := incrementalFromFn() @@ -323,6 +333,9 @@ func backupPlanHook( mvccFilter := MVCCFilter_Latest if backupStmt.Options.CaptureRevisionHistory { + if err := requireEnterprise("revision_history"); err != nil { + return err + } mvccFilter = MVCCFilter_All } @@ -367,6 +380,9 @@ func backupPlanHook( if err != nil { return err } + if err := requireEnterprise("encryption"); err != nil { + return err + } encryptionPassphrase = []byte(pw) } @@ -506,6 +522,9 @@ func backupPlanHook( var startTime hlc.Timestamp var newSpans roachpb.Spans if len(prevBackups) > 0 { + if err := requireEnterprise("incremental"); err != nil { + return err + } startTime = prevBackups[len(prevBackups)-1].EndTime } @@ -659,6 +678,18 @@ func backupPlanHook( collectTelemetry := func() { telemetry.Count("backup.total.started") + if isEnterprise { + telemetry.Count("backup.licensed") + telemetry.Count("backup.using-enterprise-features") + } else { + if err := utilccl.CheckEnterpriseEnabled( + p.ExecCfg().Settings, p.ExecCfg().ClusterID(), p.ExecCfg().Organization(), "", + ); err == nil { + telemetry.Count("backup.licensed") + } else { + telemetry.Count("backup.free") + } + } if startTime.IsEmpty() { telemetry.Count("backup.span.full") } else { diff --git a/pkg/ccl/backupccl/restore_planning.go b/pkg/ccl/backupccl/restore_planning.go index a901325df3c9..91daa4f97cfd 100644 --- a/pkg/ccl/backupccl/restore_planning.go +++ b/pkg/ccl/backupccl/restore_planning.go @@ -13,7 +13,6 @@ import ( "sort" "github.com/cockroachdb/cockroach/pkg/ccl/storageccl" - "github.com/cockroachdb/cockroach/pkg/ccl/utilccl" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/keys" @@ -878,12 +877,6 @@ func restorePlanHook( ctx, span := tracing.ChildSpan(ctx, stmt.StatementTag()) defer tracing.FinishSpan(span) - if err := utilccl.CheckEnterpriseEnabled( - p.ExecCfg().Settings, p.ExecCfg().ClusterID(), p.ExecCfg().Organization(), "RESTORE", - ); err != nil { - return err - } - if err := p.RequireAdminRole(ctx, "RESTORE"); err != nil { return err }