Skip to content

desktop/src-tauri/src/db_backup.rs

Comment 1, line 1

desktop/src-tauri/src/db_backup.rs:1

//! Consistent database backups and disk-space checks before V15/M1 migration/cleanup/rebuild.

Comment 2, line 2

desktop/src-tauri/src/db_backup.rs:2

//!

Comment 3, line 3

desktop/src-tauri/src/db_backup.rs:3

//! Backup rules:

Comment 4, line 4

desktop/src-tauri/src/db_backup.rs:4

//! - VACUUM INTO creates a single consistent snapshot, including with WAL, without file copying.

Comment 5, line 5

desktop/src-tauri/src/db_backup.rs:5

//! - Require target free space >= 1.1 * database/WAL/SHM bytes; insufficient space fails,

Comment 6, line 6

desktop/src-tauri/src/db_backup.rs:6

//! allowing callers to stop destructive operations.

Comment 7, line 7

desktop/src-tauri/src/db_backup.rs:7

//! - Keep three matching snapshots in filename order, using timestamped names.

Comment 8, line 8

desktop/src-tauri/src/db_backup.rs:8

//! V15 treats backups as application-managed restoration subject to retention rules.

Comment 9, line 9

desktop/src-tauri/src/db_backup.rs:9

//! - A direct read-only connection backs up old schemas rejected by application setup;

Comment 10, line 10

desktop/src-tauri/src/db_backup.rs:10

//! rebuild must finish backup before deleting the original.

Comment 11, line 15

desktop/src-tauri/src/db_backup.rs:15

/// Number of matching backups retained.

Comment 12, line 17

desktop/src-tauri/src/db_backup.rs:17

/// Free-space factor 1.1; this check does not establish an upper bound on snapshot size.

Comment 13, line 20

desktop/src-tauri/src/db_backup.rs:20

/// Current bytes in the database, -wal and -shm files.

Comment 14, line 32

desktop/src-tauri/src/db_backup.rs:32

/// backups/ beside the database, matching backup_before_clear placement.

Comment 15, line 40

desktop/src-tauri/src/db_backup.rs:40

/// Pure space test: free >= needed * 1.1 allows backup.

Comment 16, line 48

desktop/src-tauri/src/db_backup.rs:48

/// Insufficient target free space fails before backup; callers must stop destructive work.

Comment 17, line 65

desktop/src-tauri/src/db_backup.rs:65

/// Keep the last KEEP_BACKUPS matching prefix/.sqlite files in lexical filename order.

Comment 18, line 85

desktop/src-tauri/src/db_backup.rs:85

/// Open an old, possibly incompatible schema through a read-only connection.

Comment 19, line 94

desktop/src-tauri/src/db_backup.rs:94

/// VACUUM INTO snapshots the caller's current connection consistently.

Comment 20, line 95

desktop/src-tauri/src/db_backup.rs:95

/// Return its path, or None without backup when the database has no tables.

Comment 21, line 119

desktop/src-tauri/src/db_backup.rs:119

// Append an ordinal when the same-second name exists, avoiding overwrite.

Comment 22, line 138

desktop/src-tauri/src/db_backup.rs:138

/// Back up an incompatible old schema before rebuild deletes the original.

Comment 23, line 139

desktop/src-tauri/src/db_backup.rs:139

/// A direct read-only connection uses VACUUM INTO; Err must prevent original-file deletion.

Comment 24, line 245

desktop/src-tauri/src/db_backup.rs:245

// Open the consistent snapshot independently and close it after reading;

Comment 25, line 246

desktop/src-tauri/src/db_backup.rs:246

// an open SQLite connection on Windows can prevent prune from deleting the file.

Comment 26, line 255

desktop/src-tauri/src/db_backup.rs:255

// Five more timestamped backups leave the last three matching snapshots.