A coworker asked me this afternoon if I could whip up a script to convert hundreds of volumes, many client, 7-mode /etc/exports files into Clustered Mode Export Policies and client rules.
No problem! Nothing is too hard for some ugly bash scripting.
Now, this first version is pretty brute force, and doesn’t handle all security styles. It’s just to get them in there with each client as it’s own rule. It assumes volumes are already created on mounted on the root of the namespace. It’s also poorly tested 😉
Sample exports file:
1 2 3 4 5 |
/vol/XYZcuat_app01 -sec=sys,rw,nosuid /vol/XYZcuat_dat01 -sec=sys,rw,nosuid /vol/XYZsuat_app01 -sec=sys,rw,root=mt-116.us.example.com:mt-116-nas.us.example.com /vol/XYZsuat_dat01 -sec=sys,rw,root=mt-116.us.example.com:mt-116-nas.us.example.com /vol/XYZcuat_linux_fc_3270_rr_01 -sec=sys,rw,root=na-ux00-nas.us.example.com:mt64-019-file.us.example.com:na-ux00.us.example.com |
Save that into the same directory as my script.
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 |
#!/bin/bash ########################################################################################## # mig7mode2cDotexport.sh # Needs: bash (or cygwin in windows), cat, awk, grep, dos2unix # (c) 2015 - Twitter @JK47TheWeapon - Jarett Kulm # v0.1 - 20150417 - Quick and dirty way to convert Netapp 7-mode # exports file into a clustered mode export policy # # Usage: # * Save the exportsfs file in the directory with the script # * Run the script # * Enter the destination NFS vServer when prompted # * Enter the 70mode exports filename when prompted ############################################################################################ read -p "Enter vserver name : " vservername read -p "Enter exports filename: " exportsfile dos2unix -q $exportsfile cat $exportsfile | awk '{print $1}' > volumes.txt grep "/vol/" volumes.txt | awk -F'/vol/' '{print "/vol/"$2":/"$2}' > volume_mapper.txt cat volume_mapper.txt | while IFS=: read source7Mvolume cDotVolume do echo "#### Source 7-mode Volume='$source7Mvolume' Destination Clustered Mode Volume='$cDotVolume'" sleep 1 volpolname=`echo $cDotVolume"_exp_pol" | awk -F'/' '{print $2}'` cDotVolume=`echo $cDotVolume | awk -F'/' '{print $2}'` echo "create -vserver $vservername -policyname $volpolname" echo "export-policy rule create -vserver $vservername -policyname $volpolname" echo "volume modify -vserver $vservername -policy $volpolname -volume $cDotVolume" charactercount=`grep -o '/' <<< $source7Mvolume | grep -c .` if [ $charactercount -eq 2 ] ;then for ourclients in `grep $source7Mvolume$'\t' $exportsfile ` do if grep -q "nosuid" <<< $ourclients;then echo -n 'export-policy rule create -vserver '$vservername' -policyname '$volpolname' -clientmatch any -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs' echo " " echo " " elif grep -q "rw,anon" <<< $ourclients;then echo -n 'export-policy rule create -vserver '$vservername' -policyname '$volpolname' -clientmatch any -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs' echo " " echo " " elif grep -q "root=" <<< $ourclients ;then for clientname in `grep $source7Mvolume$'\t' $exportsfile | awk -F'root=' '{print $2}' | tr ":" " " | sort | uniq`;do echo -n 'export-policy rule create -vserver '$vservername' -policyname '$volpolname' -clientmatch '$clientname' -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs' echo " " done fi done echo " " echo "# ######################################################### " echo " " echo " " else echo "Warning Volume $source7Mvolume is deep qtree. Rejecting!" echo " " echo "# ######################################################### " echo " " echo " " fi done |
Run it, and this is what it dumps out.
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 |
jk-47:script_exports jkulm$ ./mig7mode2cDotexport.sh Enter vserver name : TestVserver Enter exports filename: exports03.txt #### Source 7-mode Volume='/vol/XYZcuat_app01' Destination Clustered Mode Volume='/XYZcuat_app01' create -vserver TestVserver -policyname XYZcuat_app01_exp_pol volume modify -vserver TestVserver -policy XYZcuat_app01_exp_pol -volume XYZcuat_app01 export-policy rule create -vserver TestVserver -policyname XYZcuat_app01_exp_pol export-policy rule create -vserver TestVserver -policyname XYZcuat_app01_exp_pol -clientmatch any -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs # ######################################################### #### Source 7-mode Volume='/vol/XYZcuat_dat01' Destination Clustered Mode Volume='/XYZcuat_dat01' create -vserver TestVserver -policyname XYZcuat_dat01_exp_pol volume modify -vserver TestVserver -policy XYZcuat_dat01_exp_pol -volume XYZcuat_dat01 export-policy rule create -vserver TestVserver -policyname XYZcuat_dat01_exp_pol export-policy rule create -vserver TestVserver -policyname XYZcuat_dat01_exp_pol -clientmatch any -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs # ######################################################### #### Source 7-mode Volume='/vol/XYZsuat_app01' Destination Clustered Mode Volume='/XYZsuat_app01' create -vserver TestVserver -policyname XYZsuat_app01_exp_pol volume modify -vserver TestVserver -policy XYZsuat_app01_exp_pol -volume XYZsuat_app01 export-policy rule create -vserver TestVserver -policyname XYZsuat_app01_exp_pol export-policy rule create -vserver TestVserver -policyname XYZsuat_app01_exp_pol -clientmatch mt-116.us.example.com -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs export-policy rule create -vserver TestVserver -policyname XYZsuat_app01_exp_pol -clientmatch mt-116-nas.us.example.com -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs # ######################################################### #### Source 7-mode Volume='/vol/XYZsuat_dat01' Destination Clustered Mode Volume='/XYZsuat_dat01' create -vserver TestVserver -policyname XYZsuat_dat01_exp_pol volume modify -vserver TestVserver -policy XYZsuat_dat01_exp_pol -volume XYZsuat_dat01 export-policy rule create -vserver TestVserver -policyname XYZsuat_dat01_exp_pol export-policy rule create -vserver TestVserver -policyname XYZsuat_dat01_exp_pol -clientmatch mt-116.us.example.com -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs export-policy rule create -vserver TestVserver -policyname XYZsuat_dat01_exp_pol -clientmatch mt-116-nas.us.example.com -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs # ######################################################### #### Source 7-mode Volume='/vol/XYZcuat_linux_fc_3270_rr_01' Destination Clustered Mode Volume='/XYZcuat_linux_fc_3270_rr_01' create -vserver TestVserver -policyname XYZcuat_linux_fc_3270_rr_01_exp_pol volume modify -vserver TestVserver -policy XYZcuat_linux_fc_3270_rr_01_exp_pol -volume XYZcuat_linux_fc_3270_rr_01 export-policy rule create -vserver TestVserver -policyname XYZcuat_linux_fc_3270_rr_01_exp_pol export-policy rule create -vserver TestVserver -policyname XYZcuat_linux_fc_3270_rr_01_exp_pol -clientmatch na-ux00-nas.us.example.com -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs export-policy rule create -vserver TestVserver -policyname XYZcuat_linux_fc_3270_rr_01_exp_pol -clientmatch mt64-019-file.us.example.com -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs export-policy rule create -vserver TestVserver -policyname XYZcuat_linux_fc_3270_rr_01_exp_pol -clientmatch na-ux00.us.example.com -rorule any -rwrule any -allow-suid true -allow-dev true -superuser any -protocol nfs |
Ta Da!!! There you have it. Copy and paste it into the cli. Next up will be some tweaks, and updating it to powershell.