Ignore:
Timestamp:
09/06/13 08:19:48 (13 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
5a6ce05
Parents:
fe78043
Message:

Add new "mirror" functionality to the 'lpreserver' command. This will
easily allow the user to add a new disk, such as an external USB drive
to mirror their existing zpool.

Now we have to do the GUI bits and add options to the installer for
restoring from the external disk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-sh/lpreserver/backend/functions.sh

    raf7bd01 r1996f85  
    375375  done 
    376376} 
     377 
     378add_mirror_disk() { 
     379   pool="$1" 
     380   disk="$2" 
     381 
     382   if [ -z "$pool" ] ; then 
     383      exit_err "No pool specified" 
     384      exit 0 
     385   fi 
     386 
     387   if [ -z "$disk" ] ; then 
     388      exit_err "No disk specified" 
     389      exit 0 
     390   fi 
     391 
     392   # Check if pool exists 
     393   zpool status $pool >/dev/null 2>/dev/null 
     394   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
     395 
     396   # Make sure zpool isn't raid 
     397   zpool list -H -v ${pool} | grep -q "raid" 
     398   if [ $? -eq 0 ] ; then exit_err "Cannot mirror a raidz pool!" ; fi 
     399 
     400   # Grab the first disk in the pool 
     401   mDisk=`zpool list -H -v | grep -v "^$pool" | awk '{print $1}' | grep -v "^mirror" | head -n 1` 
     402 
     403   # Now we can insert the target disk 
     404   zpool attach $pool $mDisk $disk 
     405   if [ $? -ne 0 ] ; then 
     406      exit_err "Failed attaching $disk" 
     407   fi 
     408 
     409   echo "Added $disk to zpool $pool. Resilver will begin automatically." 
     410   exit 0 
     411} 
     412 
     413list_mirror_disks() { 
     414   pool="$1" 
     415 
     416   if [ -z "$pool" ] ; then 
     417      exit_err "No pool specified" 
     418      exit 0 
     419   fi 
     420 
     421   # Check if pool exists 
     422   zpool status $pool >/dev/null 2>/dev/null 
     423   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
     424 
     425   # Make sure zpool isn't raid 
     426   zpool list -H -v ${pool} | grep -q "raid" 
     427   if [ $? -eq 0 ] ; then exit_err "Pool: $pool is raidz!" ; fi 
     428 
     429   zpool list -H -v | grep -v "^$pool" | awk '{print $1}' | grep -v "^mirror" | tail +2 > /tmp/.mList.$$ 
     430 
     431   while read line 
     432   do 
     433      echo "$line" | grep -q -e "spare" -e "log" -e "cache" 
     434      if [ $? -eq 0 ] ; then break ; fi 
     435 
     436      echo "$line"   
     437   done < /tmp/.mList.$$ 
     438   rm /tmp/.mList.$$ 
     439} 
     440 
     441rem_mirror_disk() { 
     442   pool="$1" 
     443   disk="$2" 
     444 
     445   if [ -z "$pool" ] ; then 
     446      exit_err "No pool specified" 
     447      exit 0 
     448   fi 
     449 
     450   if [ -z "$disk" ] ; then 
     451      exit_err "No disk specified" 
     452      exit 0 
     453   fi 
     454 
     455   # Check if pool exists 
     456   zpool status $pool >/dev/null 2>/dev/null 
     457   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
     458 
     459   # Make sure zpool isn't raid 
     460   zpool list -H -v ${pool} | grep -q "raid" 
     461   if [ $? -eq 0 ] ; then exit_err "Cannot remove disks from a raidz pool!" ; fi 
     462 
     463   zpool detach $pool $disk 
     464   if [ $? -ne 0 ] ; then 
     465      exit_err "Failed detaching $disk" 
     466   fi  
     467   echo "$disk was detached successfully!" 
     468   exit 0 
     469} 
Note: See TracChangeset for help on using the changeset viewer.