about summary refs log tree commit diff
path: root/src/database.rs
diff options
context:
space:
mode:
authorRicky Kresslein <rk@lakoliu.com>2022-09-22 21:28:50 +0200
committerRicky Kresslein <rk@lakoliu.com>2022-09-22 21:28:50 +0200
commit83e992c2077a4fb5281a461c74fc6f7265a24bde (patch)
tree8f7199a9bf49fb41defd0c61e7d4fb307a74da30 /src/database.rs
parente72813df2bb343ec4ce683baa7af2befc1ae6f80 (diff)
downloadFurtherance-83e992c2077a4fb5281a461c74fc6f7265a24bde.tar.zst
Backup database
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)
+}