Skip to content

Commit

Permalink
use full paths for zfs and rsync
Browse files Browse the repository at this point in the history
  • Loading branch information
TimStallard committed Jan 31, 2020
1 parent f7a351e commit d429dae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion backup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .zfs import dataset_create, dataset_exists, dataset_mount, dataset_mounted

LOGGER = logging.getLogger(__name__)
RSYNC = "/usr/bin/rsync"


def backup_server(server: str) -> None:
Expand Down Expand Up @@ -52,7 +53,7 @@ def backup_server(server: str) -> None:
excludes = STANDARD_EXCLUDES + customexcludes

LOGGER.info(f"Starting rsync for {server}")
rsync = subprocess.run(["rsync",
rsync = subprocess.run([RSYNC,
"-e", "ssh -o 'StrictHostKeyChecking yes'",
# bail out if host key error, rather than prompting
"--compress",
Expand Down
16 changes: 9 additions & 7 deletions backup/zfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,47 @@
import subprocess
from typing import List

ZFS = "/sbin/zfs"


def dataset_exists(dataset: str) -> bool:
"""Checks if a dataset exists."""
return subprocess.call(["zfs", "list", dataset],
return subprocess.call([ZFS, "list", dataset],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL) == 0


def dataset_mounted(dataset: str) -> bool:
"""Checks if a dataset is mounted."""
mounted = subprocess.check_output(["zfs", "get", "-Hovalue", "mounted", dataset])
mounted = subprocess.check_output([ZFS, "get", "-Hovalue", "mounted", dataset])
return mounted == b"yes\n"


def dataset_mount(dataset: str) -> None:
"""Mounts a dataset."""
subprocess.check_call(["zfs", "mount", dataset],
subprocess.check_call([ZFS, "mount", dataset],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)


def dataset_create(dataset: str) -> None:
"""Creates a dataset."""
subprocess.check_call(["zfs", "create", dataset],
subprocess.check_call([ZFS, "create", dataset],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)


def dataset_snapshot(dataset: str, snap: str) -> None:
"""Creates a dataset."""
subprocess.check_call(["zfs", "snapshot", f"{dataset}@{snap}"],
subprocess.check_call([ZFS, "snapshot", f"{dataset}@{snap}"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
return True


def dataset_get_snapshots(dataset: str) -> List[str]:
"""Gets a list of snapshots for a dataset."""
output = subprocess.check_output(["zfs", "list",
output = subprocess.check_output([ZFS, "list",
"-t", "snapshot",
"-r", "-d1",
"-H", "-oname",
Expand All @@ -54,6 +56,6 @@ def dataset_get_snapshots(dataset: str) -> List[str]:

def dataset_destroy_snapshot(dataset: str, snap: str) -> None:
"""Destroys a snapshot."""
subprocess.check_call(["zfs", "destroy", f"{dataset}@{snap}"],
subprocess.check_call([ZFS, "destroy", f"{dataset}@{snap}"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)

0 comments on commit d429dae

Please sign in to comment.