#!/bin/sh # # Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved. # # Dump to a file the following bits of information: # # * version# of the output # * mkfs info # * statfs info # * mount info # * quotas - user/group/project info # in tar format. # # Exit status: # 0 success # 1 error # 2 mount-path is not the path for a mounted file system # # There will be no output to stdout # On error, print an error msg to stderr # tmp=/tmp/$$ tmpdir=$tmp.xfsinfo status=1 # by default an error status of 1 trap "rm -rf $tmp.*; exit \$status" 0 1 2 3 15 here=`pwd` prog=`basename $0` # Various volume info data file names to tar version_file=version1.0 mnt_options_file=mnt_options mkfs_options_file=mkfs_options user_quotas_file=quotas_user group_quotas_file=quotas_group project_quotas_file=quotas_proj statfs_output_file=statfs_output _usage() { echo "Usage: $prog mount-path output-file" >&2 } # # Look thru the mounted filesystems for $mntpt # and if it exists there, then return the mount options, # if it doesn't exist then return an error status # This kills 2 birds: existence and options # _process_mount() { # Expect mount output of form: # # device on path type fs (options) # /dev/root on / type xfs (rw,raw=/dev/rroot) # mntpt=$1 mount |\ while read device on mnt type fstype opts do if [ $on != "on" -o -z "$mnt" ] then # some basic sanity checking echo "error reading mount output" >$tmp.err return fi if [ $mntpt = $mnt ] then if [ $fstype != xfs ] then echo "$mnt is not an XFS file system" >$tmp.err return fi echo $opts >$tmp.out fi done if [ -s $tmp.err ] then cat $tmp.err return 1 elif [ -s $tmp.out ] then cat $tmp.out return 0 else # Didn't find it: # we signify it isn't a mount point but # don't consider this as an error return 2 fi } # # Check that all programs we need are accessible # Go thru each 1 even on failure so we see all that # are missing. # _check_progs() { if ! which xfs_info >/dev/null 2>&1 then echo "xfs_info not found" >$tmp.err fi if ! which xfs_io >/dev/null 2>&1 then echo "xfs_io not found" >>$tmp.err fi if ! which xfs_quota >/dev/null 2>&1 then echo "xfs_quota not found" >>$tmp.err fi if [ -s $tmp.err ] then cat $tmp.err >&2 exit fi } if [ $# -ne 2 ] then _usage exit fi _check_progs mntpt=$1 outfile=$2 mnt_options=`_process_mount $mntpt` sts=$? if [ $sts -ne 0 ] then # output error msg [ $sts -eq 1 ] && echo $mnt_options >&2 status=$sts exit fi # create the results of each command in the tmpdir mkdir $tmpdir cd $tmpdir touch $version_file echo $mnt_options >$mnt_options_file xfs_info $mntpt >$mkfs_options_file || exit xfs_io -c statfs $mntpt >$statfs_output_file || exit xfs_quota -x -c "dump -uf $user_quotas_file " $mntpt || exit xfs_quota -x -c "dump -gf $group_quotas_file" $mntpt || exit xfs_quota -x -c "dump -pf $project_quotas_file" $mntpt || exit cd $here tar cf $outfile -C $tmpdir \ $version_file \ $mnt_options_file $mkfs_options_file $statfs_output_file \ $user_quotas_file $group_quotas_file $project_quotas_file || exit status=0