@@ -301,18 +301,22 @@ func (s *Sia) Close() error {
301301 return nil
302302}
303303
304- // BackupSQLite3 creates a backup of the SQLite3 database at destPath and
305- // records it as a snapshot so the orphan loop does not unpin data the backup
306- // references. The backup is created using the SQLite backup API, which is safe
307- // to use with a live database.
304+ // BackupSQLite3 flushes pending objects to Sia, then creates a backup of the
305+ // SQLite3 database at destPath and records it as a snapshot so the orphan loop
306+ // does not unpin data the backup references. The backup is created using the
307+ // SQLite backup API, which is safe to use with a live database.
308308func (s * Sia ) BackupSQLite3 (ctx context.Context , destPath string ) error {
309309 if destPath == "" {
310310 return errors .New ("empty destination path" )
311311 } else if ! filepath .IsAbs (destPath ) {
312312 return fmt .Errorf ("destination path must be absolute: %q" , destPath )
313313 }
314- // TODO: flush pending objects before the backup so the snapshot does not
315- // reference data still only on local disk (needs FlushObjects, #209)
314+ // flush pending objects to Sia first so every object captured by the
315+ // snapshot has been uploaded and pinned, rather than living only on local
316+ // disk where the SQLite backup cannot reference it
317+ if err := s .FlushObjects (ctx ); err != nil {
318+ return fmt .Errorf ("failed to flush objects before backup: %w" , err )
319+ }
316320 return s .store .CreateSnapshot (ctx , destPath )
317321}
318322
0 commit comments