From 83409641679e4a4536dfd5c1ec6db769817feb3d Mon Sep 17 00:00:00 2001 From: Martin Raiber Date: Sat, 24 Jul 2021 21:02:15 +0200 Subject: [PATCH] Fix partition resize --- urbackupclient/client_restore_http.cpp | 4 +-- urbackupclient/restorewww/src/Restoring.tsx | 32 +++++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/urbackupclient/client_restore_http.cpp b/urbackupclient/client_restore_http.cpp index 63bf4850..7d40a5b6 100644 --- a/urbackupclient/client_restore_http.cpp +++ b/urbackupclient/client_restore_http.cpp @@ -168,7 +168,7 @@ ACTION_IMPL(start_download) writestring("", out); } - Server->Log("Start_download: id = \""+std::to_string(img_id)+" time = \""+img_time+ "\"", LL_INFO); + Server->Log("Start_download: id = \""+std::to_string(img_id)+"\" time = \""+img_time+ "\"", LL_INFO); std::thread dl_thread([img_id, img_time, mbr, out, restore_res]() { restore_res->ec = restore::downloadImage(img_id, img_time, out, mbr, g_login_data, restore_res->dl_status); @@ -1091,7 +1091,7 @@ ACTION_IMPL(resize_part) int64 new_size = watoi64(POST["new_size"]); std::string out; - int rc = os_popen("parted -sm resizepart "+std::to_string(partnum)+" "+std::to_string(new_size*512)+"B 2>&1", out); + int rc = os_popen("parted \""+disk_fn+"\" -sm resizepart "+std::to_string(partnum)+" "+std::to_string(new_size*512)+"B 2>&1", out); JSON::Object ret; ret.set("ok", true); diff --git a/urbackupclient/restorewww/src/Restoring.tsx b/urbackupclient/restorewww/src/Restoring.tsx index 1caba329..986c99c5 100644 --- a/urbackupclient/restorewww/src/Restoring.tsx +++ b/urbackupclient/restorewww/src/Restoring.tsx @@ -106,10 +106,7 @@ function Restoring(props: WizardComponent) { } } - const restoreMBR = async () => { - setRestoreAction("MBR and GPT"); - setPercent(0); - + const getMBR = async (restoreImage: BackupImage) => { addLog("Loading MBR and GPT data..."); let jdata; @@ -117,8 +114,8 @@ function Restoring(props: WizardComponent) { const resp = await fetch("x?a=start_download", {method: "POST", body: new URLSearchParams({ - "img_id": ("" + props.props.restoreImage.id), - "img_time": ("" + props.props.restoreImage.time_s), + "img_id": ("" + restoreImage.id), + "img_time": ("" + restoreImage.time_s), "out": "/tmp/mbr.dat", "mbr": "1" })}); @@ -126,7 +123,7 @@ function Restoring(props: WizardComponent) { } catch(error) { addLog("Error while loading MBR"); setStatus("exception"); - return; + return false; } const mbr_res_id : number = jdata["res_id"]; @@ -144,7 +141,7 @@ function Restoring(props: WizardComponent) { } catch(error) { addLog("Error while checking MBR restore status"); setStatus("exception"); - return; + return false; } if(jdata["finished"]) { @@ -154,7 +151,7 @@ function Restoring(props: WizardComponent) { } else { addLog("Loading MBR failed: " + restoreEcToString(jdata["ec"])); setStatus("exception"); - return; + return false; } break; } else if(jdata["pc"]) { @@ -162,10 +159,22 @@ function Restoring(props: WizardComponent) { } } + return true; + } + + const restoreMBR = async () => { + setRestoreAction("MBR and GPT"); + setPercent(0); + + if(!await getMBR(props.props.restoreImage)) { + return; + } + addLog("Writing MBR and GPT to disk..."); setPercent(0); setStatus("normal"); + let jdata; try { const resp = await fetch("x?a=write_mbr", {method: "POST", @@ -282,6 +291,11 @@ function Restoring(props: WizardComponent) { let partpath: string; let partnum: number; if(!restoreToPartition) { + + if(!await getMBR(img)) { + return false; + } + addLog("Getting partition to restore to..."); let jdata; try {