Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2023-11-22 05:04:21 +0300
committerJames Fargher <jfargher@gitlab.com>2023-12-11 23:04:15 +0300
commit9969f92a9bc2ad7d9373fa96cabeca559acd40d7 (patch)
treedd7f4f1158a80380032d5b59ea2bd6aeee71866f
parentbf5fe041c501d17be2f0ea74a8d83b0f68f22ab7 (diff)
backup: Introduce a base backup ID
This base ID will be used to find the backup to use as a base of an incremental backup. Right now pointer layout always uses the latest backup as a base. Specifying a base will allow extra flexibility.
-rw-r--r--internal/backup/backup.go9
-rw-r--r--internal/backup/locator.go8
-rw-r--r--internal/backup/locator_test.go4
-rw-r--r--internal/backup/pipeline.go3
-rw-r--r--internal/backup/server_side.go1
-rw-r--r--internal/bundleuri/git_config_test.go2
-rw-r--r--internal/cli/gitalybackup/create.go3
-rw-r--r--internal/gitaly/service/repository/backup_repository.go1
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack_test.go2
9 files changed, 22 insertions, 11 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go
index cb1265a5e..e9b957b79 100644
--- a/internal/backup/backup.go
+++ b/internal/backup/backup.go
@@ -92,8 +92,11 @@ type Locator interface {
BeginFull(ctx context.Context, repo storage.Repository, backupID string) *Backup
// BeginIncremental returns the backup with the last element of Steps being
- // the tentative step needed to create an incremental backup.
- BeginIncremental(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error)
+ // the tentative step needed to create an incremental backup. backupID will
+ // be the name of the newly created backup. baseBackupID is the name of the
+ // backup used to create an incremental backup from if supported by the
+ // layout.
+ BeginIncremental(ctx context.Context, repo storage.Repository, backupID, baseBackupID string) (*Backup, error)
// Commit persists the backup so that it can be looked up by FindLatest. It
// is expected that the last element of Steps will be the newly created
@@ -243,7 +246,7 @@ func (mgr *Manager) Create(ctx context.Context, req *CreateRequest) error {
var backup *Backup
if req.Incremental {
var err error
- backup, err = mgr.locator.BeginIncremental(ctx, req.VanityRepository, req.BackupID)
+ backup, err = mgr.locator.BeginIncremental(ctx, req.VanityRepository, req.BackupID, req.BaseBackupID)
if err != nil {
return fmt.Errorf("manager: %w", err)
}
diff --git a/internal/backup/locator.go b/internal/backup/locator.go
index b2952a5f7..f2ffa3931 100644
--- a/internal/backup/locator.go
+++ b/internal/backup/locator.go
@@ -35,7 +35,7 @@ func (l LegacyLocator) BeginFull(ctx context.Context, repo storage.Repository, b
}
// BeginIncremental is not supported for legacy backups
-func (l LegacyLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) {
+func (l LegacyLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID, baseBackupID string) (*Backup, error) {
return nil, errors.New("legacy layout: begin incremental: not supported")
}
@@ -108,7 +108,7 @@ func (l PointerLocator) BeginFull(ctx context.Context, repo storage.Repository,
// backup. The incremental backup is always based off of the latest full
// backup. If there is no latest backup, a new full backup step is returned
// using fallbackBackupID
-func (l PointerLocator) BeginIncremental(ctx context.Context, repo storage.Repository, fallbackBackupID string) (*Backup, error) {
+func (l PointerLocator) BeginIncremental(ctx context.Context, repo storage.Repository, fallbackBackupID, _baseBackupID string) (*Backup, error) {
repoPath := strings.TrimSuffix(repo.GetRelativePath(), ".git")
backupID, err := l.findLatestID(ctx, repoPath)
if err != nil {
@@ -286,8 +286,8 @@ func (l ManifestInteropLocator) BeginFull(ctx context.Context, repo storage.Repo
}
// BeginIncremental passes through to Fallback
-func (l ManifestInteropLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID string) (*Backup, error) {
- return l.Fallback.BeginIncremental(ctx, repo, backupID)
+func (l ManifestInteropLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID, baseBackupID string) (*Backup, error) {
+ return l.Fallback.BeginIncremental(ctx, repo, backupID, baseBackupID)
}
// Commit passes through to Fallback, then writes a manifest file for the backup.
diff --git a/internal/backup/locator_test.go b/internal/backup/locator_test.go
index cb7f5c4ed..4c49a17a5 100644
--- a/internal/backup/locator_test.go
+++ b/internal/backup/locator_test.go
@@ -184,7 +184,7 @@ func TestPointerLocator(t *testing.T) {
previousRefPath = step.RefPath
}
- step, err := l.BeginIncremental(ctx, repo, fallbackBackupID)
+ step, err := l.BeginIncremental(ctx, repo, fallbackBackupID, "")
require.NoError(t, err)
require.Equal(t, expected, step)
@@ -465,7 +465,7 @@ custom_hooks_path = '%[1]s/%[2]s/001.custom_hooks.tar'
Fallback: l,
}
- incremental, err := l.BeginIncremental(ctx, repo, backupID)
+ incremental, err := l.BeginIncremental(ctx, repo, backupID, "")
require.NoError(t, err)
require.NoError(t, l.Commit(ctx, incremental))
diff --git a/internal/backup/pipeline.go b/internal/backup/pipeline.go
index 8e4e15784..9d98c1008 100644
--- a/internal/backup/pipeline.go
+++ b/internal/backup/pipeline.go
@@ -33,6 +33,9 @@ type CreateRequest struct {
// BackupID is used to determine a unique path for the backup when a full
// backup is created.
BackupID string
+ // BaseBackupID is used to determine the backup used to use as the base of
+ // an incremental backup if supported by the selected layout.
+ BaseBackupID string
}
// RestoreRequest is the request to restore from a backup
diff --git a/internal/backup/server_side.go b/internal/backup/server_side.go
index 35654f215..1e58f7c86 100644
--- a/internal/backup/server_side.go
+++ b/internal/backup/server_side.go
@@ -42,6 +42,7 @@ func (ss ServerSideAdapter) Create(ctx context.Context, req *CreateRequest) erro
VanityRepository: req.VanityRepository,
BackupId: req.BackupID,
Incremental: req.Incremental,
+ BaseBackupId: req.BaseBackupID,
})
if err != nil {
st := status.Convert(err)
diff --git a/internal/bundleuri/git_config_test.go b/internal/bundleuri/git_config_test.go
index c14c3625b..cea6be8e1 100644
--- a/internal/bundleuri/git_config_test.go
+++ b/internal/bundleuri/git_config_test.go
@@ -159,7 +159,7 @@ func (l dummyLocator) BeginFull(ctx context.Context, repo storage.Repository, ba
}
// BeginIncremental is not supported by this dummyLocator.
-func (l dummyLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID string) (*backup.Backup, error) {
+func (l dummyLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID, baseBackupID string) (*backup.Backup, error) {
return nil, structerr.NewUnimplemented("BeginIncremental not implemented for dummyLocator")
}
diff --git a/internal/cli/gitalybackup/create.go b/internal/cli/gitalybackup/create.go
index e1a6ec823..c8194191c 100644
--- a/internal/cli/gitalybackup/create.go
+++ b/internal/cli/gitalybackup/create.go
@@ -31,6 +31,7 @@ type createSubcommand struct {
layout string
incremental bool
backupID string
+ baseBackupID string
serverSide bool
}
@@ -41,6 +42,7 @@ func (cmd *createSubcommand) flags(ctx *cli.Context) {
cmd.layout = ctx.String("layout")
cmd.incremental = ctx.Bool("incremental")
cmd.backupID = ctx.String("id")
+ cmd.baseBackupID = ctx.String("base-id")
cmd.serverSide = ctx.Bool("server-side")
}
@@ -168,6 +170,7 @@ func (cmd *createSubcommand) run(ctx context.Context, logger log.Logger, stdin i
VanityRepository: &repo,
Incremental: cmd.incremental,
BackupID: cmd.backupID,
+ BaseBackupID: cmd.baseBackupID,
}))
}
diff --git a/internal/gitaly/service/repository/backup_repository.go b/internal/gitaly/service/repository/backup_repository.go
index 60b0314ca..880a60c98 100644
--- a/internal/gitaly/service/repository/backup_repository.go
+++ b/internal/gitaly/service/repository/backup_repository.go
@@ -36,6 +36,7 @@ func (s *server) BackupRepository(ctx context.Context, in *gitalypb.BackupReposi
VanityRepository: in.VanityRepository,
BackupID: in.BackupId,
Incremental: in.Incremental,
+ BaseBackupID: in.BaseBackupId,
})
switch {
diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go
index 47178ece6..6e9748d8d 100644
--- a/internal/gitaly/service/smarthttp/upload_pack_test.go
+++ b/internal/gitaly/service/smarthttp/upload_pack_test.go
@@ -386,7 +386,7 @@ func (l *mockBackupLocator) BeginFull(ctx context.Context, repo storage.Reposito
return l.backup
}
-func (l *mockBackupLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID string) (*backup.Backup, error) {
+func (l *mockBackupLocator) BeginIncremental(ctx context.Context, repo storage.Repository, backupID, baseBackupID string) (*backup.Backup, error) {
return nil, nil
}