mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-06-07 11:33:57 +00:00
Create Backup funcitonality
Added create backup functionality to the admin panel
This commit is contained in:
parent
5521a86693
commit
ef551f4cc6
3 changed files with 44 additions and 1 deletions
|
@ -9,6 +9,11 @@ use rocket::http::Status;
|
|||
use rocket::request::{self, FromRequest};
|
||||
use rocket::{Outcome, Request, State};
|
||||
|
||||
use std::process::Command;
|
||||
use chrono::prelude::*;
|
||||
use crate::error::Error;
|
||||
|
||||
|
||||
use crate::CONFIG;
|
||||
|
||||
/// An alias to the database connection used
|
||||
|
@ -34,6 +39,21 @@ pub fn get_connection() -> Result<Connection, ConnectionError> {
|
|||
Connection::establish(&CONFIG.database_url())
|
||||
}
|
||||
|
||||
/// Creates a back-up of the database using sqlite3
|
||||
pub fn backup_database() -> Result<(), Error> {
|
||||
let now: DateTime<Utc> = Utc::now();
|
||||
let file_date = String::from(now.format("%Y%m%d").to_string());
|
||||
let backup_command: String = format!("{}{}{}", ".backup 'db_", file_date, ".sqlite3'");
|
||||
|
||||
Command::new("sqlite3")
|
||||
.current_dir("./data")
|
||||
.args(&["db.sqlite3", &backup_command])
|
||||
.output()
|
||||
.expect("Can't open database, sqlite3 is not available, make sure it's installed and available on the PATH");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Attempts to retrieve a single connection from the managed database pool. If
|
||||
/// no pool is currently managed, fails with an `InternalServerError` status. If
|
||||
/// no connections are available, fails with a `ServiceUnavailable` status.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue