about summary refs log tree commit diff
path: root/src/database.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.rs')
-rwxr-xr-xsrc/database.rs10
1 files changed, 9 insertions, 1 deletions
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)
+}