1#!/bin/bash 2. lib/config.sh 3. lib/functions.sh 4 5# Test script specific functions 6delete_pool_if_exists() { 7 if $ZPOOL list -H -o name | grep "^$1$" > /dev/null; then 8 if yesno "About to destroy zpool $1. OK to destroy?"; then 9 log "Destroying $1" 10 $ZPOOL destroy $1 11 else 12 log "Not destroying $1" 13 fi 14 fi 15} 16 17create_zpool() { 18 local FILENAME 19 FILENAME=/var/tmp/$1.zpool 20 log "Removing $FILENAME if it exists" 21 rm -f $FILENAME 22 log "Making $POOLSIZE file $FILENAME" 23 mkfile $POOLSIZE $FILENAME 24 log "Making new file based zpool: $1 on $FILENAME" 25 $ZPOOL create $1 $FILENAME 26} 27 28create_zfs() { 29 log "Creating zfs filesystem $1" 30 `$ZFS create $1` 31} 32 33create_test_filesystems() { 34 create_zfs $SRCPOOL/test 35 create_zfs $SRCPOOL/test/foo 36 create_zfs $SRCPOOL/test/foo/bar 37 create_zfs $SRCPOOL/test/baz 38 zetaback_setclass $SRCPOOL/test/baz testclass 39} 40 41generate_zetaback_conf() { 42 log "Generating zetaback config" 43 cat > zetaback_test.conf <<EOF 44default { 45 store = /$DSTPOOL/%h 46 archive = /$DSTPOOL/archives 47 agent = "$PWD/../zetaback_agent -c $PWD/zetaback_agent_test.conf" 48 backup_interval = 10 49 full_interval = 604800 50} 51 52testclass { 53 type = class 54 store = /$DSTPOOL/classy/%h 55} 56 57$HOSTNAME { } 58EOF 59} 60 61generate_zetaback_agent_conf() { 62 log "Generating zetaback agent config" 63 cat > zetaback_agent_test.conf <<EOF 64pattern=(?:$SRCPOOL/test) 65EOF 66} 67 68run_zetaback() { 69 OPTIONS="-d -b -c $PWD/zetaback_test.conf" 70 log "Running zetaback $OPTIONS" 71 $ZETABACK $OPTIONS 2>&1 | tee -a $LOGFILE 72} 73 74zetaback_ignore() { 75 log "Setting zetaback ignore user property on $1" 76 `zfs set com.omniti.labs.zetaback:exclude=on $1` 77} 78 79zetaback_setclass() { 80 log "Setting zetaback class property on $1 to $2" 81 `zfs set com.omniti.labs.zetaback:class=$2 $1` 82} 83 84### Main program thread 85require_root 86# Set up filesystems 87if yesno "(Re)create zpools?"; then 88 delete_pool_if_exists $SRCPOOL 89 delete_pool_if_exists $DSTPOOL 90 create_zpool $SRCPOOL 91 create_zpool $DSTPOOL 92 zetaback_ignore $DSTPOOL 93 create_test_filesystems 94fi 95# Create config files 96generate_zetaback_conf 97generate_zetaback_agent_conf 98# Run zetaback 99run_zetaback 100