fix: SystemZfs uses sudo for write ops (snapshot/destroy/clone/send)
This commit is contained in:
@@ -20,8 +20,8 @@ pub struct SystemZfs;
|
|||||||
impl ZfsOps for SystemZfs {
|
impl ZfsOps for SystemZfs {
|
||||||
fn snapshot(&self, dataset: &str, tag: &str) -> Result<()> {
|
fn snapshot(&self, dataset: &str, tag: &str) -> Result<()> {
|
||||||
let name = format!("{}@{}", dataset, tag);
|
let name = format!("{}@{}", dataset, tag);
|
||||||
let out = std::process::Command::new("zfs")
|
let out = std::process::Command::new("sudo")
|
||||||
.args(["snapshot", &name])
|
.args(["zfs", "snapshot", &name])
|
||||||
.output()
|
.output()
|
||||||
.context("running zfs snapshot")?;
|
.context("running zfs snapshot")?;
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
@@ -46,8 +46,8 @@ impl ZfsOps for SystemZfs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn delete_snapshot(&self, full_name: &str) -> Result<()> {
|
fn delete_snapshot(&self, full_name: &str) -> Result<()> {
|
||||||
let out = std::process::Command::new("zfs")
|
let out = std::process::Command::new("sudo")
|
||||||
.args(["destroy", full_name])
|
.args(["zfs", "destroy", full_name])
|
||||||
.output()
|
.output()
|
||||||
.context("running zfs destroy")?;
|
.context("running zfs destroy")?;
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
@@ -59,14 +59,14 @@ impl ZfsOps for SystemZfs {
|
|||||||
fn send_to_remote(&self, snapshot: &str, incremental_from: Option<&str>,
|
fn send_to_remote(&self, snapshot: &str, incremental_from: Option<&str>,
|
||||||
remote_user: &str, remote_host: &str,
|
remote_user: &str, remote_host: &str,
|
||||||
remote_dataset: &str) -> Result<()> {
|
remote_dataset: &str) -> Result<()> {
|
||||||
let mut send_args = vec!["send".to_string()];
|
let mut send_args = vec!["sudo".to_string(), "zfs".to_string(), "send".to_string()];
|
||||||
if let Some(prev) = incremental_from {
|
if let Some(prev) = incremental_from {
|
||||||
send_args.push("-i".to_string());
|
send_args.push("-i".to_string());
|
||||||
send_args.push(prev.to_string());
|
send_args.push(prev.to_string());
|
||||||
}
|
}
|
||||||
send_args.push(snapshot.to_string());
|
send_args.push(snapshot.to_string());
|
||||||
let cmd = format!(
|
let cmd = format!(
|
||||||
"zfs {} | ssh {}@{} zfs receive -F {}",
|
"{} | ssh {}@{} sudo zfs receive -F {}",
|
||||||
send_args.join(" "), remote_user, remote_host, remote_dataset
|
send_args.join(" "), remote_user, remote_host, remote_dataset
|
||||||
);
|
);
|
||||||
let out = std::process::Command::new("sh")
|
let out = std::process::Command::new("sh")
|
||||||
@@ -80,8 +80,8 @@ impl ZfsOps for SystemZfs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clone_snapshot(&self, snapshot: &str, dest_dataset: &str) -> Result<()> {
|
fn clone_snapshot(&self, snapshot: &str, dest_dataset: &str) -> Result<()> {
|
||||||
let out = std::process::Command::new("zfs")
|
let out = std::process::Command::new("sudo")
|
||||||
.args(["clone", snapshot, dest_dataset])
|
.args(["zfs", "clone", snapshot, dest_dataset])
|
||||||
.output()
|
.output()
|
||||||
.context("running zfs clone")?;
|
.context("running zfs clone")?;
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
|
|||||||
Reference in New Issue
Block a user