I am constantly having to pre-create or migrate massive amounts of LUNs in customer environments. I have many ways to go about it, powershell, ruby, but my awk script is my #1 way to do it
Imagine having to make luns for dozens of database instances on multiple hosts for dev/prod/qa. Suckage!
They all would follow a certain order and naming convention. Most of the sizes would be the same.
If I have to do anything once, I’ll probably have to do it again. So, script it! This will work in any shell with awk (osx/linux/solaris/CygWin)
First I make my descriptor file. Typically this is autogenerated as well. If I have X DB instances per host, and they follow the same structure I’ll just loop over the name. This works the same for 1 lun or thousands.
In this case I am making my luns for a windows system on a 7-mode box. I’ll add Cluster Mode shortly!
PURPOSE:LUN_SIZE:VOL_SIZE:UNIQ_ID:IGROUP_NAME:OS
1 2 3 4 5 6 7 8 9 |
e:30:50:aggr0:sg1_db:intellmail1:windows k:8:10:aggr0:sg1_db:intellmail1:windows f:30:50:aggr0:sg1_db:intellmail1:windows i:30:50:aggr0:sg1_db:intellmail1:windows j:30:50:aggr0:sg1_db:intellmail1:windows sg1_log_l:10:20:aggr0:exch_log:intellmail1:windows sg1_log_m:10:20:aggr0:exch_log:intellmail1:windows sg1_log_n:10:20:aggr0:exch_log:intellmail1:windows sg1_log_o:10:20:aggr0:exch_log:intellmail1:windows |
Next, comes our awk script.
1 2 3 4 5 6 7 8 |
for i in `cat mounts1.txt` ; do echo $i | awk -F':' '{print "vol create vol_"$6"_"$1"_"$5"_san -s volume "$4" "$3"g"}'; echo $i | awk -F':' '{print "vol options vol_"$6"_"$1"_"$5"_san nosnap on"}'; echo $i | awk -F':' '{print "vol autosize vol_"$6"_"$1"_"$5"_san -m " $3*2"g"}'; echo $i | awk -F':' '{print "snap reserve vol_"$6"_"$1"_"$5"_san 0"}'; echo $i | awk -F':' '{print "lun create -s "$2"g -t "$7" /vol/vol_"$6"_"$1"_"$5"_san/lun_"$6"_"$5"_"$1}'; echo $i | awk -F':' '{print "lun map /vol/vol_"$6"_"$1"_"$5"_san/lun_"$6"_"$5"_"$1" "$6"\n\n"}'; done |
Line 1: Looping over the mounts.txt file
Line 2: Volume creation
Line 3: Turn off auto snapshotting on volume
Line 4: Set volume auto grow to twice the volume size
Line 5: Turn off snap reserve
Line 6: Create LUN in precreated volume
Line 7: Map Lun to igroup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
jk-47:luncreation jk-47$ for i in `cat mounts1.txt` ; do > echo $i | awk -F':' '{print "vol create vol_"$6"_"$1"_"$5"_san -s volume "$4" "$3"g"}'; > echo $i | awk -F':' '{print "vol options vol_"$6"_"$1"_"$5"_san nosnap on"}'; > echo $i | awk -F':' '{print "vol autosize vol_"$6"_"$1"_"$5"_san -m " $3*2"g"}'; > echo $i | awk -F':' '{print "snap reserve vol_"$6"_"$1"_"$5"_san 0"}'; > echo $i | awk -F':' '{print "lun create -s "$2"g -t "$7" /vol/vol_"$6"_"$1"_"$5"_san/lun_"$6"_"$5"_"$1}'; > echo $i | awk -F':' '{print "lun map /vol/vol_"$6"_"$1"_"$5"_san/lun_"$6"_"$5"_"$1" "$6"\n\n"}'; > done vol create vol_intellmail1_e_sg1_db_san -s volume aggr0 50g vol options vol_intellmail1_e_sg1_db_san nosnap on vol autosize vol_intellmail1_e_sg1_db_san -m 100g snap reserve vol_intellmail1_e_sg1_db_san 0 lun create -s 30g -t windows /vol/vol_intellmail1_e_sg1_db_san/lun_intellmail1_sg1_db_e lun map /vol/vol_intellmail1_e_sg1_db_san/lun_intellmail1_sg1_db_e intellmail1 vol create vol_intellmail1_k_sg1_db_san -s volume aggr0 10g vol options vol_intellmail1_k_sg1_db_san nosnap on vol autosize vol_intellmail1_k_sg1_db_san -m 20g snap reserve vol_intellmail1_k_sg1_db_san 0 lun create -s 8g -t windows /vol/vol_intellmail1_k_sg1_db_san/lun_intellmail1_sg1_db_k lun map /vol/vol_intellmail1_k_sg1_db_san/lun_intellmail1_sg1_db_k intellmail1 vol create vol_intellmail1_f_sg1_db_san -s volume aggr0 50g vol options vol_intellmail1_f_sg1_db_san nosnap on vol autosize vol_intellmail1_f_sg1_db_san -m 100g snap reserve vol_intellmail1_f_sg1_db_san 0 lun create -s 30g -t windows /vol/vol_intellmail1_f_sg1_db_san/lun_intellmail1_sg1_db_f lun map /vol/vol_intellmail1_f_sg1_db_san/lun_intellmail1_sg1_db_f intellmail1 vol create vol_intellmail1_i_sg1_db_san -s volume aggr0 50g vol options vol_intellmail1_i_sg1_db_san nosnap on vol autosize vol_intellmail1_i_sg1_db_san -m 100g snap reserve vol_intellmail1_i_sg1_db_san 0 lun create -s 30g -t windows /vol/vol_intellmail1_i_sg1_db_san/lun_intellmail1_sg1_db_i lun map /vol/vol_intellmail1_i_sg1_db_san/lun_intellmail1_sg1_db_i intellmail1 vol create vol_intellmail1_j_sg1_db_san -s volume aggr0 50g vol options vol_intellmail1_j_sg1_db_san nosnap on vol autosize vol_intellmail1_j_sg1_db_san -m 100g snap reserve vol_intellmail1_j_sg1_db_san 0 lun create -s 30g -t windows /vol/vol_intellmail1_j_sg1_db_san/lun_intellmail1_sg1_db_j lun map /vol/vol_intellmail1_j_sg1_db_san/lun_intellmail1_sg1_db_j intellmail1 vol create vol_intellmail1_sg1_log_l_exch_log_san -s volume aggr0 20g vol options vol_intellmail1_sg1_log_l_exch_log_san nosnap on vol autosize vol_intellmail1_sg1_log_l_exch_log_san -m 40g snap reserve vol_intellmail1_sg1_log_l_exch_log_san 0 lun create -s 10g -t windows /vol/vol_intellmail1_sg1_log_l_exch_log_san/lun_intellmail1_exch_log_sg1_log_l lun map /vol/vol_intellmail1_sg1_log_l_exch_log_san/lun_intellmail1_exch_log_sg1_log_l intellmail1 vol create vol_intellmail1_sg1_log_m_exch_log_san -s volume aggr0 20g vol options vol_intellmail1_sg1_log_m_exch_log_san nosnap on vol autosize vol_intellmail1_sg1_log_m_exch_log_san -m 40g snap reserve vol_intellmail1_sg1_log_m_exch_log_san 0 lun create -s 10g -t windows /vol/vol_intellmail1_sg1_log_m_exch_log_san/lun_intellmail1_exch_log_sg1_log_m lun map /vol/vol_intellmail1_sg1_log_m_exch_log_san/lun_intellmail1_exch_log_sg1_log_m intellmail1 vol create vol_intellmail1_sg1_log_n_exch_log_san -s volume aggr0 20g vol options vol_intellmail1_sg1_log_n_exch_log_san nosnap on vol autosize vol_intellmail1_sg1_log_n_exch_log_san -m 40g snap reserve vol_intellmail1_sg1_log_n_exch_log_san 0 lun create -s 10g -t windows /vol/vol_intellmail1_sg1_log_n_exch_log_san/lun_intellmail1_exch_log_sg1_log_n lun map /vol/vol_intellmail1_sg1_log_n_exch_log_san/lun_intellmail1_exch_log_sg1_log_n intellmail1 vol create vol_intellmail1_sg1_log_o_exch_log_san -s volume aggr0 20g vol options vol_intellmail1_sg1_log_o_exch_log_san nosnap on vol autosize vol_intellmail1_sg1_log_o_exch_log_san -m 40g snap reserve vol_intellmail1_sg1_log_o_exch_log_san 0 lun create -s 10g -t windows /vol/vol_intellmail1_sg1_log_o_exch_log_san/lun_intellmail1_exch_log_sg1_log_o lun map /vol/vol_intellmail1_sg1_log_o_exch_log_san/lun_intellmail1_exch_log_sg1_log_o intellmail1 |
That’s it. Copy and paste in groups into your SSH to your netapp.
Comments are closed.