#!/bin/bash TERM=linux function rseed(){ log=/usr/bp/logs.dir/seed.log hlp=`echo "Requires the following flags for operation: -l - location: points to the location of the nas device mount point or the raw hard drive for seeding example: -l /dev/sdc -p - password: provide the password for the encryption process example: -p \"unitrends1\" -s - seed: export operation to perform the seed example: -s -i - import: import seed data in to the target dpu example: -i -n - nas mode: set the seed to use a nas device example: -n \"10.10.10.4\" -d - drive mode: set the seed to use the single drive mode example: -d script usage example: for nas seeding: ./rseed -n \"10.10.10.4\" -s -p \"unitrends1\" for drive seeding: ./rseed -d -s -l /dev/sdc -p \"unitrends1\" for nas importing: ./rseed -n \"10.10.10.4\" -i -p \"unitrends1\" for drive importing: ./rseed -d -i -l /dev/sdc -p \"unitrends1\" "` while getopts "l:p:n:t:c:C:sidhSm" opt;do case $opt in l) sdev=$OPTARG ;; p) pw=$OPTARG if [[ `expr "$pw" : ".*[!@#\$%^\&*\:\;,\(\)<>_.\+\-\= ].*"` -gt 0 ]] then echo "invalid password use of special characters not permitted" exit 5 fi ;; s) op="export" ;; i) op="import" ;; n) mode="nas" ip=$OPTARG ;; d) mode="drive" ;; t) op="drv_chk" sdev=$OPTARG ;; c) mode="cloud" sdev=$OPTARG ;; S) op="seed_list" ;; h) op="help" ;; m) op="mntr" ;; C) cl=$OPTARG op="export_selective" ;; esac done function nas_chk(){ nas=$ip ping -c1 $nas >/dev/null 2>&1 if [[ $? -eq 1 ]] then #whiptail --title "Error" --msgbox "$ip either is not a valid IP address or is unreachable. Please Verify IP address is valud and that the NAS device is reachable." 8 78 echo "$ip either is not a valid IP address or is unreachable. Please verify IP address and the NAS device is reachable" exit 2 fi } function storage(){ if [[ ! -d /mnt/seed ]] then mkdir /mnt/seed fi cvrs=`dpu version | grep Version | awk -F"." '{print $NF}' | sed -e 's/^.*\(.\)$/\1/'` if [[ $cvrs -eq 7 ]] then mkfsopts="-f -m crc=0 -n ftype=0" else mkfsopts="-f" fi case $op in export) case $mode in drive) #drv_chk echo "preparing drive for seeding" >> $log mkfs.xfs ${mkfsopts} $sdev >> $log 2>&1 mount $sdev /mnt/seed >> $log 2>&1 echo "calling seed export function" >> $log ;; nas) sdev="/mnt/Data" nas_chk #if [[ $? -eq 2 ]] #then # exit 7 #fi echo "mounting NAS nfs from $ip to /mnt/seed" >> $log mount -t nfs $ip:$sdev /mnt/seed >> $log echo "calling seed export function" >> $log ;; esac ;; import) case $mode in drive) #drv_chk echo "mounting drive for importing" >> $log mount $sdev /mnt/seed touch /mnt/seed/.in_progress echo "calling import" >> $log ;; nas) sdev="/mnt/Data" nas_chk echo "mounting NAS nfs from $ip to /mnt/seed" >> $log mount -t nfs $ip:$sdev /mnt/seed touch /mnt/seed/.in_progress echo "calling import" >> $log ;; esac ;; mntr) case $mode in drive) #drv_chk echo "preparing drive for seeding" >> $log mkfs.xfs ${mkfsopts} $sdev >> $log 2>&1 mount $sdev /mnt/seed >> $log 2>&1 touch /mnt/seed/.in_progress echo "calling seed export function" >> $log ;; nas) sdev="/mnt/Data" nas_chk #if [[ $? -eq 2 ]] #then # exit 7 #fi echo "mounting NAS nfs from $ip to /mnt/seed" >> $log mount -t nfs $ip:$sdev /mnt/seed >> $log touch /mnt/seed/.in_progress echo "calling seed export function" >> $log ;; esac ;; esac } function setUP(){ echo "updating settings for performance" >> $log echo "[HaCTAR]" >> /usr/bp/bpinit/master.ini echo " WriteBufferSize=10485760" >> /usr/bp/bpinit/master.ini echo " ReadBufferSize=10485760" >> /usr/bp/bpinit/master.ini echo " HashCacheLimit=3000" >> /usr/bp/bpinit/master.ini } function UNset(){ echo "reverting changes" >> $log sed -i 's/\[HaCTAR\]//' /usr/bp/bpinit/master.ini sed -i 's/ WriteBufferSize=10485760//' /usr/bp/bpinit/master.ini sed -i 's/ ReadBufferSize=10485760//' /usr/bp/bpinit/master.ini sed -i 's/ HashCacheLimit=3000//' /usr/bp/bpinit/master.ini #check to make sure that settings are removed cat /usr/bp/bpinit/master.ini | grep "\[HaCTAR\]" >/dev/null if [[ $? -eq 0 ]] then UNset fi } function Export(){ sdn="/mnt/seed" if [[ -z $cl ]] then SDNO=`sdno` bkno=`echo $SDNO | awk '{for(i=1;i $loc/.asset echo "$bkno" > $loc/.receipt echo "$vsz" >> $loc/.receipt echo "backups to export to seed are $(echo $bkno)" >> $log echo "size of seed determined to be $vsz" >> $log echo "size of seed device determined to be $ssz" >> $log echo "exporting list of backups" >> $log if [[ $vsz -gt $ssz ]] then #echo "Selected seed device is too small to hold the required data. Please reduce the number of selected clients or procure a larger seed device" #whiptail --title "Error" --msgbox "seed device is too small for seed data, please check configuration." 8 78 echo "$vsz > $ssz seed device too small for seed data" >> $log exit 3 fi for bkups in $bkno do psql bpdb postgres -tc "update bp.backups set legal_hold=-1 where backup_no=$bkups" >/dev/null 2>$log done cnt=0 for bksd in $bkno do wss=`du -sm $loc | awk '{print $1}'` recCnt=`ps aux | grep recipe | grep -v grep | wc -l` while [ "$recCnt" -ge "$cc" ] do sleep 5 recCnt=`ps aux | grep recipe | grep -v grep | wc -l` wss=`du -sm $loc | awk '{print $1}'` if [[ $(echo "(($wss*100)/$vsz)/1" | bc) -ge 100 ]] then echo "100" else echo "$(echo "(($wss*100)/$vsz)/1" | bc)" fi done #/usr/bp/bin/recipe -b$bksd -f -z -1 -E 2>>/usr/bp/logs.dir/seed_recipe.log | openssl enc -aes-256-cbc -out $loc/archive_$cnt -k "$pw" & /usr/bp/bin/recipe -b$bksd -f -z -1 -E 2>>/usr/bp/logs.dir/seed_recipe.log | openssl enc -rc4 -out $loc/archive_$cnt -k "$pw" & echo "$(psql bpdb postgres -AF , -tc "select a.backup_no,b.node_name,a.total_megs from bp.backups a,bp.nodes b where a.node_no=b.node_no and a.backup_no=$bksd"),archive_$cnt" >> $loc/.det_rec cnt=$((cnt+1)) if [[ $(echo "(($wss*100)/$vsz)/1" | bc) -ge 100 ]] then echo "100" else echo "$(echo "(($wss*100)/$vsz)/1" | bc)" fi done recCnt=`ps aux | grep recipe | grep -v grep | wc -l` while [ "$recCnt" -ne "0" ] do sleep 5 recCnt=`ps aux | grep recipe | grep -v grep | wc -l` wss=`du -sm $loc | awk '{print $1}'` if [[ $(echo "(($wss*100)/$vsz)/1" | bc) -ge 100 ]] then echo "100" else echo "$(echo "(($wss*100)/$vsz)/1" | bc)" fi done echo "Seed completed, performing prep for drive removal" >> $log for bkups in $bkno do psql bpdb postgres -tc "update bp.backups set legal_hold=0 where backup_no=$bkups" >/dev/null 2>$log done sleep 60 umount $loc >> $log 2>&1 } function import(){ case $mode in nas) dc=4 hc=4 SeedDriver $hc $dc ;; drive) dc=4 hc=4 SeedDriver $hc $dc ;; cloud) dc=4 hc=4 SeedDriver $hc $dc ;; esac touch /mnt/seed/.completed umount /mnt/seed >> $log 2>&1 rm -rf /backups/seed_in } function SeedDriver(){ if [[ $mode = "cloud" ]] then seed=$sdev else seed="/mnt/seed" fi hc=$1 dc=$2 if [[ ! -d /backups/seed_in ]] then mkdir /backups/seed_in touch /usr/bp/logs.dir/seed_list.log fi echo "" > /usr/bp/logs.dir/seed_list.log #hactarCount=$(ps -leaf | grep hactarToctar | grep "/backups/seed_in" | grep -v grep | wc -l) if [[ ! -f $seed/.det_rec ]] then whiptail --title "Export Error" --infobox "Seed export not recognized as exported by this system. It appears to be a legacy export. Please follow legacy seed import process" 8 78 3>&2 2>&1 1>&3 exit 2 fi decCnt=$(ps -leaf | grep openssl | grep $seed | grep -v grep | wc -l) declst=`ls $seed` for arch in $declst do #hactarCount=$(ps -leaf | grep hactarToctar | grep "/backups/seed_in" | grep -v grep | wc -l) decCnt=$(ps -leaf | grep openssl | grep $seed | grep -v grep | wc -l) while [ "$decCnt" -ge "$dc" ] do sleep 30 #hactarCount=$(ps -leaf | grep hactarToctar | grep "/backups/seed_in" | grep -v grep | wc -l) decCnt=$(ps -leaf | grep openssl | grep "$seed" | grep -v grep | wc -l) #if [[ "$hactarCount" -le "$hc" ]] #then #hct #cleanup #fi done dec $arch sleep 30 done postp=5 while [ $postp -ne 0 ] do sleep 10 #hactarCount=$(ps -leaf | grep hactarToctar | grep "/backups/seed_in" | grep -v grep | wc -l) decCnt=$(ps -leaf | grep openssl | grep $seed | grep -v grep | wc -l) dl=`cat /usr/bp/logs.dir/seed_list.log | wc -l` #if [[ $hactarCount -le $hc ]] #then # hct # cleanup #fi if [[ $decCnt -eq 0 ]] then #hactarCount=$(ps -leaf | grep hactarToctar | grep "/backups/seed_in" | grep -v grep | wc -l) #if [[ $hactarCount -eq 0 ]] #then postp=0 #fi fi done } function cleanUP(){ alist=`ls /backups/seed_in` hlist=`cat /usr/bp/logs.dir/seed_list.log` seedP="/backups/seed_in" for cmpI in $alist do if [[ $(ps -leaf | grep -v grep | grep $cmpI >/dev/null 2>&1;echo $?) -ne 0 ]] then if [[ $(echo "$hlist" | grep $cmpI >/dev/null 2>&1;echo $?) -eq 0 ]] then #import is complete and can be deleted rm -f $seedP/$cmpI fi fi done } function dec(){ if [[ $mode = "cloud" ]] then seed=$sdev else seed="/mnt/seed" fi if [[ ! -f $seed/.det_rec ]] then whiptail --title "Export Error" --infobox "Seed export not recognized as exported by this system. It appears to be a legacy export. Please follow legacy seed import process" 8 78 3>&2 2>&1 1>&3 exit 2 fi echo "decrypting archive $1" >> $log #import using 9.1 hactarToctar stdin function #openssl enc -d -aes-256-cbc -in $seed/$1 -k "$pw" | /usr/bp/bin/hactarToctar -F -C 2>&1>>/usr/bp/logs.dir/seed_dec.log & openssl enc -d -rc4 -in $seed/$1 -k "$pw" | /usr/bp/bin/hactarToctar -w 2>&1>>/usr/bp/logs.dir/seed_dec.log & echo "importing $1" } function hct(){ seedN="/backups/seed_in" aTi=`ls $seedN/` list=`cat /usr/bp/logs.dir/seed_list.log` if [[ $aTi != "" ]] then for item in $aTi do if [[ $(ps -leaf | grep -v grep | grep $item >/dev/null 2>&1;echo $?) -ne 0 ]] then if [[ $(echo "$list" | grep $item >/dev/null 2>&1;echo $?) -ne 0 ]] then echo "importing $item" >> $log /usr/bp/bin/hactarToctar -F -C /backups/seed_in/$item 2>&1>>/usr/bp/logs.dir/seed_hactar.log & echo "$item" >> /usr/bp/logs.dir/seed_list.log echo -ne "importing $(cat $list | wc -l)/$(echo $aTi | wc -l)\r" fi fi done fi } function sdno(){ python - ${@:1} <0: import time time.sleep(secondsToSleep) return def get_nth_word(command, n): lines = get_printout(command) for line in lines: return line.split()[n] return "" # this is for null return def get_last_word(command): lines = get_printout(command) word ="" for line in lines: words = line.split() word = words[len(words)-1] return word def get_first_word(command): return get_nth_word(command,0) def print_list(list): for item in list: print item # there is hex() built-in function but it spit 0x class bcolors: RED = '\033[91m' GREEN = '\033[92m' YELLOW = '\033[93m' BLUE = '\033[94m' PURPLE = '\033[95m' CYAN = '\033[96m' ENDC = '\033[0m' def disable(self): self.RED = '' self.BLUE = '' self.GREEN = '' self.YELLOW = '' self.PURPLE = '' self.CYAN = '' self.ENDC = '' def red(text): return bcolors.RED + text + bcolors.ENDC; def blue(text): return bcolors.BLUE + text + bcolors.ENDC; def green(text): return bcolors.GREEN + text + bcolors.ENDC; class BackupType: def __init__(self, type): self.raw = type self.type = " " if type == 1 : self.type = "Master" elif type == 2 : self.type = "Increment" elif type == 3 : self.type = "Incr4ever" elif type == 4 : self.type = "Selective" elif type == 5 : self.type = "EXCHGFULL" elif type == 6 : self.type = "EXCHGDIFF" elif type == 7 : self.type = "EXCHGINCR" elif type == 9 : self.type = "MSSQLFULL" elif type == 10 : self.type = "MSSQLDIFF" elif type == 11 : self.type = "MSSQLTRNS" elif type == 12 : self.type = "VMESXFULL" elif type == 13 : self.type = "VMESXDIFF" elif type == 14 : self.type = "VMESXINCR" elif type == 1024 : self.type = "BareMetal" # IMAGE_BACKUP elif type == 1031 : self.type = "HYPRVFULL" elif type == 1032 : self.type = "HYPRVDIFF" elif type == 1033 : self.type = "HYPRVINCR" elif type == 1034 : self.type = "ORACLFULL" elif type == 1035 : self.type = "ORACLINCR" elif type == 1036 : self.type = "SHAREFULL" elif type == 1037 : self.type = "SHAREINCR" elif type == 1038 : self.type = "APPLEMETA" elif type == 1039 : self.type = "RAE__FULL" elif type == 4096 : self.type = "RAE__DIFF" elif type == 4097 : self.type = "RAE__INCR" elif type == 4098 : self.type = "NDMP_FULL" elif type == 4099 : self.type = "NDMP_DIFF" elif type == 4100 : self.type = "NDMP_INCR" elif type == 4101 : self.type = "XEN__FULL" elif type == 4102 : self.type = "XENCONFIG" elif type == 4103 : self.type = "AHVFULL" elif type == 4104 : self.type = "AHVDIFF" elif type == 4105 : self.type = "AHVINCR" elif type == 16 : self.type = "Restore" elif type == 4106 : self.type = "BLOCK_FULL" elif type == 4107 : self.type = "BLOCK_DIFF" elif type == 4108 : self.type = "BLOCK_INCR" def __repr__(self): return self.type class BackupProperties: def __init__(self, properties): self.raw = properties self.properties = [] if properties & 0x00000001: self.properties.append("SYNTHETIC"); if properties & 0x00000002: self.properties.append("COMP_HARD"); if properties & 0x00000004: self.properties.append("COMP_SOFT"); if properties & 0x00000008: self.properties.append("WPROTECTD"); if properties & 0x00000010: self.properties.append("NO_DETAIL"); if properties & 0x00000020: self.properties.append("IMPORTED "); if properties & 0x00000040: self.properties.append("P_COPY "); if properties & 0x00000080: self.properties.append("P_SQL "); if properties & 0x00000100: self.properties.append("ENCRYPTED"); if properties & 0x00000200: self.properties.append("HASHED "); if properties & 0x00000400: self.properties.append("DDUPCATED"); if properties & 0x00000800: self.properties.append("SYNTHESZD"); if properties & 0x00001000: self.properties.append("SYNTCAPBL"); if properties & 0x00002000: self.properties.append("DISK_META"); if properties & 0x10000000: self.properties.append("P_ODIRECT"); log = "" for prop in self.properties: log = log + "%s " % prop self.words = log def __repr__(self): return self.words if __name__ == '__main__': main() EOF } function sdVLDT(){ #function to validate if import was successful Istat=`psql bpdb postgres -tc "select status from bp.backups where node_no in (select node_no from bp.nodes where node_name like ('gc0%'))"` if [[ $mode = 'cloud' ]] then archCT=`ls $sdev | wc -l` nStat=`echo $Istat | wc -l` else archCT=`ls /mnt/seed | wc -l` nStat=`echo "$Istat" | wc -l` fi if [[ $archCT -eq $nStat ]] then for stat in $Istat do if [[ $stat != 3168 ]] || [[ $stat != 19552 ]] then echo "non-successful import detected" >> $log return 14 fi done else echo "detected extra imports where as compared to what is on the seed device." >> $log echo "checking all backups in list" >> $log for stat in $Istat do if [[ $stat != 3168 ]] || [[ $stat != 19552 ]] then echo "non-successful import detected" >> $log return 14 fi done fi } case $op in mntr) if [[ -z $mode ]] then exit 6 fi if [[ $mode = "drive" ]] then if [[ -z $sdev ]] then exit 6 fi fi storage ;; export_selective) Export ;; export) if [[ -z $pw ]] then #echo "Missing required parameters (-p password)" #echo "" #echo "$hlp" exit 6 fi if [[ -z $mode ]] then #echo "Missing required parameters (-d/-n )" #echo "" #echo "$hlp" exit 6 fi if [[ $mode = "drive" ]] then if [[ -z $sdev ]] then #echo "Missing required parameters (-l drive location)" #echo "" #echo "$hlp" exit 6 fi fi #echo "creating rapid seed" #setUP storage #if [[ $? -eq 7 ]] #then # exit 7 #fi Export #UNset #echo "Rapid Seed Export operation complete" echo "Rapid Seed Export operation complete" >> $log ;; import) if [[ -z $pw ]] then #echo "Missing required parameters (-p password)" #echo "" #echo "$hlp" exit 6 fi if [[ $mode != "nas" ]] then if [[ -z $sdev ]] then #echo "Missing required parameters (-l drive location)" #echo "" #echo "$hlp" exit 6 fi fi if [[ -z $mode ]] then #echo "Missing required parameters (-d/-n )" #echo "" #echo "$hlp" exit 6 fi #echo "importing rapid seed" if [[ ! $mode = "cloud" ]] then #setUP storage #need to add space validator for mounted device #need to add serial getter for nas or single drive import #need to add validator for successful import #UNset sdVLDT if [[ $? -eq 14 ]] then echo "Import was detected as unsuccessful" >> $log return 8 fi #need to add serial number pusher if validator is successful else #setUP #need to add space validator for mounted device #need to add serial getter for nas or single drive import #UNset #need to add validator for successful import sdVLDT if [[ $? -eq 14 ]] then echo "Import was detected as unsuccessful" >> $log return 8 fi #need to add serial number pusher if validator is successful fi #echo "Rapid Seed Import Complete" echo "Rapid Seed Import Complete" >> $log ;; drv_chk) drv_chk ;; seed_list) sdno ${@:2} ;; *) echo "$hlp" ;; esac } function repSet(){ function RepTgt { #to be run against the container target to make it an official target to recieve replication data during seeding curl -s -k -X POST -d "{\"network\":\"172.17.3.0\",\"port\":\"$ccpt\"}" https://localhost/api/systems/make_target | python -mjson.tool >> /tmp/tgtConf 2>&1 } function RepSrc { #to be executed from against the source unit to setup openvpn and request approval for replication tgtIP=$2 tgtHN=$3 curl -s -k -X POST -d "{\"type\":\"appliance\",\"target\":\"$tgtHN\",\"ip\":\"$tgtIP\",\"insecure\":\"1\"}" https://localhost/api/replication/target | python -mjson.tool >> /tmp/srcConf 2>&1 } function RepCTGT { #to be run from inside of the container to confirm/approve the requesting source rid=`curl -s -k -X GET https://localhost/api/replication/pending | python -mjson.tool | grep "request_id" | awk '{print $NF}' | tr -d ","` if [[ $rid = "" ]] then echo "send request from client failed" >> /tmp/tgtConf 2>&1 exit 0 fi curl -s -k -X POST -d "{\"request_id\":$rid,\"accept\":true}" https://localhost/api/replication/source | python -mjson.tool >> /tmp/tgtConf 2>&1 } function RepCSRC { #usage of sshpass plus rtpw and dpuIP will then execute this below command to confirm replication setup and complete final stage tgtHN=$2 /usr/bp/bin/rrpoll $tgtHN 443 1 } function get(){ #token=`curl -sk -X POST -d "{\"username\":\"root\",\"password\":\"$uipw\"}" https://$dpuIP/api/login | python -mjson.tool | grep "auth_token" | awk '{print $NF}' | sed 's/"//g;s/,//g'` if [[ $nas -eq 1 ]] then curl -sk -X GET -H "AuthToken: $token" $1 else curl -sk -X GET $1 fi } function put(){ #token=`curl -sk -X POST -d "{\"username\":\"root\",\"password\":\"$uipw\"}" https://$dpuIP/api/login | python -mjson.tool | grep "auth_token" | awk '{print $NF}' | sed 's/"//g;s/,//g'` if [[ $nas -eq 1 ]] then curl -sk -X PUT -H "AuthToken: $token" $1 else curl -sk -X PUT $1 fi } function list(){ whiptail --title "Data Collection" --infobox "Collecting client data. Please wait" 8 78 3>&2 2>&1 1>&3 json=$(get "https://$dpuIP/api/clients") num=$(echo "$json" | jq '.data[].id' | wc -l) jid=$(echo "$json" | jq -r '.data[].id') jnm=$(echo "$json" | jq -r '.data[].name') jis=$(echo "$json" | jq -r '.data[].is_synchable') clist=$(for i in `seq 1 $num`;do echo "$(echo "$jid" | head -n$i | tail -n1) $(echo "$jnm" | head -n$i | tail -n1) $(if [[ `echo "$jis" | head -n$i | tail -n1` = "false" ]];then echo "OFF";else echo "ON";fi)";done) if [[ $(echo $clist | sed 's/OFF//g' | wc -w) -le 0 ]] then whiptail --title "Error" --msgbox "We found no clients from registered to the DPU, or the IP address provided was incorrect. Please try again" 8 78 3>&2 2>&1 1>&3 exit 1 else itmNum=`echo "(($(echo $clist | wc -w)/3)/2)/1" | bc` if [[ $itmNum -ge 10 ]] then itmNum=10 fi whiptail --title "Available Clients" --checklist "Use spacebar to select/unselect clients to seed" 18 50 $itmNum $clist 3>&2 2>&1 1>&3 fi } #openvpn port should always be the same port as that which is exposed, cloudops automation script to handle part of this function function setClients(){ #put="curl -sk -X PUT -H "AuthToken: $token"" choice=`list | sed 's/"//g'` if [[ `echo $choice | wc -w` -le 0 ]] then whiptail --title "Error" --msgbox "You must select at least one client for seeding" 8 78 whiptail --title "Error" --yesno "Would you like to try again?" 8 78 if [[ $? -eq 0 ]] then return 0 else whiptail --title "Error" --msgbox "You have chosen to exit. Aborting seed operation" 8 78 exit 1 fi else #need to add a get and parse operation for the confirmation to list clients and total seed size preCon=`whiptail --title "Confirmation" --scrolltext --yesno "$(for i in $choice;do echo "$i 80gb\n";done)----------\nTotal 320gb" 10 78 3>&2 2>&1 1>&3;echo $?` fi for i in $choice do #nme=`get "https://$dpuIP/api/clients/$i" | jq '.data[].name' | sed 's/"//g'` #rep=`get "https://$dpuIP/api/clients/$i" | jq '.data[].is_synchable' | sed 's/"//g'` curl -sk -X PUT -H "AuthToken: $token" https://$dpuIP/api/clients/$i -d '{"is_synchable":1}' done return 1 } function legClients(){ #ussh="sshpass -p $2 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$1" #uscp="sshpass -p $2 scp" whiptail --title "Data Collection" --infobox "Collecting client data. Please Wait." 8 78 3>&2 2>&1 1>&3 clist=`legList` choice=`whiptail --title "Available Clients" --checklist "Use spacebar to select/unselect clients to seed." 28 120 18 $clist 3>&2 2>&1 1>&3` if [[ `echo $choice | wc -w` -le 0 ]] then whiptail --title "Error" --msgbox "You must select at least one client for seeding" 8 78 whiptail --title "Error" --yesno "Would you like to try again?" 8 78 if [[ $? -eq 0 ]] then return 0 else whiptail --title "Error" --msgbox "You chosen to exit, Aborting seed Operation" 8 78 exit 1 fi else #preCon=`whiptail --title "Confirmation" --scrolltext --yesno "$(for i in $choice;do echo "$i 80gb\n";done)---------\nTotal 320gb" 10 78 3>&2 2>&1 1>&3;echo $?` #set clients to be replicated and collect backup size for selected clients #for i in $choice #do if [[ $selective = "true" ]] then j=`echo $choice | sed 's/"//g' | awk '{for(i=1;i/dev/null 2>&1 else psql bpdb postgres -c "update bp.application_instances set sync=true where instance_id in ($j)" >/dev/null 2>&1 fi fi #done val=`legGet` #then display confirmation box with totals #if confirmation is yes then save copy of backup numbers, clients, and size to file on seed, file on dpu at /usr/bp/logs.dir/seed_receipt_$(date).log #clie=`echo "$choice" | sed 's/"//g'` #cline=`for i in $clie;do echo "$(echo "$clist" | grep -w "^$i" | awk '{print $2}')";done` preCon=`whiptail --title "Confirmation" --scrolltext --yesno "$val" 20 78 3>&2 2>&1 1>&3;echo $?` if [[ $preCon -eq 0 ]] then if [[ $nas -eq 1 ]] then echo "$val" > /mnt/Data/seed_receipt_$(date +%m_%d_%Y).log $uscp /mnt/Data/seed_receipt_$(date +%m_%d_%Y).log root@$1:/usr/bp/logs.dir/ >/dev/null 2>&1 else echo "$val" > /mnt/seed/seed_receipt_$(date +%m_%d_%Y).log echo "$val" > /usr/bp/logs.dir/seed_receipt_$(date +%m_%d_%Y).log fi return 1 else for i in $choice do j=`echo $i | sed 's/"//g'` if [[ $nas -eq 1 ]] then psql bpdb postgres -h $1 -c "update bp.application_instances set sync=false where instance_id=$j" >/dev/null 2>&1 else psql bpdb postgres -c "update bp.application_instances set sync=false where instance_id=$j" >/dev/null 2>&1 fi done return 2 fi fi #return 1 } function repConf(){ rpst=`get "https://$dpuIP/api/replication/targets/?sid=1" | jq '.targets[]'` if [[ -z $rdst ]] then yn=$(whiptail --title "Error" --yesno "Replication has not been configured. would you like this to be configured automatically?" 8 78 3>&2 2>&1 1>&3;echo $?) if [[ $yn -eq 0 ]] then whiptail --title "Configuration" --msgbox "configuring replication automated has been enabled" 8 78 else whiptail --title "Error" --msgbox "Please setup replication and re-run this process" 8 78 return 0 fi else whiptail --title "Replication" --msgbox "Replication is enabled" 8 78 fi return 1 } function legGet(){ #uscp="sshpass -p $2 scp" #will return backup numbers and total size of job will need to use rseed -S to retrieve required information if [[ $nas -eq 1 ]] then #$uscp /bin/rseed root@$dpuIP:/tmp/ >/dev/null 2>&1 dt=`$ussh "sh /tmp/rseed -S" 2>/dev/null` dtn=`echo "$dt" | head -n-1` dtt=`echo "$(echo "($(echo "$dt" | tail -n1)/1024)/1" | bc)gb"` dta=`echo $dtn | awk '{for(i=1;i /usr/bp/data/pg_hba.conf" >/dev/null 2>&1 $ussh "sudo -iu postgres pg_ctl reload -D /usr/bp/data/;rm -f /usr/bp/data/pg_hba.conf.sav" >/dev/null 2>&1 else $ussh "echo \"host bpdb postgres $1/32 trust\" >> /usr/bp/data/pg_hba.conf;sudo -iu postgres pg_ctl reload -D /usr/bp/data/" >/dev/null 2>&1 #$ussh "sudo -iu postgres pg_ctl reload -D /usr/bp/data/" >/dev/null 2>&1 fi fi } function legSet(){ #whiptail --title "Error" --msgbox "Legacy placeholder for client setup for seeding" 8 78 3>&2 2>&1 1>&3 #legPG nns=`legList` echo "$nns" #first call legPG to allow postgres communication. This will need to update the pg_hba.conf and perform a reload #second call to legList, this will get a list of all clients on the unit. should pull from bp.application_instances for client names #legGet will handle the call to the DPU to perform the rseed mechanisms to write data into the system through the exposed nfs share. #final operation to remove changes, using legPG -r } Type=$1 case $Type in target) if [[ $nas -eq 1 ]] then dpuIP=$2 rtpw=$3 uipw=$4 #ccnm=$4 #ccpt=docker inspect $ccnm | grep 1194 external ussh="sshpass -p $rtpw ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$dpuIP" uscp="sshpass -p $rtpw scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" token=`curl -sk -X POST -d "{\"username\":\"root\",\"password\":\"$uipw\"}" https://$dpuIP/api/login | python -mjson.tool | grep "auth_token" | awk '{print $NF}' | sed 's/"//g;s/,//g'` sip=$5 fi if [[ -z $token ]] then whiptail --title "Error" --msgbox "System not configured to use Satori UI interface. Automation not possible" 8 78 exit 4 fi strt="0" while [ "$strt" -eq "0" ] do setClients if [[ $? -eq 1 ]] then repConf if [[ $? -eq 1 ]] then whiptail --title "Success" --msgbox "Setup completed successfully" 8 78 strt=1 else whiptail --title "Error" --msgbox "Failed to setup replication" 8 78 fi else whiptail --title "Error" --msgbox "We encountered an error during the client setup" 8 78 fi done ;; legacy) if [[ $nas -eq 1 ]] then dpuIP=$2 rtpw=$3 #ccnm=$4 #ccpt=docker inspect $ccnm | grep 1194 external ussh="sshpass -p $rtpw ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$dpuIP" uscp="sshpass -p $rtpw scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" sip=$4 fi #legPG "$sip" strt="0" while [ "$strt" -eq "0" ] do legClients #"$dpuIP" "$rtpw" if [[ $? -eq 1 ]] then strt=1 fi done ;; -r) dpuIP=$2 rtpw=$3 ussh="sshpass -p $rtpw ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$dpuIP" #uscp="sshpass -p $rtpw scp" legPG -r ;; selective) whiptail --title "Data Collection" --infobox "Collecting client data. Please Wait." 8 78 3>&2 2>&1 1>&3 clist=`legList sel` choice=`whiptail --title "Available Clients" --checklist "Use spacebar to select/unselect clients to seed." 28 120 18 $clist 3>&2 2>&1 1>&3` echo $choice ;; esac } function menu(){ function validIP(){ if [[ -z $2 ]] then sub="255.255.255.0" else sub=$2 fi ip=$1 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] then OIFS=$IFS IFS='.' ipn=($ip) subn=($sub) IFS=$OIFS [[ ${ipn[0]} -le 255 && ${ipn[1]} -le 255 && ${ipn[2]} -le 255 && ${ipn[3]} -le 255 ]] stat1=$? [[ ${subn[0]} -le 255 && ${subn[1]} -le 255 && ${subn[2]} -le 255 && ${subn[3]} -le 255 ]] stat2=$? if [[ $stat1 -eq 0 ]] then if [[ $stat2 -eq 0 ]] then valid=0 else whiptail --title "Error" --msgbox "You have entered an invalid IP address or subnet. Please try again" 8 78 fi else whiptail --title "Error" --msgbox "You have entered an invalid IP address or subnet. Please try again" 8 78 fi else whiptail --title "Error" --msgbox "You have entered an invalid IP address or subnet. Please try again" 8 78 fi } function validENC(){ if [[ `expr "$1" : ".*[!@#\$%^\&*\:\;,\(\)<>_.\+\-\= ].*"` -gt 0 ]] then whiptail --title "Error" --msgbox "Invalid use of special character in encryption passphrase" 8 78 else if [[ -z $1 ]] then whiptail --title "Error" --msgbox "Blank encryption passphrase is not allowed" 8 78 else valid=0 fi fi } function PF(){ rdir="/tmp" ldir="/bin" ip=$1 pw=$2 files="any_snmptrap_sender.py rseed" for file in $files do sshpass -p $pw scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $ldir/$file root@$ip:$rdir >/dev/null 2>&1 done } function netMenu(){ valid="1" netmn=$(whiptail --title "Network Setup Selection" --menu "Select an option to proceed" 16 78 5 \ "Static" "Set IP manually" \ "DHCP" "Use DHCP to setup networking" --nocancel 3>&2 2>&1 1>&3) if [[ $netmn = "Static" ]] then while [ "$valid" -eq 1 ] do ipc=$(whiptail --title "IP Address Setup" --inputbox "Enter an IP address to use in the format of XXX.XXX.XXX.XXX" 8 78 --nocancel 3>&2 2>&1 1>&3) subc=$(whiptail --title "IP Address Setup" --inputbox "Enter the Subnet Mask to use in the format of XXX.XXX.XXX.XXX" 8 78 --nocancel 3>&2 2>&1 1>&3) gwc=$(whiptail --title "IP Address Setup" --inputbox "Enter the IP address of the gateway to use in the format of XXX.XXX.XXX.XXX" 8 78 --nocancel 3>&2 2>&1 1>&3) validIP $ipc $subc validIP $gwc if [[ $valid -eq 0 ]] then whiptail --title "IP Address Setup" --msgbox "Setting IP and subnet to $ipc/$subc using gateway $gwc" 8 78 if [[ $debug -eq 0 ]] then SetNet 1 "$ipc" "$subc" "$gwc" touch /root/.setNET else whiptail --title "Debug Mode" --msgbox "Running SetNet $ipc $subc $gwc" 8 78 conf=1 fi fi done else #call SetNet in dhcp mode then populate ipc with information from dhcp lease if [[ $debug -eq 0 ]] then SetNet 0 1 2 3 ipc=$(ifconfig $devName | grep netmask | awk '{print $2}') touch /root/.setNET else whiptail --title "Debug Mode" --msgbox "Running SetNet in DHCP mode" 8 78 ipc="192.168.40.240" conf=1 fi fi } function drv_sel(){ function drv_chk(){ dr=`lsscsi | grep disk | awk '{print $NF}'` for sdev in $dr do drv=`echo $sdev | awk -F"/" '{print $NF}'` if [[ ${drv} == '-' ]]; then continue fi if [[ `lsscsi | grep disk | grep $sdev >/dev/null 2>&1;echo $?` -eq 0 ]] then if [[ $(cat /sys/class/block/"${drv}"/queue/rotational) -ne 0 ]] then if [[ `cat /proc/mdstat | grep $drv >/dev/null 2>&1;echo $?` -ne 0 ]] then if [[ `mount | grep $sdev >/dev/null 2>&1;echo $?` -ne 0 ]] then if [[ `pvdisplay | grep $sdev >/dev/null 2>&1;echo $?` -ne 0 ]] then drl+="$sdev " fi fi fi fi fi done echo $drl } function drv_list(){ dv=`drv_chk` if [[ -z $dv ]] then whiptail --title "Error" --msgbox "No valid drives found to use for seeding. Please recheck connection and try again." 10 78 2>&2 2>&1 1>&3 exit fi for i in $dv do #dsz=`lsscsi -s | grep $i | awk '{print $NF}'` #ser=`lsscsi -s | grep $i | awk '{a=NF-3}{print $a}'` ser=$(smartctl -a -d sat,16 "$i" | grep "Device Model" | awk '{print $NF}') dsz=$(smartctl -a -d sat,16 "$i" | grep "Capacity" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}' | awk '{print $1$2}' | tr -d '\n') echo "$i ${ser}____${dsz}" done } whiptail --title "Collecting Drive Data" --infobox "Collecting Drive information on all available drives" 8 78 3>&2 2>&1 1>&3 drve=`drv_list` #drive=`whiptail --title "Drive Selection" --menu "Please select a drive to use for seeding" 16 78 5 $(drv_list) 3>&2 2>&1 1>&3` if [[ -z $drve ]] then echo 2 else drive=`whiptail --title "Drive Selection" --menu "Please select a drive to use for seeding" 16 78 5 $drve 3>&2 2>&1 1>&3` echo $drive fi } function strPrep(){ #check for previously existing raid device. ar=`cat /proc/mdstat | grep md >/dev/null 2>&1;echo $?` if [[ $ar -eq 0 ]] then #detected previously existing md device. This should only occur during import to the cloud. As such mount the device to /mnt/Data md=`cat /proc/mdstat | grep -o md[0-9]*` dmd=`echo "$md" | wc -l` if [[ $md -gt 1 ]] then #invalid drive configuration whiptail --title "Unitrends Rapid Seed Storage Error" --msgbox "Detected an invalid storage setup, previously created. Seeding will not be able to complete successfully." 10 78 else mount -t xfs /dev/$md /mnt/Data fi else #make raid 0 devices from detected drives drvs=`lsscsi | grep ATA | awk '{print $NF}'` mdadm --create --force /dev/md0 --level=0 --raid-devices=$(echo $drvs | wc -w) $drvs >/dev/null 2>&1 <</dev/null 2>&1 mount -t xfs /dev/md0 /mnt/Data >/dev/null 2>&1 fi if [[ $(cat /etc/exports | grep "Data" >/dev/null 2>&1;echo $?) -eq 1 ]] then echo "/mnt/Data (rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports fi service nfs start >/dev/null 2>&1 } function SetNet(){ ipN=$2 sbN=$3 gwN=$4 dhcp=$1 #need to online the network devices before proceeding on,without the networkmanager running this is not done on boot nDEV=$(ip l | grep "1:\|2:\|3:" | awk '{print $2}' | sed 's/://g' | grep -v "lo") for DEV in $nDEV do ifconfig $DEV up done whiptail --title "Unitrends Rapid Seed Device Configuration" --infobox "Configuring the network devices" 8 78 sleep 30 DevL=`ifconfig -s | grep -iv "Iface\|lo" | awk '{print $1}'` for name in $DevL do act=$(ethtool $name | grep -i "detected" | awk '{print $NF}') if [[ $act = "yes" ]] then devName=$name break fi done if [[ -z $devName ]] then whiptail --title "Error" --msgbox "Could not detect an active network link to use. Please ensure that a network cable is plugged in and active" 8 78 exit 3 else if [[ $dhcp -eq 1 ]] then ifconfig $devName down ifconfig $devName $ipN ifconfig $devName netmask $sbN ifconfig $devName up route add default gw $gwN conf=1 else dhclientD $devName conf=1 sleep 30 DHIP=`ip a | grep $devName | grep "inet " | awk '{print $2}' | awk -F"/" '{print $1}'` if [[ $DHIP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] then whiptail --title "Setup Confirmation" --msgbox "The IP address assigned to this NAS device is $DHIP" 8 78 else whiptail --title "Error" --msgbox "The DHCP server did not respond in a timely fashion." 8 78 exit 3 fi fi fi } case $1 in -d) debug=1 whiptail --title "Debug Mode" --msgbox "Using debug mode, no changes will be made to the system." 8 78 ;; target) pf="target" debug=1 ;; legacy) pf="legacy" debug=1 ;; esac if [[ $nas -eq 1 ]] then strPrep fi whiptail --title "Unitrends Rapid Seed" --msgbox "Unitrends Rapid Seed Device Setup Wizard" 8 80 estat=$? if [[ $nas -eq 0 ]] then method=$(whiptail --title "Rapid Seed Options" --menu "Select an option to proceed" 16 78 5 \ "Single drive" "seed export" \ "NAS device" "seed export" --cancel-button "Exit" 3>&2 2>&1 1>&3) methodC=$(echo $method | sed 's/ //g') case "$methodC" in Singledrive) dstate=`drv_sel` sdNAS=0 if [[ -z $dstate ]] then whiptail --title "Error" --msgbox "You have not selected a drive for seeding. Exiting seed wizard" 8 78 exit 2 fi if [[ $dstate -eq 2 ]] then exit 2 fi ;; NASdevice) DNIP=$(whiptail --title "Rapid Seed" --inputbox "Enter the IP address of the Unitrends Rapid Seed NAS device" 8 78 --nocancel 3>&2 2>&1 1>&3) dnIP=$(echo $DNIP | sed 's/ //g') sdNAS=1 #ping -c1 $dnIP >/dev/null 2>&1 #if [[ $? -eq 1 ]] #then # whiptail --title "Error" --msgbox "$dnIP either is not a valid IP address or is unreachable. Please Verify IP address is valud and that the NAS device is reachable." 8 78 #echo "$ip either is not a valid IP address or is unreachable. Please verify IP address and the NAS device is reachable" # exit 2 #fi ;; *) echo "selection canceled or not provided exiting cleanly" exit 0 ;; esac else if [[ ! -f /root/.setNET ]] then netMenu if [[ $? -eq 3 ]] then whiptail --title "Error" --msgbox "Failed to configure network of the system. Please check network connection and retry" 8 78 exit 3 fi else conf=1 fi fi if [[ $nas -eq 0 ]] then if [ $estat = 0 ];then status="0" while [ "$status" -eq 0 ] do case $pf in legacy) if [[ $nas -eq 1 ]] then choice=$(whiptail --title "$ipc Configuration" --menu "Select an option to proceed" 16 78 5 \ "configure" "Set Configuration of the Rapid Seed Device" \ "Launch rapid" "seed export process" \ "target seed" "Launch the rapid seed for single tenant targets" --cancel-button "Exit" 3>&2 2>&1 1>&3) else choice=$(whiptail --title "$ipc Configuration" --menu "Select an option to proceed" 16 78 5 \ "rapid seed" "Launch the rapid seed process" \ "target seed" "Launch the rapid seed for single tenant targets" --cancel-button "Exit" 3>&2 2>&1 1>&3) fi ;; target) if [[ $nas -eq 1 ]] then choice=$(whiptail --title "$ipc Configuration" --menu "Select an option to proceed" 16 78 5 \ "configure" "Set Configuration of the Rapid Seed Device" \ "Launch rapid" "seed export process" \ "target seed" "Launch the rapid seed for single tenant targets" --cancel-button "Exit" 3>&2 2>&1 1>&3) else choice=$(whiptail --title "$ipc Configuration" --menu "Select an option to proceed" 16 78 5 \ "Launch rapid" "seed export process" \ "target seed" "Launch the rapid seed for single tenant targets" --cancel-button "Exit" 3>&2 2>&1 1>&3) fi ;; *) if [[ $nas -eq 1 ]] then choice=$(whiptail --title "$ipc Configuration" --menu "Select an option to proceed" 16 78 5 \ "configure" "Set Configuration of the Rapid Seed Device" \ "Launch rapid" "seed export process" --cancel-button "Exit" 3>&2 2>&1 1>&3) else choice=$(whiptail --title "$ipc Configuration" --menu "Select an option to proceed" 16 78 5 \ "Launch rapid" "seed export process" --cancel-button "Exit" 3>&2 2>&1 1>&3) fi ;; esac option=$(echo $choice | sed 's/ //g') pf="" case "$option" in configure) back="0" while [ "$back" -eq 0 ] do case $pf in legacy) back=1 choice="menu" ;; command) choice="commandline" ;; target) back=1 choice="menu" ;; *) choice=$(whiptail --title "$ipc Configuration" --menu "Select an option to configure" 16 78 5 \ "ip address" "Set the seed device's IP address" \ "dns servers" "Set the primary and secondary dns servers" \ "advance configuration" "Set seeding advanced configuration mode" --cancel-button "Main Menu" 3>&2 2>&1 1>&3) back=0 ;; esac op=$(echo $choice | sed 's/ //g') case "$op" in commandline) break 3 ;; ipaddress) netMenu ;; dnsservers) pri=$(whiptail --title "DNS Resolver Setup" --inputbox "Enter primary DNS server" 8 78 --nocancel 3>&2 2>&1 1>&3) sec=$(whiptail --title "DNS Resolver Setup" --inputbox "Enter secondary DNS server" 8 78 --nocancel 3>&2 2>&1 1>&3) whiptail --title "DNS Resolver Setup" --msgbox "setting primary DNS server as $pri and setting secondary DNS server to $sec" 8 78 3>&2 2>&1 1>&3 if [[ $debug -eq 0 ]] then if [[ -z $sec ]] then echo "nameserver $pri" >> /etc/resolv.conf else echo "nameserver $pri" >> /etc/resolv.conf echo "nameserver $sec" >> /etc/resolv.conf fi else whiptail --title "Debug Mode" --msgbox "setting nameserver primary $pri secondary $sec" 8 78 fi ;; advanceconfiguration) pf=$(whiptail --title "Advanced Configuration Mode" --inputbox "Enter Configuration option to enable" 8 78 --nocancel 3>&2 2>&1 1>&3) ;; *) whiptail --title "Return" --msgbox "Returning to main menu" 8 78 back=1 ;; esac done ;; Launchrapid) if [[ $nas -eq 1 ]] then if [[ $conf -ne 1 ]] then whiptail --title "Warning" --msgbox "You have not run through the configuration settings yet. Please configure the IP address of the system before proceeding." 8 78 continue fi valid="1" while [ "$valid" -eq 1 ] do ipr=$(whiptail --title "Rapid Seed" --inputbox "Enter the IP address of the Unitrends appliance" 8 78 --nocancel 3>&2 2>&1 1>&3) validIP $ipr done upw=$(whiptail --title "Rapid Seed" --inputbox "Enter the Unitrends Appliance OS password" 8 78 --nocancel 3>&2 2>&1 1>&3) fi valid="1" while [ "$valid" -eq 1 ] do enc=$(whiptail --title "Rapid Seed" --inputbox "Enter the encryption password" 8 78 --nocancel 3>&2 2>&1 1>&3) validENC "$enc" done if [[ $sdNAS -eq 1 ]] then #PF "$ipr" "$upw" whiptail --title "Rapid Seed" --msgbox "Will perform seed operation against the Unitrends NAS Seed Device at $dnIP with encryption password: $enc" 8 78 3>&2 2>&1 1>&3 else whiptail --title "Rapid Seed" --msgbox "Will perform seed operation to $dstate using encryption password: $enc" 8 78 3>&2 2>&1 1>&3 fi #email preper eml=`whiptail --title "Rapid Seed" --yesno "Would you like a notification upon seed operation completion?" 8 78 3>&2 2>&1 1>&3;echo $?` if [[ $eml -eq 0 ]] then emlAddr=`whiptail --title "Rapid Seed" --inputbox "Please enter the receiver's email address, for multiple email address, use a space seperator\n\n*Please note that email setup must be completed successfully for email completion notifications" --nocancel 10 78 3>&2 2>&1 1>&3` fi repSet legacy "$ipr" "$upw" "$ipc" go=$(whiptail --title "Rapid Seed" --yesno "Are you ready to begin?" 8 78 3>&2 2>&1 1>&3;echo $?) if [ $go -eq 0 ]; then assetTag=`cat /etc/unitrends-asset` date=`date +"%m_%d_%y_%H_%M"` size=`rseed -S | tail -n1` numClients=`rseed -S | head -n-1 | wc -l` ##### TODO Send EMAIL #### Sec=0 #$(whiptail --title "Rapid Seed" --yesno "Are you ready to begin?" 8 78 3>&2 2>&1 1>&3;echo $?) if [ $Sec -eq 0 ]; then #{ if [[ $sdNAS -eq 0 ]] then #move mounting and size validation to this point #rseed -mdl $dstate #check size if [[ ! -d /mnt/seed ]] then mkdir /mnt/seed fi cvrs=`dpu version | grep Version | awk -F"." '{print $NF}' | sed -e 's/^.*\(.\)$/\1/'` if [[ $cvrs -eq 7 ]] then mkfsopts="-f -m crc=0 -n ftype=0" else mkfsopts="-f" fi mkfs.xfs ${mkfsopts} ${dstate} >/dev/null 2>&1 mount ${dstate} /mnt/seed ssz=`df -Pm | grep "/mnt/seed" | awk '{print $4}'` umount /mnt/seed if [[ $size -gt $ssz ]] then #echo "Selected seed device is too small to hold the required data. Please reduce the number of selected clients or procure a larger seed device" whiptail --title "Error" --msgbox "seed device is too small for seed data, please check configuration." 8 78 #echo "$vsz > $ssz seed device too small for seed data" >> $log exit 3 fi #start seed rseed -dsl ${dstate} -p ${enc} | whiptail --title "Rapid Seed Progress" --gauge "Percentage of seed written to device" 8 78 0 3>&2 2>&1 1>&3 if [[ $? -ne 0 ]] then whiptail --title "Error" --msgbox "An error has occurred please check log file at /usr/bp/logs.dir/seed.log for more information" 8 78 3>&2 2>&1 1>&3 exit 3 fi else #move mounting and size validation to this point rseed -mn $dnIP #check size ssz=`df -Pm | grep "/mnt/seed" | awk '{print $4}'` if [[ $size -gt $ssz ]] then #echo "Selected seed device is too small to hold the required data. Please reduce the number of selected clients or procure a larger seed device" whiptail --title "Error" --msgbox "seed device is too small for seed data, please check configuration." 8 78 #echo "$vsz > $ssz seed device too small for seed data" >> $log exit 3 fi #start seed rseed -n $dnIP -sp $enc | whiptail --title "Rapid Seed Progress" --gauge "Percentage of seed written to device" 8 78 0 3>&2 2>&1 1>&3 if [[ $? -ne 0 ]] then whiptail --title "Error" --msgbox "An error has occurred please check log file at /usr/bp/logs.dir/seed.log for more information" 8 78 3>&2 2>&1 1>&3 exit 3 fi fi #for i in `seq 1 100` #do # sleep .5 # echo $i #done #} | whiptail --title "Rapid Seed Progress" --gauge "Percentage of seed written to device" 8 78 0 3>&2 2>&1 1>&3 #send seed complete successfully trap message, stop time, client list (maybe), size of seed (maybe) if [[ $sdNAS -eq 1 ]] then date=`date +"%m_%d_%y_%H_%M"` #### TODO send email #### else date=`date +"%m_%d_%y_%H_%M"` #### TODO send email #### fi if [[ $eml -eq 0 ]] then if [[ $sdNAS -eq 1 ]] then echo "Seed export is complete for $assetTag at ${date}. Seed is ready to be shipped" | mail -s "Seed Notification" $emlAddr else echo "Seed export is complete for $assetTag at ${date}. Seed is ready to be shipped" | mail -s "Seed Notification" $emlAddr fi fi else whiptail --title "Rapid Seed" --msgbox "Returning to Main Menu" 8 78 3>&2 2>&1 1>&3 fi else whiptail --title "Rapid Seed" --msgbox "Returning to Main Menu" 8 78 3>&2 2>&1 1>&3 fi ;; targetseed) if [[ $conf -ne 1 ]] then whiptail --title "Warning" --msgbox "You have not run through the configuration settings yet. Please configure the IP address of the system before proceeding." 8 78 continue fi if [[ $nas -eq 1 ]] then valid="1" while [ "$valid" -eq 1 ] do ipt=$(whiptail --title "Rapid Seed" --inputbox "Enter the IP address of the Unitrends appliance" 8 78 --nocancel 3>&2 2>&1 1>&3) validIP $ipt done pw=$(whiptail --title "Rapid Seed" --inputbox "Enter the Unitrends appliance OS password" 8 78 --nocancel 3>&2 2>&1 1>&3) uipw=$(whiptail --title "Rapid Seed" --inputbox "Enter the Unitrends appliance UI password" 8 78 --nocancel 3>&2 2>&1 1>&3) whiptail --title "Rapid Seed" --msgbox "Will perform seed operation against DPU at $ip with OS password: $pw and UI password: $uipw" 8 78 3>&2 2>&1 1>&3 fi #need to call repSet from here to enable replication then direct the end user to create a backup job schedule to perform the seed #new systems should all be on 9.0 defualt UI password of the target at this time is unitrends1, cloudops should change this after the fact #password could change based on target autoconfigs for nlc,mtr, or 4fv. Need to check which this is. May need a secondary question with regards #to which cloud subscription package they selected. Or create the target with the right name and apply the changes after import into cloud. repSet target $ipt $pw $uipw $ipc #send start seed trap #if [[ $nas -eq 1]] #then #ussh "/tmp/any_snmptrap_sender.py -c -m \"Seed start for $assetTag at $date, seed size is $size\"" #else #snmp "Seed start for $assetTag at $date, seed size is $size" #fi #start replication seeding #upon complete of seeding send completion trap here #if [[ nas -eq 1 ]] #then #$ussh "/tmp/any_snmptrap_sender.py -c -m \"Seed completed for $assetTag at $date, seed size is $size, number of clients is $numClients\"" #else #snmp "Seed completed for $assetTag at $date, seed size is $size, number of clients is $numClients" #fi ;; *) if [[ $nas -eq 1 ]] then whiptail --title "Unitrends Rapid Seed" --msgbox "You have chosen to exit the Unitrends RapidNAS configuration system. Returning you to the command line." 8 78 else whiptail --title "Unitrends Rapid Seed" --msgbox "You have chosen to exit the rapid seed wizard" 8 78 fi status=1 if [[ $debug -eq 0 ]] then if [[ $nas -eq 0 ]] then exit 0 fi else exit 0 fi ;; esac done else if [[ $nas -eq 1 ]] then whiptail --title "Unitrends Rapid Seed" --msgbox "You have chosen to exit the Unitrends RapidNAS configuration system. Returning you to the commmand line." 8 78 else whiptail --title "Unitrends Rpaid Seed" --msgbox "You have chosen to exit the rapid seed wizard" 8 78 fi if [[ $debug -eq 0 ]] then if [[ $nas -eq 0 ]] then exit 0 fi else exit 0 fi fi else whiptail --title "Unitrends Rapid Seed" --msgbox "The system is configured and you may now start seeding operations from the Unitrends Appliance." 8 78 exit 0 fi } function cldImpDD(){ function validIP(){ if [[ -z $2 ]] then sub="255.255.255.0" else sub=$2 fi ip=$1 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] then OIFS=$IFS IFS='.' ipn=($ip) subn=($sub) IFS=$OIFS [[ ${ipn[0]} -le 255 && ${ipn[1]} -le 255 && ${ipn[2]} -le 255 && ${ipn[3]} -le 255 ]] stat1=$? [[ ${subn[0]} -le 255 && ${subn[1]} -le 255 && ${subn[2]} -le 255 && ${subn[3]} -le 255 ]] stat2=$? if [[ $stat1 -eq 0 ]] then if [[ $stat2 -eq 0 ]] then valid=0 else whiptail --title "Error" --msgbox "You have entered an invalid IP address or subnet, Please try again" 8 78 fi else whiptail --title "Error" --msgbox "You have entered an invalid IP address or subnet, Please try again" 8 78 fi else whiptail --title "Error" --msgbox "You have entered an invalid IP address or subnet, Please try again" 8 78 fi } #function for importing for unitrends cloud single disk seed #for unitrends cloud services sshpass will need to be installed on the first run for any target. sps=`rpm -qa | grep sshpass` cvrs=`dpu version | grep Version | awk -F"." '{print $NF}' | sed -e 's/^.*\(.\)$/\1/'` if [[ -z $sps ]] then if [[ $cvrs -eq 6 ]] then yum install -y http://dl.fedoraproject.org/pub/epel/6/i386/sshpass-1.05-1.el6.i686.rpm else yum install -y http://dl.fedoraproject.org/pub/epel/5/i386/sshpass-1.05-1.el5.i386.rpm fi fi valid=1 while [ "$valid" -eq 1 ] do bayIP=`whiptail --title "Unitrends Cloud Seed Import" --inputbox "Please enter the IP address of the single drive seed bay" 8 78 3>&2 2>&1 1>&3` enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` if [[ -z $bayIP ]] then whiptail --title "Unitrends Rapid Seed Import" --msgbox "You have canceled the operation. Canceling the import operation" 8 78 fi validIP $bayIP if [[ $valid -eq 0 ]] then pc=`ping -c1 $bayIP >/dev/null 2>&1;echo $?` if [[ $pc -eq 0 ]] then isBay=`sshpass -p unitrends1 ssh root@$bayIP "if [[ -f /reports/new_seed.csv ]];then echo 0;else echo 1;fi"` if [[ $isBay -eq 0 ]] then valid=0 else valid=1 whiptail --title "Error" --msgbox "The provided IP address does not identify as a seed bay. Check the IP and try again." 8 78 fi else valid=1 whiptail --title "Error" --msgbox "The provided IP address does not respond or is unreachable on the network. Check the IP and try again." 8 78 fi fi done cssh="sshpass -p unitrends1 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$bayIP" adv=`$cssh "cat /reports/new_seed.csv" | awk -F"," '{print $1" "$2}'` #adv=`cat drv_att` whiptail --title "Unitrends Cloud Seed Import" --infobox "Collecting available drive list" 8 78 imp=`whiptail --title "Unitrends Cloud Seed Import" --menu "Select drive to import" 20 78 10 $adv 3>&2 2>&1 1>&3` if [[ -z $imp ]] then whiptail --title "Error" --msgbox "No drive selected. Exiting seed import menu." 8 78 exit 0 fi #echo $imp #echo $cssh #echo $bayIP mntNM=`echo "$adv" | grep $imp | awk '{print $2}'` $cssh "mkdir /mnt/$mntNM" >/dev/null 2>&1 $cssh "mount /dev/$imp /mnt/$mntNM" >/dev/null 2>&1 smbE=`cat <<-EOF [$mntNM] path = /mnt/$mntNM public = yes browsable = yes writeable = yes guest ok = yes EOF` $cssh "echo \"$smbE\" >> /etc/samba/smb.conf" >/dev/null 2>&1 #remove selected seed device from the list. $cssh "sed -i 's/$imp,$mntNM//' /reports/new_seed.csv" #add seed device to in progress list $cssh "echo \"$imp,$mntNM\" >> /reports/new_imp_seed.csv" >/dev/null 2>&1 #then mount the share to /mnt/seed sleep 120 mkdir /mnt/$mntNM mount -t cifs -o username=guest,password="" //$bayIP/$mntNM /mnt/$mntNM >/dev/null 2>&1 #copy in seed_receipt($sr) into /usr/bp/logs.dir as $(echo $sr | sed 's/.log//g')_$(cat /mnt/seed/.asset).log sr=`ls /mnt/$mntNM | grep seed_receipt` #sr="seed_receipt_$mntNM.log" cp /mnt/$mntNM/$sr /usr/bp/logs.dir/$(echo $sr | sed 's/.log//g')_${mntNM}.log >/dev/null 2>&1 #then perform rseed import operation touch /mnt/$mntNM/.in_progress rseed -ic /mnt/$mntNM -p $enpw if [[ $? -eq 8 ]] then return 8 fi #once complete remove mount touch /mnt/$mntNM/.completed umount /mnt/$mntNM >/dev/null 2>&1 #remove share information $cssh "sed -i '/\[$mntNM\]/,+5d' /etc/samba/smb.conf" >/dev/null 2>&1 #dismount drive from seed disk bay $cssh "umount /mnt/$mntNM" >/dev/null 2>&1 #remove from inprogress to complete list $cssh "sed -i 's/$imp,$mntNM//' /reports/new_imp_seed.csv" >/dev/null 2>&1 #and append drive information to remove disk file $cssh "echo \"$imp,$mntNM\" >> /reports/new_cmp_seed.csv" >/dev/null 2>&1 } function impdrv(){ function drv_chk(){ dr=`lsscsi | grep disk | awk '{print $NF}'` for sdev in $dr do drv=`echo $sdev | awk -F"/" '{print $NF}'` if [[ `lsscsi | grep disk | grep $sdev >/dev/null 2>&1;echo $?` -eq 0 ]] then if [[ `cat /proc/mdstat | grep $drv >/dev/null 2>&1;echo $?` -ne 0 ]] then if [[ `mount | grep $sdev >/dev/null 2>&1;echo $?` -ne 0 ]] then if [[ `pvdisplay | grep $sdev >/dev/null 2>&1;echo $?` -ne 0 ]] then drl+="$sdev " fi fi fi fi done echo $drl } function drv_list(){ dv=`drv_chk` for i in $dv do #dsz=`lsscsi -s | grep $i | awk '{print $NF}'` #ser=`lsscsi -s | grep $i | awk '{a=NF-3}{print $a}'` ser=`smartctl -a $i | grep "Device Model" | awk '{print $NF}'` dsz=`smartctl -a $i | grep "Capacity" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}' | awk '{print $1$2}'` echo "$i ${ser}____${dsz}" done } whiptail --title "Collecting Drive Data" --infobox "Collecting drive information on all available drives" 8 78 3>&2 2>&1 1>&3 drive=`whiptail --title "Drive Selection" --menu "Please select a drive to import seed data from" 16 78 5 $(drv_list) 3>&2 2>&1 1>&3` echo $drive } function selectClients() { whiptail --title "Selective Seeding" --yesno "Have you mounted the seed device already?" 8 78 if [[ $? -eq 1 ]] then whiptail --title "Error" --infobox "Seed device must be mounted to /mnt/seed before using this function." 8 78 exit 0 fi mount | grep /mnt/seed >/dev/null 2>&1 if [[ $? -ne 0 ]] then whiptail --title "Error" --infobox "Seed device not found at expected location of /mnt/seed please mount seed device here and try again." 8 78 exit 0 fi whiptail --title "Selective Seeding" --msgbox "engaging selective seeding mode" 8 78 #will need to get list of clients to seed, mount storage device to /mnt/seed and then call rseed -C clients=`repSet selective` strt="0" while [ "$strt" -eq "0" ] do if [[ `echo $clients | wc -w` -le 0 ]] then whiptail --title "Error" --msgbox "You must select at least one client for seeding" 8 78 whiptail --title "Error" --yesno "Would you like to try again?" 8 78 if [[ $? -eq 0 ]] then strt="0" else whiptail --title "Error" --msgbox "You chosen to exit, Aborting seed Operation" 8 78 exit 1 fi clients=`repSet selective` else strt="1" fi done clientS=`echo $clients | sed 's/"//g' | sed 's/ /,/g'` enpw=`whiptail --title "Selective Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw while [[ $? -eq 1 ]] do enpw=`whiptail --title "Selective Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw done #get chosen media to mount rseed -sC $clientS -p $enpw | whiptail --title "Rapid Seed Progress" --gauge "Percentage of seed written to device" 8 78 0 3>&2 2>&1 1>&3 } function chkIP(){ if [[ -z $2 ]] then sub="255.255.255.0" else sub=$2 fi ip=$1 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] then OIFS=$IFS IFS='.' ipn=($ip) subn=($sub) IFS=$OIFS [[ ${ipn[0]} -le 255 && ${ipn[1]} -le 255 && ${ipn[2]} -le 255 && ${ipn[3]} -le 255 ]] stat1=$? [[ ${subn[0]} -le 255 && ${subn[1]} -le 255 && ${subn[2]} -le 255 && ${subn[3]} -le 255 ]] stat2=$? if [[ $stat1 -eq 0 ]] then if [[ $stat2 -eq 0 ]] then ping -c1 $1 >/dev/null if [[ $? -eq 0 ]] then return 0 else whiptail --title "Error" --msgbox "The IP address entered does not respond on the network. Please Check the IP address and try again." 8 78 return 1 fi else whiptail --title "Error" --msgbox "You have entered an invalid IP address. Please try again" 8 78 return 1 fi else whiptail --title "Error" --msgbox "You have entered an invalid IP address. Please try again" 8 78 return 1 fi else whiptail --title "Error" --msgbox "You have entered an invalid IP address. Please try again" 8 78 return 1 fi } function chkENC(){ if [[ `expr "$1" : ".*[!@#\$%^\&*\:\;,\(\)<>_.\+\-\= ].*"` -gt 0 ]] then whiptail --title "Error" --msgbox "Invalid use of special character in encryption passphrase" 8 78 return 1 else if [[ -z $1 ]] then whiptail --title "Error" --msgbox "Blank encryption passphrase is not allowed" 8 78 return 1 else return 0 fi fi } function sdbyIP(){ octet=`ifconfig eth0 | awk '{match($0,/inet addr:([^ ]+)/,a);x=x FS a[1]}END {print x}' | awk -F"." '{print $2}'` case $octet in 207) echo "10.207.15.200";; 209) echo "10.209.15.200";; *) #setting default to Denver seed bay echo "10.201.0.254";; esac } case $1 in -d) case $2 in NAS) nas=1 menu -d ;; import) op=$(whiptail --title "Rapid Seed Import Menu" --menu "Select an option to proceed" 16 78 5 \ "Rapid NAS" "import" \ "Disk Drive" "import" --cancel-button "Exit" 3>&2 2>&1 1>&3) opt=$(echo $op | sed 's/ //g') if [[ -z $op ]] then whiptail --title "Unitrends Rapid Seed Import" --msgbox "You have canceled the operation. Canceling the import operation" 8 78 fi case $opt in RapidNAS) tg=`whiptail --title "Import Seed" --inputbox "Enter an IP address of the seed device to import from in the format of XXX.XXX.XXX.XXX" 8 78 --nocancel 3>&2 2>&1 1>&3` enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` nas=1 ;; DiskDrive) tg=`impdrv` if [[ -z $tg ]] then whiptail --title "Unitrends Rapid Seed Import" --msgbox "You have canceled the operation. Canceling the import operation" 8 78 fi enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` nas=0 ;; esac if [[ $nas -eq 1 ]] then echo "calling rseed" echo "rseed -in $tg -p $enpw" rseed -in $tg -p $enpw else echo "calling rseed" echo "rseed -idl $tg -p $enpw" fi ;; *) nas=0 menu -d ;; esac ;; NAS) nas=1 menu ;; import) op=$(whiptail --title "Rapid Seed Import Menu" --menu "Select an option to proceed" 16 78 5 \ "Rapid NAS" "import" \ "Disk Drive" "import" --cancel-button "Exit" 3>&2 2>&1 1>&3) if [[ -z $op ]] then whiptail --title "Unitrends Rapid Seed Import" --msgbox "You have canceled the operation. Canceling the import operation" 8 78 fi eml=`whiptail --title "Rapid Seed" --yesno "Would you like a notification upon seed operation completion?" 8 78 3>&2 2>&1 1>&3;echo $?` if [[ $eml -eq 0 ]] then emlAddr=`whiptail --title "Rapid Seed" --inputbox "Please enter the receiver's email address, for multiple email address, use a space seperator\n\n*Please note that email setup must be completed successfully for email completion notifications" --nocancel 10 78 3>&2 2>&1 1>&3` fi opt=$(echo $op | sed 's/ //g') case $opt in RapidNAS) tg=`whiptail --title "Import Seed" --inputbox "Enter an IP address of the seed device to import from in the format of XXX.XXX.XXX.XXX" 8 78 --nocancel 3>&2 2>&1 1>&3` chkIP $tg while [[ $? -eq 1 ]] do tg=`whiptail --title "Import Seed" --inputbox "Enter an IP address of the seed device to import from in the format of XXX.XXX.XXX.XXX" 8 78 --nocancel 3>&2 2>&1 1>&3` chkIP $tg done enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw while [[ $? -eq 1 ]] do enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw done nas=1 ;; DiskDrive) tg=`impdrv` if [[ -z $tg ]] then whiptail --title "Unitrends Rapid Seed Import" --msgbox "You have canceled the operation. Canceling the import operation" 8 78 fi enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw while [[ $? -eq 1 ]] do enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw done nas=0 ;; esac if [[ $nas -eq 1 ]] then # echo "calling rseed" rseed -in $tg -p $enpw if [[ $eml -eq 0 ]] then echo "seed import completed for target $(cat /etc/unitrends-asset). Seed is ready to be disconnected" | mail -s "Seed Notification" $emlAddr fi else # echo "calling rseed" rseed -idl $tg -p $enpw if [[ $eml -eq 0 ]] then echo "seed import completed for target $(cat /etc/unitrends-asset). Seed is ready to be disconnected" | mail -s "Seed Notification" $emlAddr fi fi ;; cloud) op=$(whiptail --title "Unitrends Rapid Seed Import Menu" --menu "Select an option to proceed" 16 78 5 \ "Rapid NAS" "import" \ "Disk Drive" "import" --cancel-button "Exit" 3>&2 2>&1 1>&3) if [[ -z $op ]] then whiptail --title "Unitrends Rapid Seed Import" --msgbox "You have canceled the operation. Canceling the import operation" 8 78 fi eml=`whiptail --title "Rapid Seed" --yesno "Would you like a notification upon seed operation completion?" 8 78 3>&2 2>&1 1>&3;echo $?` if [[ $eml -eq 0 ]] then emlAddr=`whiptail --title "Rapid Seed" --inputbox "Please enter the receiver's email address, for multiple email address, use a space seperator\n\n*Please note that email setup must be completed successfully for email completion notifications" --nocancel 10 78 3>&2 2>&1 1>&3` fi sps=`rpm -qa | grep sshpass` cvrs=`dpu version | grep Version | awk -F"." '{print $NF}' | sed -e 's/^.*\(.\)$/\1/'` if [[ -z $sps ]] then if [[ $cvrs -eq 6 ]] then yum install -y ftp://ftp.unitrends.com/outgoing/rsanchez/brp/sshpass-1.06-1.el6.i686.rpm else yum install -y http://dl.fedoraproject.org/pub/epel/5/i386/sshpass-1.05-1.el5.i386.rpm fi fi opt=$(echo $op | sed 's/ //g') case $opt in RapidNAS) #add size check to confirm that import can land, free space must be larger than seed total in .receipt | tail -n1 (this should most likely be performed inside of rseed) #request NAS serial number tg=`whiptail --title "Import Seed" --inputbox "Enter an IP address of the seed device to import from in the format of XXX.XXX.XXX.XXX" 8 78 --nocancel 3>&2 2>&1 1>&3` enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw while [[ $? -eq 1 ]] do enpw=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $enpw done nas=1 #echo "calling rseed" rseed -in $tg -p $enpw #need to add a validator for successful imports and then add call to seed bay system to remove connected device once done. if [[ $? -eq 8 ]] then whiptail --title "Import Seed" --msgbox "Detected an unsuccessful import. Please check the appropiate hactarToctar logs and the UI for more information." 8 78 3>&2 2>&1 1>&3 else gdSRN=1 while [ "$gdSRN" -eq 1 ] do SRN=`whiptail --title "Import Seed" --inputbox "Enter serial number of the seed device" 8 78 --nocancel 3>&2 2>&1 1>&3` if [[ -z $SRN ]] then whiptail --title "Import Seed" --msgbox "Serial number cannot be blank" 8 78 3>&2 2>&1 1>&3 else gdSRN=0 denCHK=`ping -c1 $(sdbyIP) >/dev/null 2>&1;echo $?` if [[ $denCHK -eq 0 ]] then sshpass -p unitrends1 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$(sdbyIP) "echo \"$SRN\" >> /reports/detach_completed_seeds.txt" >/dev/null 2>&1 fi fi done if [[ $eml -eq 0 ]] then echo "seed import completed for target $(cat /etc/unitrends-asset). Seed is ready to be disconnected" | mail -s "Seed Notification" $emlAddr fi whiptail --title "Import Seed" --msgbox "Seed Import operation completed successfully. Imported backups have been successfully validated" 8 78 3>&2 2>&1 1>&3 fi ;; DiskDrive) #add size check to confirm that import can land, free space must be larger than seed total in .receipt | tail -n1 (this should most likely be performed inside of rseed) #request single drive serial number isMount=`whiptail --title "Import Seed" --yesno "Has the drive already been mounted to the target?" 8 78 3>&2 2>&1 1>&3;echo $?` if [[ $isMount -eq 0 ]] then mLoc=`whiptail --title "Import Seed" --inputbox "Please provide the mount point path" 8 78 --nocancel 3>&2 2>&1 1>&3` ePwd=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $ePwd while [[ $? -eq 1 ]] do ePwd=`whiptail --title "Import Seed" --inputbox "Enter encryption passphrase" 8 78 --nocancel 3>&2 2>&1 1>&3` chkENC $ePwd done rseed -ic $mLoc -p $ePwd if [[ $? -eq 8 ]] then whiptail --title "Import Seed" --msgbox "Detected an unsuccessful import. Please check the appropiate hactarToctar logs and the UI for more information." 8 78 3>&2 2>&1 1>&3 else gdSRN=1 while [ "$gdSRN" -eq 1 ] do SRN=`whiptail --title "Import Seed" --inputbox "Enter serial number of the seed device" 8 78 --nocancel 3>&2 2>&1 1>&3` if [[ -z $SRN ]] then whiptail --title "Import Seed" --msgbox "Serial number cannot be blank" 8 78 3>&2 2>&1 1>&3 else gdSRN=0 denCHK=`ping -c1 $(sdbyIP) >/dev/null 2>&1;echo $?` if [[ $denCHK -eq 0 ]] then sshpass -p unitrends1 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$(sdbyIP) "echo \"$SRN\" >> /reports/detach_completed_seeds.txt" >/dev/null 2>&1 fi fi done if [[ $eml -eq 0 ]] then echo "seed import completed for target $(cat /etc/unitrends-asset). Seed is ready to be disconnected" | mail -s "Seed Notification" $emlAddr fi whiptail --title "Import Seed" --msgbox "Seed Import operation completed successfully. Imported backups have been successfully validated" 8 78 3>&2 2>&1 1>&3 fi else cldImpDD if [[ $? -eq 8 ]] then whiptail --title "Import Seed" --msgbox "Detected an unsuccessful import. Please check the appropiate hactarToctar logs and the UI for more information." 8 78 3>&2 2>&1 1>&3 else gdSRN=1 while [ "$gdSRN" -eq 1 ] do SRN=`whiptail --title "Import Seed" --inputbox "Enter serial number of the seed device" 8 78 --nocancel 3>&2 2>&1 1>&3` if [[ -z $SRN ]] then whiptail --title "Import Seed" --msgbox "Serial number cannot be blank" 8 78 3>&2 2>&1 1>&3 else gdSRN=0 denCHK=`ping -c1 $(sdbyIP) >/dev/null 2>&1;echo $?` if [[ $denCHK -eq 0 ]] then sshpass -p unitrends1 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$(sdbyIP) "echo \"$SRN\" >> /reports/detach_completed_seeds.txt" >/dev/null 2>&1 fi fi done if [[ $eml -eq 0 ]] then echo "seed import completed for target $(cat /etc/unitrends-asset). Seed is ready to be disconnected" | mail -s "Seed Notification" $emlAddr fi whiptail --title "Import Seed" --msgbox "Seed Import operation completed successfully. Imported backups have been successfully validated" 8 78 3>&2 2>&1 1>&3 fi fi ;; esac ;; rs) #echo ${@:2} #eml=`whiptail --title "Rapid Seed" --yesno "Would you like a notification upon seed operation completion?" 8 78 3>&2 2>&1 1>&3;echo $?` #if [[ $eml -eq 0 ]] #then # emlAddr=`whiptail --title "Rapid Seed" --inputbox "Please enter the receiver's email address, for multiple email address, use a space seperator\n\n*Please note that email setup must be completed successfully for email completion notifications" --nocancel 10 78 3>&2 2>&1 1>&3` #fi rseed ${@:2} #need to add a validator for successful import to rseed function and then add call to seed bay system to remove connected device once done. #if [[ $eml -eq 0 ]] #then # echo "Seed export is complete for $(cat /etc/unitrends-asset) at ${date}. Seed is ready to be shipped" | mail -s \"Seed Notification\" $emlAddr #fi ;; sIa) #require $2 and $3. where $2 is the path and $3 is the password. if [[ -z $2 ]] || [[ -z $3 ]] then echo "Missing required parameters" else openssl enc -d -rc4 -in $2 -k "$3" | /usr/bp/bin/hactarToctar -F -C 2>&1>>/usr/bp/logs.dir/seed_dec.log & fi ;; detach) whiptail --title " Import Seed" --msgbox "Performing notification for drive or nas to be removed. Please be aware this will not unmount any partitions that are left mounted." 8 78 3>&2 2>&1 1>&3 gdSRN=1 while [ "$gdSRN" -eq 1 ] do SRN=`whiptail --title "Import Seed" --inputbox "Enter serial number of the seed device" 7 78 --nocancel 3>&2 2>&1 1>&3` if [[ -z $SRN ]] then whiptail --title "Import Seed" --msgbox "Serial number cannot be blank" 8 78 3>&2 2>&1 1>&3 else gdSRN=0 #check which data center we are at and contact the correct seed bay system. denCHK=`ping -c1 $(sdbyIP) >/dev/null 2>&1;echo $?` if [[ $denCHK -eq 0 ]] then sshpass -p unitrends1 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$(sdbyIP) "echo \"$SRN\" >> /reports/detach_completed_seeds.txt" >/dev/null 2>&1 fi fi done ;; selective) echo "selective seeding" selectClients ;; *) nas=0 menu exit $? ;; esac