@@ -5,15 +5,16 @@ import (
55 "context"
66 "encoding/json"
77 "fmt"
8- "github.com/antchfx/xmlquery"
9- "github.com/rs/zerolog"
10- "github.com/rs/zerolog/log"
118 "os"
129 "path"
1310 "strconv"
1411 "strings"
1512 "time"
1613
14+ "github.com/antchfx/xmlquery"
15+ "github.com/rs/zerolog"
16+ "github.com/rs/zerolog/log"
17+
1718 "github.com/Altinity/clickhouse-backup/v2/pkg/clickhouse"
1819 "github.com/go-zookeeper/zk"
1920)
@@ -42,6 +43,12 @@ type DumpNode struct {
4243 Value []byte `json:"value"` // json encodes/decodes as base64 automatically
4344}
4445
46+ // old format used during restore
47+ type DumpNodeString struct {
48+ Path string `json:"path"`
49+ Value string `json:"value"`
50+ }
51+
4552type Keeper struct {
4653 conn * zk.Conn
4754 root string
@@ -197,8 +204,13 @@ func (k *Keeper) Restore(dumpFile, prefix string) error {
197204 scanner := bufio .NewScanner (f )
198205 for scanner .Scan () {
199206 node := DumpNode {}
200- if err = json .Unmarshal (scanner .Bytes (), & node ); err != nil {
201- return err
207+ binaryData := scanner .Bytes ()
208+ if err = json .Unmarshal (binaryData , & node ); err != nil {
209+ //convert from old format
210+ nodeString := DumpNodeString {}
211+ if stringUnmarshalErr := json .Unmarshal (binaryData , & nodeString ); stringUnmarshalErr != nil {
212+ return fmt .Errorf ("k.Restore can't read data binaryErr=%v, stringErr=%v" , err , stringUnmarshalErr )
213+ }
202214 }
203215 node .Path = path .Join (prefix , node .Path )
204216 version := int32 (0 )
0 commit comments