From 60d546e309f79460ad53deda0bb6888315462e43 Mon Sep 17 00:00:00 2001 From: Jingyi Hu Date: Tue, 25 Sep 2018 16:50:47 -0700 Subject: [PATCH] etcdctl: cherry pick of #10109 to release-3.3 Add snapshot file integrity verification in snapshot status. --- etcdctl/ctlv3/command/snapshot_command.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/etcdctl/ctlv3/command/snapshot_command.go b/etcdctl/ctlv3/command/snapshot_command.go index 2929cd94e8c..297c9c0b93c 100644 --- a/etcdctl/ctlv3/command/snapshot_command.go +++ b/etcdctl/ctlv3/command/snapshot_command.go @@ -423,6 +423,14 @@ func dbStatus(p string) dbstatus { h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) err = db.View(func(tx *bolt.Tx) error { + // check snapshot file integrity first + var dbErrStrings []string + for dbErr := range tx.Check() { + dbErrStrings = append(dbErrStrings, dbErr.Error()) + } + if len(dbErrStrings) > 0 { + return fmt.Errorf("snapshot file integrity check failed. %d errors found.\n"+strings.Join(dbErrStrings, "\n"), len(dbErrStrings)) + } ds.TotalSize = tx.Size() c := tx.Cursor() for next, _ := c.First(); next != nil; next, _ = c.Next() {