Changeset 1996f85


Ignore:
Timestamp:
09/06/13 08:19:48 (12 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2
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

Location:
src-sh/lpreserver
Files:
2 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} 
  • src-sh/lpreserver/lpreserver

    r3c8d32d r1996f85  
    4040Type in help <command> for information and usage about that command 
    4141 
     42       help - This help file or the help for the specified command 
     43 
     44   cronsnap - Schedule snapshot creation via cron 
    4245        get - Get list of lpreserver options 
    43        help - This help file 
     46   listcron - Listing of scheduled snapshots 
     47   listsnap - List snapshots of a zpool/dataset 
    4448     mksnap - Create a ZFS snapshot of a zpool/dataset 
    45    listsnap - List snapshots of a zpool/dataset 
    46    listcron - Listing of scheduled snapshots 
    47    cronsnap - Schedule snapshot creation via cron 
     49     mirror - Enable / Disable ZFS mirroring to a local drive 
     50  replicate - Enable / Disable ZFS replication to a remote system 
    4851 revertsnap - Revert zpool/dataset to a snapshot 
    49   replicate - Enable / Disable ZFS replication to a remote system 
     52     rmsnap - Remove a snapshot 
    5053        set - Set lpreserver options 
    5154     status - List datasets, along with last snapshot / replication date  
    52      rmsnap - Remove a snapshot 
    5355__EOF__ 
     56}; 
     57 
     58help_mirror() 
     59{ 
     60 title 
     61 echo "Help mirror 
     62 
     63Life-Preserver mirror sub-system 
     64 
     65Mirroring uses ZFS to create a exact copy of your target disk to a new drive, 
     66such as an external USB disk. When first started the mirror will take a while 
     67to sync or "resilver". Once this is finished your new disk will be kept in sync 
     68with the target disk automatically, and can be used as a fall-back disk if the 
     69primary begins to fail.  
     70 
     71Should your primary disk fail the mirrored disk can then be used to restore 
     72the system via the restore option of the PC-BSD installation media.  
     73 
     74*NOTES*  
     75 
     76* Mirroring will only work with a non-raidz ZFS pool. If you are using 
     77raidz you will need to manage disks through the "zpool" command.  
     78 
     79* The mirror disk must be the same size or larger than the target disk 
     80 
     81Available Flags: 
     82        list - List mirror disks 
     83         add - Add a new mirror disk 
     84      remove - Remove a mirror disk 
     85 
     86Add Options: 
     87 
     88        add <zpool> <new disk> 
     89 
     90        Example 1:  
     91 
     92        add tank1 /dev/da0 
     93 
     94        Will enable mirroring of the tank1 pool to /dev/da0 
     95 
     96Remove Options: 
     97 
     98        remove <zpool> <disk> 
     99         
     100        Remove a mirrored disk from the zpool 
     101 
     102        Use 'mirror list' for a list of available disks  
     103 
     104List Options: 
     105 
     106        lizt <zpool> 
     107         
     108        Lists mirrored disks of a zpool 
     109 
     110Usage: 
     111 
     112  lpreserver mirror <subcmd> <flags> 
     113 
     114Example: 
     115 
     116  lpreserver mirror list tank1 
     117" 
    54118}; 
    55119 
     
    324388           listsnap) help_listsnap ;; 
    325389           revertsnap) help_revertsnap ;; 
     390           mirror) help_mirror ;; 
    326391           replicate) help_replicate ;; 
    327392           cronsnap) help_cronsnap ;; 
     
    421486                        fi 
    422487                        ;; 
    423                 *) exit_err "Invalid option!" ;; 
     488                *) help_replicate ;; 
     489            esac 
     490         ;; 
     491    mirror) require_root 
     492            shift 
     493            case ${1} in 
     494                add) add_mirror_disk "$2" "$3" ;; 
     495                list) list_mirror_disks "$2" ;; 
     496                remove) rem_mirror_disk "$2" "$3" ;; 
     497                *) help_mirror ;; 
    424498            esac 
    425499         ;; 
Note: See TracChangeset for help on using the changeset viewer.