{"id":783,"date":"2014-12-20T07:05:40","date_gmt":"2014-12-20T15:05:40","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=783"},"modified":"2014-12-20T07:05:40","modified_gmt":"2014-12-20T15:05:40","slug":"zfssa-list-snapshots-script","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/zfssa-list-snapshots-script\/","title":{"rendered":"ZFSSA List Snapshots Script"},"content":{"rendered":"
Quick script to illustrate interacting with the ZFS Storage Appliance. In this example I am listing ZFSSA snapshots containing a search string.\u00a0 Note I edited this for the article without re-testing it still works.<\/p>\n
\r\n#!\/bin\/sh\r\n\r\nUsage() {\r\n echo "$1 -u <Appliance user> -h <appliance> -j <project> -p <pool> -s <containsString>"\r\n exit 1\r\n}\r\n\r\nPROG=$0\r\nwhile getopts u:h:s:j:p flag\r\ndo\r\n case "$flag" in\r\n p) pool="$OPTARG";;\r\n j) project="$OPTARG";;\r\n s) string="$OPTARG";;\r\n u) user="$OPTARG";;\r\n h) appliance="$OPTARG";;\r\n \\?) Usage $PROG ;;\r\n esac\r\ndone\r\n\r\n[ -z "$pool" -o -z "$project" -o -z "$appliance" -o -z "$user" ] && Usage $PROG\r\n\r\nssh -T $user@$appliance << EOF\r\nscript\r\nvar MyArguments = {\r\n pool: '$pool',\r\n project: '$project',\r\n string: '$string'\r\n}\r\n\r\nfunction ListSnapshotsbyS (Arg) {\r\n run('cd \/'); \/\/ Make sure we are at root child context level\r\n run('shares');\r\n try {\r\n run('set pool=' + Arg.pool);\r\n } catch (err) {\r\n printf ('ERROR: %s\\n',err);\r\n return (err);\r\n }\r\n\r\n var allSnaps=[];\r\n try {\r\n run('select ' + Arg.project + ' snapshots');\r\n snapshots=list();\r\n for(i=0; i < snapshots.length; i++) {\r\n allSnaps.push(snapshots[i]);\r\n }\r\n run('done');\r\n } catch (err) {\r\n printf ('ERROR: %s\\n',err);\r\n return(err);\r\n }\r\n\r\n for(i=0; i < allSnaps.length; i++) {\r\n if (Arg.string !="") {\r\n var idx=allSnaps[i].indexOf(Arg.string);\r\n if (idx>0) {\r\n printf('#%i: %s contained search string %s \\n',i,allSnaps[i], Arg.string);\r\n }\r\n } else {\r\n printf('#%i: %s \\n',i,allSnaps[i]);\r\n }\r\n }\r\n return(0);\r\n}\r\nListSnapshotsbyS(MyArguments);\r\n.\r\nEOF\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"Quick script to illustrate interacting with the ZFS Storage Appliance. In this example I am listing ZFSSA snapshots containing a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,30],"tags":[],"class_list":["post-783","post","type-post","status-publish","format-standard","hentry","category-bash","category-zfs"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=783"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/783\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}