Removed FTPS backups and added FTP backups
+ Reverted to ftp 3.0.1 + fmt + clippybackup_error_fix
parent
249ad8dad8
commit
0ff76dec0a
|
@ -21,13 +21,22 @@ version = "1.0.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
|
||||
dependencies = [
|
||||
"memchr 0.1.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"memchr 2.3.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -35,13 +44,13 @@ name = "albatross"
|
|||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"anvil-region",
|
||||
"chrono",
|
||||
"chrono 0.4.19",
|
||||
"config",
|
||||
"discord-hooks-rs",
|
||||
"flate2",
|
||||
"ftp",
|
||||
"log",
|
||||
"regex",
|
||||
"regex 1.4.3",
|
||||
"reqwest",
|
||||
"serde 1.0.117",
|
||||
"ssh2",
|
||||
|
@ -159,6 +168,16 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.2.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00"
|
||||
dependencies = [
|
||||
"num",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.19"
|
||||
|
@ -338,13 +357,12 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
|||
[[package]]
|
||||
name = "ftp"
|
||||
version = "3.0.1"
|
||||
source = "git+https://github.com/joeyahines/rust-ftp.git#ab44662b5f27d18116a2721c1ddf76e117ed88be"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "542951aad0071952c27409e3bd7cb62d1a3ad419c4e7314106bf994e0083ad5d"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"lazy_static 1.4.0",
|
||||
"native-tls",
|
||||
"openssl",
|
||||
"regex",
|
||||
"chrono 0.2.25",
|
||||
"lazy_static 0.1.16",
|
||||
"regex 0.1.80",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -408,7 +426,7 @@ dependencies = [
|
|||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"memchr 2.3.3",
|
||||
"pin-project",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
|
@ -586,6 +604,12 @@ dependencies = [
|
|||
"winapi-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.2.11"
|
||||
|
@ -670,6 +694,15 @@ version = "0.1.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.3"
|
||||
|
@ -788,10 +821,21 @@ version = "4.2.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"memchr 2.3.3",
|
||||
"version_check 0.1.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
|
||||
dependencies = [
|
||||
"num-integer",
|
||||
"num-iter",
|
||||
"num-traits 0.2.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.42"
|
||||
|
@ -802,6 +846,17 @@ dependencies = [
|
|||
"num-traits 0.2.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-iter"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits 0.2.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.1.43"
|
||||
|
@ -1044,18 +1099,37 @@ version = "0.1.56"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "0.1.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
|
||||
dependencies = [
|
||||
"aho-corasick 0.5.3",
|
||||
"memchr 0.1.11",
|
||||
"regex-syntax 0.3.9",
|
||||
"thread_local 0.2.7",
|
||||
"utf8-ranges",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
"thread_local",
|
||||
"aho-corasick 0.7.10",
|
||||
"memchr 2.3.3",
|
||||
"regex-syntax 0.6.22",
|
||||
"thread_local 1.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.22"
|
||||
|
@ -1187,7 +1261,7 @@ dependencies = [
|
|||
"lazy_static 0.2.11",
|
||||
"linked-hash-map 0.3.0",
|
||||
"num-traits 0.1.43",
|
||||
"regex",
|
||||
"regex 1.4.3",
|
||||
"serde 0.8.23",
|
||||
]
|
||||
|
||||
|
@ -1358,6 +1432,25 @@ dependencies = [
|
|||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread-id"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
|
||||
dependencies = [
|
||||
"kernel32-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
|
||||
dependencies = [
|
||||
"thread-id",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.0.1"
|
||||
|
@ -1388,7 +1481,7 @@ dependencies = [
|
|||
"futures-core",
|
||||
"iovec",
|
||||
"lazy_static 1.4.0",
|
||||
"memchr",
|
||||
"memchr 2.3.3",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
|
@ -1496,6 +1589,12 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8-ranges"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.9"
|
||||
|
|
|
@ -19,4 +19,4 @@ reqwest = { version = "0.10", features = ["blocking", "json"] }
|
|||
discord-hooks-rs = { git = "https://github.com/joeyahines/discord-hooks-rs" }
|
||||
anvil-region = "0.4.0"
|
||||
ssh2 = "0.9.1"
|
||||
ftp = { git = "https://github.com/joeyahines/rust-ftp.git" , features=["secure", "native-tls"]}
|
||||
ftp = "3.0.1"
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::discord::send_webhook;
|
|||
use crate::error::Result;
|
||||
use crate::region::Region;
|
||||
use crate::remote::file::FileBackup;
|
||||
use crate::remote::ftps::FTPSBackup;
|
||||
use crate::remote::ftp::FTPBackup;
|
||||
use crate::remote::sftp::SFTPBackup;
|
||||
use crate::remote::RemoteBackupSite;
|
||||
use chrono::Utc;
|
||||
|
@ -254,13 +254,16 @@ pub fn do_remote_backup(
|
|||
remote_backup_cfg: &RemoteBackupConfig,
|
||||
backup_path: PathBuf,
|
||||
) -> Result<()> {
|
||||
if let Ok(mut sftp_backup) = SFTPBackup::new(remote_backup_cfg) {
|
||||
if remote_backup_cfg.sftp.is_some() {
|
||||
let mut sftp_backup = SFTPBackup::new(&remote_backup_cfg)?;
|
||||
sftp_backup.backup_to_remote(backup_path)?;
|
||||
sftp_backup.cleanup()?;
|
||||
} else if let Ok(mut ftps_backup) = FTPSBackup::new(remote_backup_cfg) {
|
||||
} else if remote_backup_cfg.ftp.is_some() {
|
||||
let mut ftps_backup = FTPBackup::new(&remote_backup_cfg)?;
|
||||
ftps_backup.backup_to_remote(backup_path)?;
|
||||
ftps_backup.cleanup()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod remote;
|
||||
|
||||
use crate::config::remote::{FTPSConfig, SFTPConfig};
|
||||
use crate::config::remote::{FTPConfig, SFTPConfig};
|
||||
use config::{Config, ConfigError, File};
|
||||
use serde::Deserialize;
|
||||
use std::path::PathBuf;
|
||||
|
@ -49,7 +49,7 @@ pub struct BackupConfig {
|
|||
pub struct RemoteBackupConfig {
|
||||
pub backups_to_keep: u64,
|
||||
pub sftp: Option<SFTPConfig>,
|
||||
pub ftps: Option<FTPSConfig>,
|
||||
pub ftp: Option<FTPConfig>,
|
||||
}
|
||||
|
||||
/// Configs
|
||||
|
|
|
@ -18,9 +18,9 @@ pub struct SFTPConfig {
|
|||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
/// FTPS Config
|
||||
/// FTP Config
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct FTPSConfig {
|
||||
pub struct FTPConfig {
|
||||
/// Remote server address
|
||||
pub server_addr: String,
|
||||
/// Remote output directory
|
||||
|
@ -29,6 +29,4 @@ pub struct FTPSConfig {
|
|||
pub username: String,
|
||||
/// Password
|
||||
pub password: String,
|
||||
/// Domain
|
||||
pub domain: Option<String>,
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ pub enum AlbatrossError {
|
|||
ChronoParseError(chrono::ParseError),
|
||||
NoSSHAuth,
|
||||
RemoteConfigError(String),
|
||||
FTPSError(ftp::FtpError),
|
||||
FTPError(ftp::FtpError),
|
||||
}
|
||||
|
||||
impl std::error::Error for AlbatrossError {}
|
||||
|
@ -28,7 +28,7 @@ impl std::fmt::Display for AlbatrossError {
|
|||
AlbatrossError::ChronoParseError(e) => write!(f, "Unable to parse time: {}", e),
|
||||
AlbatrossError::NoSSHAuth => write!(f, "No SSH auth methods provided in the config"),
|
||||
AlbatrossError::RemoteConfigError(e) => write!(f, "Invalid configuration for {}", e),
|
||||
AlbatrossError::FTPSError(e) => write!(f, "FTPS error: {}", e),
|
||||
AlbatrossError::FTPError(e) => write!(f, "FTP error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,6 @@ impl From<chrono::ParseError> for AlbatrossError {
|
|||
|
||||
impl From<ftp::FtpError> for AlbatrossError {
|
||||
fn from(e: ftp::FtpError) -> Self {
|
||||
AlbatrossError::FTPSError(e)
|
||||
AlbatrossError::FTPError(e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use ftp::native_tls::TlsConnector;
|
||||
use ftp::FtpStream;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
@ -7,8 +6,8 @@ use crate::error;
|
|||
use crate::error::AlbatrossError;
|
||||
use crate::remote::{PathLocation, RemoteBackupSite};
|
||||
|
||||
/// FTPS Remote Site
|
||||
pub struct FTPSBackup {
|
||||
/// FTP Remote Site
|
||||
pub struct FTPBackup {
|
||||
/// FTP command stream
|
||||
stream: FtpStream,
|
||||
/// Remote target directory
|
||||
|
@ -17,44 +16,39 @@ pub struct FTPSBackup {
|
|||
backups_to_keep: usize,
|
||||
}
|
||||
|
||||
impl FTPSBackup {
|
||||
/// New FTPSBackup
|
||||
impl FTPBackup {
|
||||
/// New FTPBackup
|
||||
pub fn new(config: &RemoteBackupConfig) -> error::Result<Self> {
|
||||
let ftps_config = config
|
||||
.ftps
|
||||
let ftp_config = config
|
||||
.ftp
|
||||
.as_ref()
|
||||
.ok_or_else(|| AlbatrossError::RemoteConfigError("FTPS".to_string()))?;
|
||||
.ok_or_else(|| AlbatrossError::RemoteConfigError("FTP".to_string()))?;
|
||||
|
||||
let ctx = TlsConnector::new().unwrap();
|
||||
let (ftp_stream, _) = FtpStream::connect(&ftps_config.server_addr)?;
|
||||
let mut ftp_stream = FtpStream::connect(&ftp_config.server_addr)?;
|
||||
|
||||
let domain = ftps_config
|
||||
.domain
|
||||
.as_ref()
|
||||
.map_or_else(|| "".to_string(), |s| s.clone());
|
||||
let mut ftp_stream = ftp_stream.into_secure(ctx, domain.as_str())?;
|
||||
ftp_stream.login(&ftps_config.username, &ftps_config.password)?;
|
||||
ftp_stream.login(&ftp_config.username, &ftp_config.password)?;
|
||||
|
||||
Ok(Self {
|
||||
stream: ftp_stream,
|
||||
target_dir: ftps_config.remote_dir.clone(),
|
||||
target_dir: ftp_config.remote_dir.clone(),
|
||||
backups_to_keep: config.backups_to_keep as usize,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FTPSBackup {
|
||||
impl Drop for FTPBackup {
|
||||
fn drop(&mut self) {
|
||||
self.stream.quit().ok();
|
||||
}
|
||||
}
|
||||
|
||||
impl RemoteBackupSite for FTPSBackup {
|
||||
impl RemoteBackupSite for FTPBackup {
|
||||
type FileType = PathLocation;
|
||||
|
||||
fn backup_to_remote(&mut self, file: PathBuf) -> error::Result<()> {
|
||||
let mut local_file = std::fs::File::open(&file)?;
|
||||
let location = self.target_dir.join(file);
|
||||
let location = self.target_dir.join(file.file_name().unwrap());
|
||||
|
||||
self.stream
|
||||
.put(location.to_str().unwrap(), &mut local_file)?;
|
||||
|
|
@ -5,7 +5,7 @@ use chrono::NaiveDateTime;
|
|||
use crate::error::Result;
|
||||
|
||||
pub mod file;
|
||||
pub mod ftps;
|
||||
pub mod ftp;
|
||||
pub mod sftp;
|
||||
|
||||
pub trait RemoteBackupFile {
|
||||
|
|
Loading…
Reference in New Issue