Skip to content

Commit

Permalink
Create backups without freelist. (prysmaticlabs#4847)
Browse files Browse the repository at this point in the history
* Create backups without freelist. This is a bit slower, but more accurate
* Merge refs/heads/master into better-backups
  • Loading branch information
prestonvanloon authored and cryptomental committed Feb 28, 2020
1 parent 6988af3 commit 17a9f2b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion beacon-chain/db/kv/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})
}

0 comments on commit 17a9f2b

Please sign in to comment.