Add better informational messages

This commit is contained in:
Eduard Tolosa 2024-02-05 03:27:51 -05:00
parent ca4e96a662
commit 0a1beeb3b7
3 changed files with 13 additions and 13 deletions

View file

@ -49,14 +49,17 @@ pub fn manage_restoring(args: &mut Args, extra_args: &mut ExtraArgs) -> Result<(
args.dest_dir = snapshot_data.source; args.dest_dir = snapshot_data.source;
} }
} }
println!("Restoring the snapshot with ID {}", args.snapshot_id); println!(
println!("Name of the snapshot: {}", extra_args.snapshot_name); "Restoring snapshot {} to {}",
println!("Restoring snapshot to: {}", args.dest_dir); extra_args.snapshot_name, args.dest_dir
);
if !extra_args.snapshot_name.is_empty() if !extra_args.snapshot_name.is_empty()
&& operations::restore_snapshot(args, &extra_args.snapshot_name) && operations::restore_snapshot(args, &extra_args.snapshot_name)
{ {
println!("The snapshot was successfully restored"); println!("The snapshot was successfully restored");
} else {
eprintln!("Error while restoring the snapshot");
} }
Ok(()) Ok(())

View file

@ -21,9 +21,11 @@ fn try_run() -> Result<()> {
database_connection: arguments.database_connection(), database_connection: arguments.database_connection(),
}; };
arguments.init(&extra_args)?;
if arguments.create_snapshot { if arguments.create_snapshot {
arguments.check_for_source_and_dest_dir();
arguments.init(&extra_args)?;
// It's required to have a trailing slash for the source and destination directories. // It's required to have a trailing slash for the source and destination directories.
// Otherwise, when we retrieve the snapshot data from the database, we won't be able to // Otherwise, when we retrieve the snapshot data from the database, we won't be able to
// restore/delete the snapshot because the source/destination paths won't match. // restore/delete the snapshot because the source/destination paths won't match.
@ -34,7 +36,7 @@ fn try_run() -> Result<()> {
arguments.dest_dir += "/"; arguments.dest_dir += "/";
} }
// Now we need to make sure that the paths for source and destination are full paths. // We need to make sure that the paths for source and destination are full paths.
// If they are not, we will use the current working directory to build the full path. // If they are not, we will use the current working directory to build the full path.
if !Path::new(&arguments.source_dir).is_absolute() { if !Path::new(&arguments.source_dir).is_absolute() {
arguments.source_dir = std::env::current_dir()? arguments.source_dir = std::env::current_dir()?

View file

@ -37,14 +37,9 @@ pub fn del_snapshot(snapshot_name: &str) -> bool {
} }
pub fn restore_snapshot(args: &Args, snapshot_name: &str) -> bool { pub fn restore_snapshot(args: &Args, snapshot_name: &str) -> bool {
(!Path::new(&args.source_dir).exists() !Path::new(&args.dest_dir).exists()
|| Command::new("btrfs")
.args(["subvolume", "delete", &args.source_dir])
.status()
.expect("Error deleting the subvolume.")
.success())
&& Command::new("btrfs") && Command::new("btrfs")
.args(["subvolume", "snapshot", &snapshot_name, &args.source_dir]) .args(["subvolume", "snapshot", &snapshot_name, &args.dest_dir])
.status() .status()
.expect("Error restoring the snapshot.") .expect("Error restoring the snapshot.")
.success() .success()