120 lines
3.9 KiB
Rust
120 lines
3.9 KiB
Rust
use std::path::PathBuf;
|
|
use structopt::StructOpt;
|
|
|
|
mod backup;
|
|
mod config;
|
|
mod discord;
|
|
mod region;
|
|
mod restore;
|
|
|
|
use crate::backup::{convert_backup_to_sp, do_backup};
|
|
use crate::config::AlbatrossConfig;
|
|
use crate::restore::{restore_range_from_backup, restore_chunk_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<PathBuf>,
|
|
},
|
|
/// 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<PathBuf>,
|
|
/// World to restore
|
|
world_name: String,
|
|
/// Backup to restore from
|
|
#[structopt(parse(from_os_str))]
|
|
backup_path: PathBuf,
|
|
/// Backup range can be a single chunk coordinate pair or a chunk range
|
|
chunk_range: Vec<i32>,
|
|
},
|
|
}
|
|
|
|
fn main() {
|
|
let opt = Albatross::from_args();
|
|
|
|
let cfg = AlbatrossConfig::new(opt.config_path.into_os_string().to_str().unwrap())
|
|
.expect("Config not found");
|
|
|
|
if cfg.world_config.is_some() {
|
|
match opt.sub_command {
|
|
SubCommand::Backup { output } => {
|
|
println!("Starting backup");
|
|
match do_backup(cfg, output) {
|
|
Ok(_) => println!("Backup complete!"),
|
|
Err(e) => println!("Error doing backup: {:?}", e),
|
|
};
|
|
}
|
|
SubCommand::Export {
|
|
input_backup,
|
|
output,
|
|
} => {
|
|
println!("Starting export");
|
|
match convert_backup_to_sp(&cfg, &input_backup, &output) {
|
|
Ok(_) => println!("Export complete!"),
|
|
Err(e) => println!("Error exporting backup: {:?}", e),
|
|
};
|
|
}
|
|
SubCommand::Restore {
|
|
server_directory,
|
|
world_name,
|
|
backup_path,
|
|
chunk_range
|
|
} => {
|
|
println!("Starting restore");
|
|
|
|
let server_directory = match server_directory {
|
|
Some(dir) => dir,
|
|
None => cfg.backup.minecraft_dir
|
|
};
|
|
|
|
if chunk_range.len() > 2 {
|
|
let lower_x = chunk_range[0];
|
|
let lower_z = chunk_range[1];
|
|
let upper_x = chunk_range[2];
|
|
let upper_z = chunk_range[3];
|
|
match restore_range_from_backup(world_name.as_str(), lower_x, upper_x, lower_z, upper_z, &backup_path, &server_directory) {
|
|
Ok(count) => println!("Restored {} chunks!", count),
|
|
Err(e) => println!("Error restoring backup: {:?}", e),
|
|
};
|
|
}
|
|
else if chunk_range.len() == 2 {
|
|
let x = chunk_range[0];
|
|
let z = chunk_range[1];
|
|
match restore_chunk_from_backup(world_name.as_str(), x, z, &backup_path, &server_directory) {
|
|
Ok(_) => println!("Restored chunk!"),
|
|
Err(e) => println!("Error restoring backup: {:?}", e),
|
|
};
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
println!("No worlds specified in config file!")
|
|
}
|
|
}
|