refactor: removed warnings and added sqlx offline data
This commit is contained in:
parent
a081744f8b
commit
6e391d2875
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT INTO Presets (id, description, config) VALUES ($1, $2, $3);",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "3bad8ca7685e12be00334129267685dcb9d365a2efd5e28a3d423c5e20fb2aa9"
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT INTO Backups (time, config, path, status) VALUES($1, $2, $3, $4) RETURNING id;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 4
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "44f8794faff536269fabe40149c7c3ca61615a27015ab256bb2f656522f77e9e"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "\n CREATE TABLE IF NOT EXISTS Backups (\n id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n time INTEGER NOT NULL,\n config TEXT NOT NULL,\n path TEXT NOT NULL,\n status TEXT NOT NULL\n );\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "696690d3ff3d908b024461d329fc71701821bd2da9a9689c7ca966cf1820e25e"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "UPDATE Backups SET status = $1 WHERE id = $2;",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "98b8070302ad60e069a0fca1a196186ca15f1b2f3a5f613bb8a79518c0ca97af"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "\n CREATE TABLE IF NOT EXISTS Presets (\n id VARCHAR(32) NOT NULL,\n description TEXT,\n config TEXT NOT NULL,\n\t PRIMARY KEY(id)\n );\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "b818d43e93cebcb4e4e1eacf21f9bf6381b63431b71db7faf8afb8444755f7aa"
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT * FROM Presets;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "config",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "c134c45fc0a42bfcfd7c2ac504822ee9fc1634bd7eaee23a90cac8519277dc0b"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "UPDATE Backups SET path = $1 WHERE id = $2;",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "d376ade8293ebf4fa6613619b53d2afc3bfbddf54bd4c9553eb654be6a51d797"
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT * FROM Backups;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"ordinal": 1,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "config",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "path",
|
||||
"ordinal": 3,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"ordinal": 4,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "e66fa65c7176524454b2a1a0387eff15f7f070a79831e2a1802261aeaac8263f"
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT * FROM Backups WHERE id = $1;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"ordinal": 1,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "config",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "path",
|
||||
"ordinal": 3,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"ordinal": 4,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "eb6915bb8b1a2c1d5d7aa56034da79d8e5f3682f846402bb59e9a6d497e0b94d"
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT * FROM Presets WHERE id = $1;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "config",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "f62b62651ece72dc8651d4ff7824d18b682fb916223d47a3a8f012a4bb8608d4"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "DELETE FROM Presets WHERE id = $1;",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "f8e9460c4c97456346b677a35d07eca81d9d0103f4d3a2632a98c59c2b90b16c"
|
||||
}
|
|
@ -19,7 +19,7 @@ pub async fn backup_create(
|
|||
BackupCreateRequest::Config(cfg) => cfg.into(),
|
||||
};
|
||||
|
||||
let backup = backup::Backup::new(pool, tx, config).await?;
|
||||
let _backup = backup::Backup::new(pool, tx, config).await?;
|
||||
|
||||
Ok(BackupCreateResponse::Success)
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ use anyhow::{bail, Context, Result};
|
|||
use log::{error, info};
|
||||
use sqlx::SqlitePool;
|
||||
use std::fs::File;
|
||||
use std::io::{copy, BufReader, Write};
|
||||
use std::io::{copy, BufReader};
|
||||
use std::path::Path;
|
||||
use tokio::sync::mpsc;
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
use walkdir::WalkDir;
|
||||
use zip::{write::FileOptions, CompressionMethod, ZipWriter};
|
||||
|
||||
fn add_dir_to_archive(
|
||||
|
@ -19,12 +19,11 @@ fn add_dir_to_archive(
|
|||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
let fname = entry.file_name();
|
||||
let ftype = entry.file_type();
|
||||
let file_type = entry.file_type();
|
||||
|
||||
if ftype.is_dir() {
|
||||
if file_type.is_dir() {
|
||||
archive.add_directory(entry.path().to_string_lossy(), options)?;
|
||||
} else if ftype.is_file() {
|
||||
} else if file_type.is_file() {
|
||||
archive.start_file(entry.path().to_string_lossy(), options)?;
|
||||
let mut reader = BufReader::new(File::open(entry.path())?);
|
||||
copy(&mut reader, archive)?;
|
||||
|
@ -33,7 +32,7 @@ fn add_dir_to_archive(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn perform_backup(backup: backup::Backup, pool: SqlitePool) -> Result<()> {
|
||||
fn perform_backup(backup: backup::Backup) -> Result<()> {
|
||||
let host = env!("NC_AW_HOST_PATH");
|
||||
let archive_file = File::create(&backup.path)?;
|
||||
let mut archive = ZipWriter::new(archive_file);
|
||||
|
@ -57,7 +56,7 @@ fn perform_backup(backup: backup::Backup, pool: SqlitePool) -> Result<()> {
|
|||
bail!("The config option 'mail_server' is not implemented yet!");
|
||||
}
|
||||
|
||||
if let Some(cfg) = &backup.config.docker {
|
||||
if let Some(_cfg) = &backup.config.docker {
|
||||
info!("Starting docker backup...");
|
||||
bail!("The config option 'docker' is not implemented yet!");
|
||||
}
|
||||
|
@ -87,10 +86,7 @@ pub async fn start(pool: SqlitePool) -> Result<mpsc::Sender<backup::Backup>> {
|
|||
.expect("Failed to set backup status!");
|
||||
|
||||
let cloned_backup = backup.clone();
|
||||
let cloned_pool = pool.clone();
|
||||
match tokio::task::spawn_blocking(|| perform_backup(cloned_backup, cloned_pool))
|
||||
.await?
|
||||
{
|
||||
match tokio::task::spawn_blocking(|| perform_backup(cloned_backup)).await? {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
tokio::fs::remove_file(backup.path).await?;
|
||||
|
|
Loading…
Reference in New Issue