FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 28abf346 authored by Dr Adam Thorn's avatar Dr Adam Thorn
Browse files

Fully-qualify paths to zfs, zpool commands

We now e.g. have a cron job on cerebro-backup which calls
these scripts, where /sbin is not on the $PATH.
parent 82b033a3
No related branches found
Tags 0.9-ch63
No related merge requests found
......@@ -3,7 +3,7 @@ Priority: optional
Section: otherosfs
Maintainer: Frank Lee <rl201@cam.ac.uk>
Architecture: all
Version: 0.9-ch62
Version: 0.9-ch63
Depends: zfs-dkms, postgresql-9.5 | postgresql-9.4 , liblockfile-simple-perl, libdbi-perl, libjson-perl, libzfs-perl-chem, libnet-openssh-perl, libdbd-pg-perl, mbuffer, rsync, nfs-kernel-server, pv, libwww-curl-perl
Description: a backup system using ZFS
Ported (well, mostly) from FreeBSD to a Sane OS.
#!/bin/bash
# To create a new host in the database
ZFSCMD=/sbin/zfs
ZPOOLCMD=/sbin/zpool
if [ -z $1 ] ; then
echo Use: $0 hostname [flag [flag [...]]]
echo Known flags: postgres, mysql
......@@ -16,11 +19,11 @@ FQDN=`getent hosts $HN | awk ' { print $2 } '`
echo Searching for existing ZFS ...
# Find an existing ZFS for this host:
# Never use zroot
ZPS=` zpool list -H -o name | grep -v zroot`
ZPS=`$ZPOOLCMD list -H -o name | grep -v zroot`
TGT=''
for ZPOOL in $ZPS ; do
if [ -z $TGT ] ; then
if zfs list -H -o name $ZPOOL/$FQDN >/dev/null 2>&1 ; then
if $ZFSCMD list -H -o name $ZPOOL/$FQDN >/dev/null 2>&1 ; then
TGT=$ZPOOL/$FQDN
fi
fi
......@@ -33,15 +36,15 @@ done
if [ -z $TGT ] ; then
echo No existing ZFS found
# Find emptiest zpool
ZPOOL=`zfs list -H -oname -S avail -d0 | grep -v zroot | head -n1`
ZPOOL=`$ZFSCMD list -H -oname -S avail -d0 | grep -v zroot | head -n1`
TGT=$ZPOOL/$FQDN
echo Using $ZPOOL
fi
function ensurezfs() {
ZFS=$1
if ! zfs list $ZFS >/dev/null 2>&1; then
zfs create $ZFS
if ! $ZFSCMD list $ZFS >/dev/null 2>&1; then
$ZFSCMD create $ZFS
fi
}
......@@ -129,7 +132,7 @@ function getsshkey() {
HOSTID=`ensurehost $FQDN`
echo Host ID is $HOSTID
ensurezfs $TGT
zfs set sharenfs=ro=${FQDN},no_root_squash $TGT
$ZFSCMD set sharenfs=ro=${FQDN},no_root_squash $TGT
# Do root backup
backupdir $FQDN $TGT/zfs-rsnap /
......
......@@ -2,10 +2,13 @@
# To create a new backup task in the database, perhaps to back up a particular directory
# on an existing machine.
ZFSCMD=/sbin/zfs
ZPOOLCMD=/sbin/zpool
function ensurezfs() {
ZFS=$(echo $1| sed 's@//*@/@g')
if ! zfs list $ZFS >/dev/null 2>&1; then
zfs create -p $ZFS
if ! $ZFSCMD list $ZFS >/dev/null 2>&1; then
$ZFSCMD create -p $ZFS
fi
}
......@@ -109,11 +112,11 @@ FQDN=`getent hosts $HN | awk ' { print $2 } '`
echo Searching for existing ZFS ...
# Find an existing ZFS for this host and directory:
# Never use zroot
ZPS=` zpool list -H -o name | grep -v zroot`
ZPS=`$ZPOOLCMD list -H -o name | grep -v zroot`
TGT=''
for Z in $ZPS ; do
if [ -z $TGT ] ; then
if zfs list -H -o name $Z/${FQDN}${BACKUP_PATH} >/dev/null 2>&1 ; then
if $ZFSCMD list -H -o name $Z/${FQDN}${BACKUP_PATH} >/dev/null 2>&1 ; then
TGT=$Z/${FQDN}${BACKUP_PATH}
fi
fi
......@@ -125,8 +128,8 @@ done
if [ -z $TGT ] ; then
echo No existing ZFS found
if [ -z "$ZPOOL" ] ; then
# Find emptiest zpool
ZPOOL=`zfs list -H -oname -S avail -d0 | grep -v zroot | head -n1`
# Find emptiest zpool. We have to use $ZFSCMD in order to sort via "-S avail"
ZPOOL=`$ZFSCMD list -H -oname -S avail -d0 | grep -v zroot | head -n1`
fi
TGT=$ZPOOL/$FQDN/${BACKUP_PATH}
echo Using $ZPOOL
......@@ -136,12 +139,12 @@ TGT=$(echo $TGT | sed 's@//*@/@g')
HOSTID=`ensurehost $FQDN`
echo Host ID is $HOSTID
ensurezfs $TGT
zfs set sharenfs=ro=${FQDN},no_root_squash $TGT
$ZFSCMD set sharenfs=ro=${FQDN},no_root_squash $TGT
# Create the backup task
backupdir $FQDN $TGT ${BACKUP_PATH}
# set ssh key in known_hosts
getsshkey $FQDN
zfs set quota=${QUOTA} $TGT
$ZFSCMD set quota=${QUOTA} $TGT
dosql "update host set disabled=false where hostname='$FQDN';"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment