use log::{LevelFilter, info}; use std::path::PathBuf; use structopt::StructOpt; mod backup; mod chunk_coordinate; mod config; mod discord; mod error; mod region; mod remote; mod restore; use crate::backup::{convert_backup_to_sp, do_backup}; use crate::chunk_coordinate::ChunkCoordinate; use crate::config::AlbatrossConfig; use crate::restore::{restore_chunk_from_backup, restore_range_from_backup}; #[derive(Debug, StructOpt)] #[structopt(about = "Backup your Minecraft Server!")] struct Albatross { /// Path to the Albatross config #[structopt(short, long, env = "ALBATROSS_CONFIG", parse(from_os_str))] config_path: PathBuf, /// Subcommand #[structopt(subcommand)] sub_command: SubCommand, } #[derive(Debug, StructOpt)] enum SubCommand { /// Backup a server Backup { /// Output path #[structopt(short = "o", long = "ouptut", parse(from_os_str))] output: Option, }, /// Export a backup as a single player world Export { /// Backup to convert #[structopt(parse(from_os_str))] input_backup: PathBuf, /// Output location override #[structopt(parse(from_os_str))] output: PathBuf, }, /// Restore certain chunks from a backup Restore { /// Output server directory #[structopt(short, long, parse(from_os_str))] server_directory: Option, /// World to restore world_name: String, /// Backup to restore from #[structopt(parse(from_os_str))] backup_path: PathBuf, /// Chunk to backup chunk: ChunkCoordinate, /// Upper chunk range bound #[structopt(short, long)] upper_bound: Option, }, } fn main() { env_logger::builder() .filter_level(LevelFilter::Info) .parse_default_env() .init(); let opt = Albatross::from_args(); let cfg = AlbatrossConfig::new(opt.config_path.into_os_string().to_str().unwrap()) .expect("Config error"); match opt.sub_command { SubCommand::Backup { output } => { info!("Starting backup"); match do_backup(cfg, output) { Ok(_) => info!("Backup complete!"), Err(e) => info!("Error doing backup: {e:?}"), }; } SubCommand::Export { input_backup, output, } => { info!("Starting export"); match convert_backup_to_sp(&cfg, &input_backup, &output) { Ok(_) => info!("Export complete!"), Err(e) => info!("Error exporting backup: {e:?}"), }; } SubCommand::Restore { server_directory, world_name, backup_path, chunk, upper_bound, } => { info!("Starting restore"); let server_directory = match server_directory { Some(dir) => dir, None => cfg.backup.minecraft_dir, }; if let Some(upper_bound) = upper_bound { match restore_range_from_backup( world_name.as_str(), chunk, upper_bound, &backup_path, &server_directory, ) { Ok(count) => info!("Restored {count} chunks!"), Err(e) => info!("Error restoring backup: {e:?}"), }; } else { match restore_chunk_from_backup( world_name.as_str(), chunk, &backup_path, &server_directory, ) { Ok(_) => info!("Restored chunk!"), Err(e) => info!("Error restoring backup: {e:?}"), }; } } } }