From 17a9f2b95885c075bb26f4b038902b8b8cacdc90 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 12 Feb 2020 14:01:07 -0800 Subject: [PATCH] Create backups without freelist. (#4847) * Create backups without freelist. This is a bit slower, but more accurate * Merge refs/heads/master into better-backups --- beacon-chain/db/kv/backup.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/beacon-chain/db/kv/backup.go b/beacon-chain/db/kv/backup.go index 52436b871dba..27d30b8990fd 100644 --- a/beacon-chain/db/kv/backup.go +++ b/beacon-chain/db/kv/backup.go @@ -34,7 +34,25 @@ func (k *Store) Backup(ctx context.Context) error { } backupPath := path.Join(backupsDir, fmt.Sprintf("prysm_beacondb_at_slot_%07d.backup", head.Block.Slot)) logrus.WithField("prefix", "db").WithField("backup", backupPath).Info("Writing backup database.") + + copyDB, err := bolt.Open(backupPath, 0666, nil) + if err != nil { + panic(err) + } + defer copyDB.Close() + return k.db.View(func(tx *bolt.Tx) error { - return tx.CopyFile(backupPath, 0666) + return tx.ForEach(func(name []byte, b *bolt.Bucket) error { + logrus.Debugf("Copying bucket %s\n", name) + return copyDB.Update(func(tx2 *bolt.Tx) error { + b2, err := tx2.CreateBucketIfNotExists(name) + if err != nil { + return err + } + return b.ForEach(func(k []byte, v []byte) error { + return b2.Put(k, v) + }) + }) + }) }) }