diff --git a/README.md b/README.md index 74d752f..81b94db 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ ### Launch Axum -In directory /backend type: +In directory */backend* type: ```$> cargo run``` Then browse http://127.0.0.1:8082 (You need to compile the wasm file first, see section *Frontend*) -At first launch the configuration file '/backend/conf.ron' is created. It contains the port the server will listen to and information about the SMTP server which will be used to send email when a user sign up or change its password. +At first launch the configuration file `/backend/conf.ron` is created. It contains the port the server will listen to and information about the SMTP server which will be used to send email when a user sign up or change its password. ### Autoreload @@ -20,7 +20,7 @@ First install cargo watch: ```$> cargo install cargo-watch``` -In directory /backend type: +In directory */backend* type: ```$> cargo watch -x run``` @@ -33,11 +33,11 @@ trunk: https://trunkrs.dev ### Compilation -In directory /frontend type: +In directory */frontend* type: ```$> trunk build``` -It will create the wasm file in '/backend/static'. +It will create the wasm file in */backend/static*. You can now refresh your browser to reload the wasm file. # How-to @@ -46,7 +46,7 @@ You can now refresh your browser to reload the wasm file. As root: -1. Copy '/doc/recipes.service' to '/lib/systemd/system/' +1. Copy */doc/recipes.service* to */lib/systemd/system/* 2. Change the values of `User`, `WorkingDirectory` and `ExecStart`. 2. Enabled it: `#> systemctl enable recipes` 3. Launch it: `#> systemctl start recipes` diff --git a/backend/Cargo.toml b/backend/Cargo.toml index e399a92..6814a62 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -27,8 +27,10 @@ clap = { version = "4", features = ["derive"] } sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "chrono"] } +async-compression = { version = "0.4", features = ["tokio", "gzip"] } + askama = "0.13" -comrak = "0.37" +comrak = "0.38" argon2 = { version = "0.5", features = ["default", "std"] } rand_core = { version = "0.9", features = ["std"] } diff --git a/backend/src/data/backup.rs b/backend/src/data/backup.rs index 3935567..83b32a8 100644 --- a/backend/src/data/backup.rs +++ b/backend/src/data/backup.rs @@ -1,4 +1,6 @@ +use async_compression::tokio::bufread::GzipEncoder; use chrono::{NaiveTime, TimeDelta}; +use tokio::{fs::File, io::BufReader}; use tracing::{Level, event}; use super::db; @@ -44,11 +46,60 @@ where path.display() ); - if let Err(error) = db_connection.backup(path).await { + if let Err(error) = db_connection.backup(&path).await { event!(Level::ERROR, "Error when backing up database: {}", error); } - event!(Level::INFO, "Backup done"); + // Compress the backup file. + match File::open(&path).await { + Ok(file_input) => { + let buf_reader = BufReader::new(file_input); + let mut encoder = GzipEncoder::new(buf_reader); + let path_compressed = path.with_extension("sqlite.gz"); + match File::create(&path_compressed).await { + Ok(mut file_output) => { + if let Err(error) = + tokio::io::copy(&mut encoder, &mut file_output).await + { + event!( + Level::ERROR, + "Error when compressing backup file: {}", + error + ); + } else { + match std::fs::remove_file(&path) { + Ok(()) => event!( + Level::INFO, + "Backup done: {}", + path_compressed.display() + ), + Err(error) => { + event!( + Level::ERROR, + "Error when removing uncompressed backup file: {}", + error + ); + } + } + } + } + Err(error) => { + event!( + Level::ERROR, + "Error when creating compressed backup file: {}", + error + ); + } + } + } + Err(error) => { + event!( + Level::ERROR, + "Error when opening backup file for compression: {}", + error + ); + } + } } }) }