feat: properly backup config directory
parent
640364405f
commit
f5fc8b588f
|
@ -1,2 +1,3 @@
|
||||||
[alias]
|
[alias]
|
||||||
runs = "run -- paper 1.19.4-545 --config data/config --backup data/backups --world data/worlds --jar data/paper.jar"
|
runs = "run -- paper 1.19.4-545 --config data/config --backup data/backups --world data/worlds --jar data/paper.jar"
|
||||||
|
runrs = "run --release -- paper 1.19.4-545 --config data/config --backup data/backups --world data/worlds --jar data/paper.jar"
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::server::ServerType;
|
||||||
use flate2::write::GzEncoder;
|
use flate2::write::GzEncoder;
|
||||||
use flate2::Compression;
|
use flate2::Compression;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Child;
|
use std::process::Child;
|
||||||
|
|
||||||
#[link(name = "c")]
|
#[link(name = "c")]
|
||||||
|
@ -108,11 +108,21 @@ impl ServerProcess {
|
||||||
|
|
||||||
tar.append_dir_all("worlds", &self.world_dir)?;
|
tar.append_dir_all("worlds", &self.world_dir)?;
|
||||||
|
|
||||||
// We don't store all files in the config, as this would include caches
|
// Add all files from the config directory that aren't the cache
|
||||||
tar.append_path_with_name(
|
for entry in self
|
||||||
self.config_dir.join("server.properties"),
|
.config_dir
|
||||||
"config/server.properties",
|
.read_dir()?
|
||||||
)?;
|
.filter_map(|e| e.ok())
|
||||||
|
.filter(|e| e.file_name() != "cache")
|
||||||
|
{
|
||||||
|
let tar_path = Path::new("config").join(entry.file_name());
|
||||||
|
|
||||||
|
if entry.file_type()?.is_dir() {
|
||||||
|
tar.append_dir_all(tar_path, entry.path())?;
|
||||||
|
} else {
|
||||||
|
tar.append_path_with_name(entry.path(), tar_path)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We add a file to the backup describing for what version it was made
|
// We add a file to the backup describing for what version it was made
|
||||||
let info = format!("{} {}", self.type_, self.version);
|
let info = format!("{} {}", self.type_, self.version);
|
||||||
|
@ -128,8 +138,6 @@ impl ServerProcess {
|
||||||
|
|
||||||
tar.append_data(&mut header, "info.txt", info_bytes)?;
|
tar.append_data(&mut header, "info.txt", info_bytes)?;
|
||||||
|
|
||||||
// tar.append_dir_all("config", &self.config_dir)?;
|
|
||||||
|
|
||||||
// Backup file gets finalized in the drop
|
// Backup file gets finalized in the drop
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -139,7 +147,9 @@ impl ServerProcess {
|
||||||
fn remove_old_backups(&mut self) -> std::io::Result<()> {
|
fn remove_old_backups(&mut self) -> std::io::Result<()> {
|
||||||
// The naming format used allows us to sort the backups by name and still get a sorting by
|
// The naming format used allows us to sort the backups by name and still get a sorting by
|
||||||
// creation time
|
// creation time
|
||||||
let mut backups = std::fs::read_dir(&self.backup_dir)?
|
let mut backups = self
|
||||||
|
.backup_dir
|
||||||
|
.read_dir()?
|
||||||
.filter_map(|res| res.map(|e| e.path()).ok())
|
.filter_map(|res| res.map(|e| e.path()).ok())
|
||||||
.collect::<Vec<PathBuf>>();
|
.collect::<Vec<PathBuf>>();
|
||||||
backups.sort();
|
backups.sort();
|
||||||
|
|
Loading…
Reference in New Issue