Skip to content

Commit 49c8f76

Browse files
restore inplace
1 parent 8fa9b31 commit 49c8f76

File tree

5 files changed

+500
-4
lines changed

5 files changed

+500
-4
lines changed

cmd/clickhouse-backup/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ func main() {
407407
UsageText: "clickhouse-backup restore [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [-s, --schema] [-d, --data] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--resume] <backup_name>",
408408
Action: func(c *cli.Context) error {
409409
b := backup.NewBackuper(config.GetConfigFromCli(c))
410+
// Override config with CLI flag if provided
411+
if c.Bool("restore-in-place") {
412+
b.SetRestoreInPlace(true)
413+
}
410414
return b.Restore(c.Args().First(), c.String("tables"), c.StringSlice("restore-database-mapping"), c.StringSlice("restore-table-mapping"), c.StringSlice("partitions"), c.StringSlice("skip-projections"), c.Bool("schema"), c.Bool("data"), c.Bool("drop"), c.Bool("ignore-dependencies"), c.Bool("rbac"), c.Bool("rbac-only"), c.Bool("configs"), c.Bool("configs-only"), c.Bool("resume"), c.Bool("restore-schema-as-attach"), c.Bool("replicated-copy-to-detached"), version, c.Int("command-id"))
411415
},
412416
Flags: append(cliapp.Flags,
@@ -496,6 +500,11 @@ func main() {
496500
Hidden: false,
497501
Usage: "Copy data to detached folder for Replicated*MergeTree tables but skip ATTACH PART step",
498502
},
503+
cli.BoolFlag{
504+
Name: "restore-in-place",
505+
Hidden: false,
506+
Usage: "Perform in-place restore by comparing backup parts with current database parts. Only downloads differential parts instead of full restore. Requires --data flag.",
507+
},
499508
),
500509
},
501510
{

pkg/backup/backuper.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import (
66
"encoding/binary"
77
"errors"
88
"fmt"
9-
"github.com/Altinity/clickhouse-backup/v2/pkg/common"
10-
"github.com/Altinity/clickhouse-backup/v2/pkg/metadata"
11-
"github.com/Altinity/clickhouse-backup/v2/pkg/utils"
12-
"github.com/eapache/go-resiliency/retrier"
139
"net/url"
1410
"os"
1511
"path"
1612
"regexp"
1713
"strings"
1814

15+
"github.com/Altinity/clickhouse-backup/v2/pkg/common"
16+
"github.com/Altinity/clickhouse-backup/v2/pkg/metadata"
17+
"github.com/Altinity/clickhouse-backup/v2/pkg/utils"
18+
"github.com/eapache/go-resiliency/retrier"
19+
1920
"github.com/Altinity/clickhouse-backup/v2/pkg/clickhouse"
2021
"github.com/Altinity/clickhouse-backup/v2/pkg/config"
2122
"github.com/Altinity/clickhouse-backup/v2/pkg/resumable"
@@ -64,6 +65,11 @@ func NewBackuper(cfg *config.Config, opts ...BackuperOpt) *Backuper {
6465
return b
6566
}
6667

68+
// SetRestoreInPlace sets the RestoreInPlace flag in the configuration
69+
func (b *Backuper) SetRestoreInPlace(value bool) {
70+
b.cfg.General.RestoreInPlace = value
71+
}
72+
6773
// Classify need to log retries
6874
func (b *Backuper) Classify(err error) retrier.Action {
6975
if err == nil {

0 commit comments

Comments
 (0)