diff options
Diffstat (limited to 'backup')
-rw-r--r-- | backup/src/main.rs | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/backup/src/main.rs b/backup/src/main.rs index 2f5f06a..6981389 100644 --- a/backup/src/main.rs +++ b/backup/src/main.rs @@ -31,7 +31,10 @@ struct Config { timestamp_file: String, source_file: String, exclude_file: String, - cycles: Option<u32> + cycles: Option<u32>, + zstd_level: Option<u8>, + zstd_threads: Option<u8>, + skip_db: Option<bool> } fn read_lines<P: AsRef<Path>>(path: P) -> Result<Vec<String>, Box<dyn Error>> { @@ -70,6 +73,9 @@ fn main() -> Result<(), Box<dyn Error>> { let timestamp_file = Path::new(&config.timestamp_file); let source_list = read_lines(&config.source_file)?; let exclude_list = read_lines(&config.exclude_file)?; + let zstd_level = config.zstd_level.unwrap_or(9).clamp(1, 19); + let zstd_threads = config.zstd_threads.unwrap_or(1); + let zstd_cmd = format!("zstd -{} -T{}", zstd_level, zstd_threads); fs::create_dir_all(backup_dir)?; @@ -109,22 +115,27 @@ fn main() -> Result<(), Box<dyn Error>> { println!("INFO: Backup-Rotation durchgeführt"); } - // Dump 1 - let dump1 = rotate_subdir.join("backup_mastodon-db-1.sql.zst"); - cmd!("docker", "exec", "mastodon-db-1", "pg_dumpall", "-U", "postgres") - .pipe(cmd!("zstd", "-9")) - .stdout_file(File::create(dump1)?) - .run()?; - - // Dump 2 - let dump2 = rotate_subdir.join("backup_db.sql.zst"); - cmd!("pg_dumpall", "-U", "postgres") - .pipe(cmd!("zstd", "-9")) - .stdout_file(File::create(dump2)?) - .run()?; - - if args.verbose { - println!("INFO: Datenbank-Dumps gespeichert"); + // Nur wenn skip_db != true + if config.skip_db.unwrap_or(false) == false { + // Dump 1 + let dump1 = rotate_subdir.join("backup_mastodon-db-1.sql.zst"); + cmd!("docker", "exec", "mastodon-db-1", "pg_dumpall", "-U", "postgres") + .pipe(cmd!("sh", "-c", &zstd_cmd)) + .stdout_file(File::create(dump1)?) + .run()?; + + // Dump 2 + let dump2 = rotate_subdir.join("backup_db.sql.zst"); + cmd!("pg_dumpall", "-U", "postgres") + .pipe(cmd!("sh", "-c", &zstd_cmd)) + .stdout_file(File::create(dump2)?) + .run()?; + + if args.verbose { + println!("INFO: Datenbank-Dumps gespeichert"); + } + } else if args.verbose { + println!("INFO: Datenbank-Dumps wurden übersprungen (skip_db_dumps=true)"); } } @@ -140,7 +151,7 @@ fn main() -> Result<(), Box<dyn Error>> { tar_cmd .arg("-cvp") .arg("-I") - .arg("zstd -9 -T1") + .arg(zstd_cmd) .arg("-f") .arg(&backup_path) .arg("-g") |