From 83e992c2077a4fb5281a461c74fc6f7265a24bde Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Thu, 22 Sep 2022 21:28:50 +0200 Subject: Backup database --- src/database.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/database.rs') diff --git a/src/database.rs b/src/database.rs index 6c2649c..090814e 100755 --- a/src/database.rs +++ b/src/database.rs @@ -16,10 +16,11 @@ use chrono::{DateTime, Local}; use directories::ProjectDirs; -use rusqlite::{Connection, Result}; +use rusqlite::{Connection, Result, backup}; use std::convert::TryFrom; use std::fs::create_dir_all; use std::path::PathBuf; +use std::time::Duration; #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct Task { @@ -337,3 +338,10 @@ pub fn delete_all() -> Result<()> { Ok(()) } + +pub fn backup_db(backup_file: String) -> Result<()> { + let mut bkup_conn = Connection::open(backup_file)?; + let conn = Connection::open(get_directory())?; + let backup = backup::Backup::new(&conn, &mut bkup_conn)?; + backup.run_to_completion(5, Duration::from_millis(250), None) +} -- cgit 1.4.1