mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-11-28 21:18:11 -05:00
add some mutation flags to moonfire-nvr check
For recovering from corruption, as in #107. These should aid in restoring database integrity without throwing away the entire database. I only added the conditions that came up in #107, so far. * "Missing ... row" => --trash-orphan-sample-files * "Recording ... missing file" => --delete-orphan-rows * "bad video_index" => --trash-corrupt-rows
This commit is contained in:
@@ -45,12 +45,35 @@ pub struct Args {
|
||||
/// Compare sample file lengths on disk to the database.
|
||||
#[structopt(long)]
|
||||
compare_lens: bool,
|
||||
|
||||
/// Trash sample files without matching recording rows in the database.
|
||||
/// This addresses "Missing ... row" errors.
|
||||
///
|
||||
/// The ids are added to the "garbage" table to indicate the files need to
|
||||
/// be deleted. Garbage is collected on normal startup.
|
||||
#[structopt(long)]
|
||||
trash_orphan_sample_files: bool,
|
||||
|
||||
/// Delete recording rows in the database without matching sample files.
|
||||
/// This addresses "Recording ... missing file" errors.
|
||||
#[structopt(long)]
|
||||
delete_orphan_rows: bool,
|
||||
|
||||
/// Trash recordings when their database rows appear corrupt.
|
||||
/// This addresses "bad video_index" errors.
|
||||
///
|
||||
/// The ids are added to the "garbage" table to indicate their files need to
|
||||
/// be deleted. Garbage is collected on normal startup.
|
||||
#[structopt(long)]
|
||||
trash_corrupt_rows: bool,
|
||||
}
|
||||
|
||||
pub fn run(args: &Args) -> Result<i32, Error> {
|
||||
// TODO: ReadOnly should be sufficient but seems to fail.
|
||||
let (_db_dir, conn) = super::open_conn(&args.db_dir, super::OpenMode::ReadWrite)?;
|
||||
check::run(&conn, &check::Options {
|
||||
let (_db_dir, mut conn) = super::open_conn(&args.db_dir, super::OpenMode::ReadWrite)?;
|
||||
check::run(&mut conn, &check::Options {
|
||||
compare_lens: args.compare_lens,
|
||||
trash_orphan_sample_files: args.trash_orphan_sample_files,
|
||||
delete_orphan_rows: args.delete_orphan_rows,
|
||||
trash_corrupt_rows: args.trash_corrupt_rows,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user