aboutsummaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/mod.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 824b3c71..51ffba9c 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -368,23 +368,31 @@ pub mod models;
/// Creates a back-up of the sqlite database
/// MySQL/MariaDB and PostgreSQL are not supported.
-pub async fn backup_database(conn: &mut DbConn) -> Result<(), Error> {
+pub async fn backup_database(conn: &mut DbConn) -> Result<String, Error> {
db_run! {@raw conn:
postgresql, mysql {
let _ = conn;
err!("PostgreSQL and MySQL/MariaDB do not support this backup feature");
}
sqlite {
- use std::path::Path;
- let db_url = CONFIG.database_url();
- let db_path = Path::new(&db_url).parent().unwrap().to_string_lossy();
- let file_date = chrono::Utc::now().format("%Y%m%d_%H%M%S").to_string();
- diesel::sql_query(format!("VACUUM INTO '{db_path}/db_{file_date}.sqlite3'")).execute(conn)?;
- Ok(())
+ backup_sqlite_database(conn)
}
}
}
+#[cfg(sqlite)]
+pub fn backup_sqlite_database(conn: &mut diesel::sqlite::SqliteConnection) -> Result<String, Error> {
+ use diesel::RunQueryDsl;
+ let db_url = CONFIG.database_url();
+ let db_path = std::path::Path::new(&db_url).parent().unwrap();
+ let backup_file = db_path
+ .join(format!("db_{}.sqlite3", chrono::Utc::now().format("%Y%m%d_%H%M%S")))
+ .to_string_lossy()
+ .into_owned();
+ diesel::sql_query(format!("VACUUM INTO '{backup_file}'")).execute(conn)?;
+ Ok(backup_file)
+}
+
/// Get the SQL Server version
pub async fn get_sql_server_version(conn: &mut DbConn) -> String {
db_run! {@raw conn: