So, this isn’t “new”, I wrote it a few weeks back, but, well, meh, figured I’d share. First “useful” ruby-instead-of-bash script for a little automation/keeping things consistent.
@ work we have the need to move a whole mess of storage (just under 100TB) from one thing to another, and to preserve quotas as we do so. Most of the quotas are simple 1TB tree/project quotas. Some are bigger, but by default we want to start @ 1TB and then we can bump the ones needed. Anyways, I need to do this for about 8 groups of 5-20 “projects/trees”, so by hand isn’t really an option. Hence the script:
#Usage: mkscartch <project/group name> #Makes the needed project/projid entires turns on the project quota, and sets a 1TB default hard/soft limit. ifARGV.length!=2puts"usage: mkscartch <project/group name> <full path to directory>"puts"This script takes a lab/group name, and a path as arguments"puts"It will make a directory for the lab/group at the path, and turn it into a default 1TB project quota"exitendnew_scratch=ARGV[0];new_path=ARGV[1];project_nums=Array.new#first, we need to figure out what project ID to start withFile.open("/etc/projects").reverse_each{|projects|project_nums.push(projects.split(':')[0])}last_project=project_nums[0].to_i;new_project=last_project+1project_line="#{new_project}:#{new_path}"projid_line="#{new_scratch}:#{new_project}"mkdir_cmd="mkdir #{new_path}"quota_set="xfs_quota -x -c 'project -s #{new_scratch}'"quota_limit="xfs_quota -x -c 'limit -p bhard=1024g bsoft=1024g #{new_scratch}'"sleep(1)puts"Adding #{project_line} to /etc/projects..."File.open("/etc/projects","a")do|f|f.puts(project_line)endsleep(1)puts"Adding #{projid_line} to /etc/projid..."File.open("/etc/projid","a")do|f2|f2.puts(projid_line)endsleep(1)puts"Making #{new_path} with #{mkdir_cmd}"Dir::mkdir(new_path)sleep(1)puts"Setting quota with #{quota_set}"system"#{quota_set}"sleep(1)puts"Setting quota limits @ 1TB with #{quota_limit}"system"#{quota_limit}"
So, I can, from the place I want to sync from, do something like:
1
$ for i in *; do /usr/bin/mkscratch.rb $i /new/location/$i; done
And be done with it. Really basic, I know. But, first thing I would have normally shell scripted done in ruby instead. And you know what? I liked it, Its nice. So there.