Cleanup and modernize

+ Bump to rust 2024
+ Cleaned up old code
+ Added more fail safes in case certain files are missing
This commit is contained in:
joeyahines committed 2025-07-26 13:14:52 -06:00
1 parent 8378f2ead3
commit a9cf1d5c6f
13 files changed
+1999 -864

No files matched your search

+1 -1
View File
@@ -1,9 +1,9 @@
use ftp::FtpStream;
use std::path::PathBuf;
use crate::config::remote::FTPConfig;
use crate::error;
use crate::remote::{PathLocation, RemoteBackupSite};
use crate::config::remote::FTPConfig;
/// FTP Remote Site
pub struct FTPBackup {
+10 -13
View File
@@ -8,6 +8,7 @@ pub mod file;
pub mod ftp;
pub mod sftp;
#[allow(dead_code)]
pub trait RemoteBackupFile {
/// Type containing the location of the remote_backup backup
type LocationType;
@@ -16,14 +17,14 @@ pub trait RemoteBackupFile {
fn location(&self) -> Self::LocationType;
/// Get the time the remote_backup file was created
fn time_created(&self) -> chrono::NaiveDateTime;
fn time_created(&self) -> NaiveDateTime;
/// Parse the time created from the file name
fn parse_file_name(file_name: &str) -> Option<chrono::NaiveDateTime> {
fn parse_file_name(file_name: &str) -> Option<NaiveDateTime> {
let time: Vec<&str> = file_name.split("_backup.tar.gz").collect();
if let Some(time_str) = time.get(0) {
chrono::NaiveDateTime::parse_from_str(time_str, "%d-%m-%y_%H.%M.%S").ok()
if let Some(time_str) = time.first() {
NaiveDateTime::parse_from_str(time_str, "%d-%m-%y_%H.%M.%S").ok()
} else {
None
}
@@ -34,7 +35,7 @@ pub trait RemoteBackupSite {
/// Struct representing the location of a backup on the site
type FileType: RemoteBackupFile;
/// Backup a file to the the remote_backup site
/// Backup a file to the remote_backup site
fn backup_to_remote(&mut self, file: PathBuf) -> Result<()>;
/// Get the locations backups contained on the remote_backup site
@@ -80,14 +81,10 @@ impl PathLocation {
if let Some(file_name) = path.file_name() {
let file_name = file_name.to_str().unwrap();
if let Some(time) = Self::parse_file_name(file_name) {
Some(Self {
location: path,
time_created: time,
})
} else {
None
}
Self::parse_file_name(file_name).map(|time| Self {
location: path,
time_created: time,
})
} else {
None
}
+2 -2
View File
@@ -3,10 +3,10 @@ use std::path::PathBuf;
use ssh2::Session;
use crate::config::remote::SFTPConfig;
use crate::error;
use crate::error::AlbatrossError;
use crate::remote::{PathLocation, RemoteBackupSite};
use crate::config::remote::SFTPConfig;
/// SFTP Remote Site
pub struct SFTPBackup {
@@ -69,7 +69,7 @@ impl RemoteBackupSite for SFTPBackup {
}
fn remove_backup(&mut self, backup: Self::FileType) -> error::Result<()> {
Ok(self.session.sftp()?.unlink(&*backup.location)?)
Ok(self.session.sftp()?.unlink(&backup.location)?)
}
fn backups_to_keep(&self) -> usize {