Adrian Heine
5 years ago
35 changed files with 142 additions and 236 deletions
-
8src/command_runner.rs
-
14src/factory.rs
-
32src/lib.rs
-
2src/loggers.rs
-
23src/schema.rs
-
2src/storage.rs
-
6src/symbols/acme/account_key.rs
-
8src/symbols/acme/cert.rs
-
6src/symbols/acme/chain.rs
-
2src/symbols/acme/mod.rs
-
4src/symbols/cron.rs
-
16src/symbols/factory.rs
-
6src/symbols/git/checkout.rs
-
6src/symbols/git/submodules.rs
-
8src/symbols/list.rs
-
6src/symbols/mariadb/database.rs
-
4src/symbols/mariadb/database_dump.rs
-
4src/symbols/mariadb/user.rs
-
2src/symbols/mod.rs
-
22src/symbols/nginx/server.rs
-
4src/symbols/npm.rs
-
4src/symbols/owner.rs
-
8src/symbols/postgresql/database.rs
-
75src/symbols/postgresql/database_dump.rs
-
2src/symbols/postgresql/mod.rs
-
6src/symbols/stored_directory.rs
-
4src/symbols/systemd/reload.rs
-
20src/symbols/systemd/user_service.rs
-
10src/symbols/systemd/user_session.rs
-
4src/symbols/tls/csr.rs
-
6src/symbols/tls/key.rs
-
4src/symbols/tls/self_signed_cert.rs
-
26src/symbols/user.rs
-
6src/symbols/wordpress/plugin.rs
-
18src/symbols/wordpress/translation.rs
@ -1,75 +0,0 @@ |
|||||
use std::error::Error;
|
|
||||
use std::fmt;
|
|
||||
use std::str::FromStr;
|
|
||||
|
|
||||
use crate::command_runner::CommandRunner;
|
|
||||
use crate::storage::Storage;
|
|
||||
use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
|
||||
|
|
||||
pub struct DatabaseDump<'a, N: AsRef<str>, C: CommandRunner, S: Storage> {
|
|
||||
db_name: N,
|
|
||||
storage: S,
|
|
||||
command_runner: &'a C,
|
|
||||
}
|
|
||||
|
|
||||
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> {
|
|
||||
pub fn new(db_name: N, storage: S, command_runner: &'a C) -> Self {
|
|
||||
DatabaseDump {
|
|
||||
db_name,
|
|
||||
storage,
|
|
||||
command_runner,
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
|
|
||||
let b = self
|
|
||||
.command_runner
|
|
||||
.get_output("mariadb", args!["--skip-column-names", "-B", "-e", sql])?;
|
|
||||
Ok(String::from_utf8(b)?)
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'a, N, C, S> {
|
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||
write!(f, "Dump MariaDB Database {}", self.db_name.as_ref())
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> {
|
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
|
||||
let dump_date = self.storage.recent_date()?;
|
|
||||
let modified_date = self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref()))?;
|
|
||||
if modified_date.trim_end() == "NULL" {
|
|
||||
return Ok(false);
|
|
||||
}
|
|
||||
Ok(u64::from_str(modified_date.trim_end())? <= dump_date)
|
|
||||
}
|
|
||||
|
|
||||
fn execute(&self) -> Result<(), Box<dyn Error>> {
|
|
||||
self.command_runner.run_successfully(
|
|
||||
"sh",
|
|
||||
args![
|
|
||||
"-c",
|
|
||||
format!(
|
|
||||
"mysqldump '{}' > {}",
|
|
||||
self.db_name.as_ref(),
|
|
||||
self.storage.write_filename()
|
|
||||
),
|
|
||||
],
|
|
||||
)
|
|
||||
}
|
|
||||
|
|
||||
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
|
|
||||
Box::new(SymbolAction::new(runner, self))
|
|
||||
}
|
|
||||
|
|
||||
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b>
|
|
||||
where
|
|
||||
Self: 'b,
|
|
||||
{
|
|
||||
Box::new(OwnedSymbolAction::new(runner, *self))
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
#[cfg(test)]
|
|
||||
mod test {}
|
|
@ -1,5 +1,3 @@ |
|||||
mod database;
|
mod database;
|
||||
mod database_dump;
|
|
||||
|
|
||||
pub use self::database::PostgreSQLDatabase;
|
pub use self::database::PostgreSQLDatabase;
|
||||
//pub use self::database_dump::PostgreSQLDump;
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue