Whilst working on an Exalogic Upgrade I was working with the ZFS
storage and having executed the same commands a number of times I
decided to script them. This short blog entry, although it will
grow over time, contains the scripts I find useful. For each of
the scripts I will simply provide a brief description and the
source of the script and occasionally add the output assuming it
is not too long. Where I need to pass the Hostname / IP Address of
the storage heads the scripts will use the flags:
To run the script you will need to execute the following:
To run the script you will need to execute the following:
To run the script you will need to execute the following:
To run the script you will need to execute the following:
- -p <Primary - first storage head>
- -s <Secondary - Second storage head>
Show Config
Executing this script against one of the storage heads will read and show all the properties that are current set on the specified storage head. Simply redirecting the output to a file provides me with a backup before I execute any modifications.To run the script you will need to execute the following:
ssh root@<Storage IP> < showConfig.aksh > storageConfig.log
showConfig.aksh
script function processNode(node) { run('cd /'); run(node); printf("*****************************************************\n"); printf("%s\n", node); printf("*****************************************************\n\n"); printf("%s", run('list')); printf("\n\n*****************************************************\n\n"); var nodeChildren = children(); for (var i = 0; i < nodeChildren.length; i++) { processNode(node + " " + nodeChildren[i]); run('cd ..'); } } processNode('');
Show Shares
This script, modified from the ZFS Admin Guide, will display a list of all Projects/Shares on the storage along with the amount of spece used and available.To run the script you will need to execute the following:
ssh root@<Storage IP> < showShares.aksh
showShares.aksh
script run('shares'); projects = list(); printf("%-50s %-10s %-10s\n", "Project/Share", "Used", "Available"); printf("%-50s %-10s %-10s\n", "=============", "====", "========="); for (i = 0; i < projects.length; i++) { run('select ' + projects[i]); shares = list(); for (j = 0; j < shares.length; j++) { run('select ' + shares[j]); share = projects[i] + '/' + shares[j]; used = run('get space_data').split(/\s+/)[3]; available = run('get space_available').split(/\s+/)[3]; printf("%-50s %-10s %-10s\n", share, used, available); run('cd ..'); } run('cd ..'); }
showShares.aksh
[root@slce50cn01 ~]# ssh root@slce50sn01 < showShares.aksh Pseudo-terminal will not be allocated because stdin is not a terminal. Project/Share Used Available ============= ==== ========= ExalogicControl/ExalogicControl 312G 21.9T ExalogicControl/ExalogicPool1 1.28G 21.9T ExalogicControl/ExalogicPool2 31.5K 21.9T ExalogicControl/ExalogicPool3 31.5K 21.9T ExalogicControl/ExalogicPool4 31.5K 21.9T ExalogicControl/ExalogicRepo 1.01T 21.9T ExalogicControl/Exalogic_EnterpriseController 37.5K 21.9T ExalogicControl/Exalogic_OVAB 31.5K 21.9T ExalogicControl/Exalogic_ProxyController 31.5K 21.9T ExalogicControl/Exalogic_RDBMS 31.5K 21.9T
Set NFSv4 Delegation
The following script will set the NFSv4 Delegation flag to false (recommended) and also the appropriate IPMP values. If you know the location of the value to set then the following should be easy to modify.To run the script you will need to execute the following:
./setIPMPAndNFSV4Delegation.sh [-s <Secondary Storage Node hostname/IP>] [-p <Primary Storage Node hostname/IP>]
setIPMPAndNFSV4Delegation.sh
#!/bin/bash PRIMARY= SECONDARY= while [ $# -gt 0 ] do case "$1" in -p) PRIMARY="$2"; shift;; -s) SECONDARY="$2"; shift;; *) echo ""; echo >&2 \ "usage: $0 [-s <Secondary Storage Node hostname/IP>] [-p <Primary Storage Node hostname/IP>] " echo""; exit 1;; *) break;; esac shift done function updateStorage { ssh root@$1 << EOF cd / configuration services ipmp show set interval=5000 set failback=false commit cd / configuration services nfs show set enable_delegation=false commit quit EOF } if [ "$PRIMARY" != "" ] then updateStorage $PRIMARY fi if [ "$SECONDARY" != "" ] then updateStorage $SECONDARY fi
Snapshot ZFS Project or Share
This script will allow you to create a snapshot of a ZFS Project or Share on the internal storage. You have the option of specifying the Snapshot name but if this is not supplied it will default to a date stamped name.To run the script you will need to execute the following:
snapshotZFS.sh -ip <Storage Node hostname/IP> -p <Project Name> [-s <Share Name>] [-n <Snapshot Name>]
snapshotZFS.sh
#!/bin/bash BAK_EXT=`date +"%Y%m%d-%H%M%S"` PROJECT="" SHARE="" IPADDRESS="" SNAPSHOTNAME="SnapShot-$BAK_EXT" while [ $# -gt 0 ] do case "$1" in -ip) IPADDRESS="$2"; shift;; -p) PROJECT="$2"; shift;; -s) SHARE="$2"; shift;; -n) SNAPSHOTNAME="$2"; shift;; *) echo ""; echo >&2 \ "usage: $0 -ip <Storage Node hostname/IP> -p <Project Name> [-s <Share Name>] [-n <Snapshot Name>] " echo""; exit 1;; *) break;; esac shift done if [ "$IPADDRESS" == "" ] then echo "IP Address or Hostname of the Storage must be provided" exit 1 fi if [ "$PROJECT" == "" ] then echo "Project name must be provided" exit 1 fi echo $SNAPSHOTNAME ssh root@$IPADDRESS <<EOF script try { run('cd /'); run('shares'); run('select $PROJECT'); printf('%s\n', run('list')); try { run('select $SHARE'); } catch (e) { } run('snapshots'); run('snapshot $SNAPSHOTNAME'); } catch (err) { if (err.code == EAKSH_ENTITY_BADSELECT) { printf('ERROR: "$SHARE" is not a share in the "$PROJECT" project\n'); } else { printf('ERROR: (%s)\n', err.message); } } EOF
Hi,
ReplyDeletescript for SNAPSHOT ZFS PROJECT OR SHARE is very good, it will be very helpfull.
Do you have script to take snapshots for multiple shares at a time.
can you please provide script if you have.
Thanks.
if we have 10 shares which need to take snapshot using script,
ReplyDeleteCan you please share me the script to take snapshots for 10 shares using single script.