From f18fb66665f8216d665818b75aa6b18ff52cb55a Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 3 Jan 2024 00:54:02 -0500 Subject: [PATCH] Better logic --- CHANGELOG.md | 1 + store/store.go | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b2d5cee..70ad65f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [PR #1548](https://github.com/rqlite/rqlite/pull/1548): Make system-level test failures easier to understand. - [PR #1555](https://github.com/rqlite/rqlite/pull/1555): Correct build and import of Protobuf files. - [PR #1556](https://github.com/rqlite/rqlite/pull/1556): Add fast-path backup. +- [PR #1556](https://github.com/rqlite/rqlite/pull/1556): rqlite CLI streams backup to file. ## 8.14.1 (December 31st 2023) ### Implementation changes and bug fixes diff --git a/store/store.go b/store/store.go index c05c9dc8..a850d2ab 100644 --- a/store/store.go +++ b/store/store.go @@ -1199,19 +1199,6 @@ func (s *Store) Backup(br *proto.BackupRequest, dst io.Writer) (retErr error) { } if br.Format == proto.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY { - // Snapshot to ensure the main SQLite file has all the latest data. - if err := s.Snapshot(0); err != nil && err != raft.ErrNothingNewToSnapshot { - return fmt.Errorf("pre-backup snapshot failed: %s", err.Error()) - } - - // Pause any snapshotting and which will allow us to read the SQLite - // file without it changing underneath us. Any new writes will be - // sent to the WAL. - if err := s.snapshotCAS.Begin(); err != nil { - return err - } - defer s.snapshotCAS.End() - var srcFD *os.File var err error if br.Vacuum { @@ -1229,6 +1216,18 @@ func (s *Store) Backup(br *proto.BackupRequest, dst io.Writer) (retErr error) { return err } } else { + // Snapshot to ensure the main SQLite file has all the latest data. + if err := s.Snapshot(0); err != nil && err != raft.ErrNothingNewToSnapshot { + return fmt.Errorf("pre-backup snapshot failed: %s", err.Error()) + } + // Pause any snapshotting and which will allow us to read the SQLite + // file without it changing underneath us. Any new writes will be + // sent to the WAL. + if err := s.snapshotCAS.Begin(); err != nil { + return err + } + defer s.snapshotCAS.End() + // Fast path -- direct copy. srcFD, err = os.Open(s.dbPath) if err != nil {