> I think based on this, there really isn't a good way to know 
> how much space is being consumed by snapshots? 
This perl script hacked together by a colleague, given a zfs filesystem,
will tell you how much space is used by the files, and how much by the
snapshots. This has proven helpful in tracking down some hogs.

It's still not useful for my core issue: How do I tell how much disk
space would be freed if I nuke a snapshot?

But I thought I'd post it in case others find it useful.

Example outputs:

titan[root]:/> snapsize vol0

Space utilization for volume vol0

   4421278 MB Total Used
   2119551 MB Used by Files
   2301727 MB Used by Snapshots



titan[root]:/> snapsize vol0/groups

Space utilization for volume vol0/groups

   2127068 MB Total Used
    623498 MB Used by Files
   1503570 MB Used by Snapshots

johnS



#!/bin/perl
########################################################################
#############################
# snapsize
#
# This script compares the disk space used by files & overhead and the
total space used
# to calculate the space used by snapshots for a given volume.
#
# usage: snapsize <volname>
#
# History
#
------------------------------------------------------------------------
--------------------------
# 06-Nov-2008 Adam Bodette - Initial creation
# 06-Nov-2008 John Stewart - Change output to megabytes
# 06-Nov-2008 Adam Bodette - Changed to accept volume name from input
and removed hardcodes
# 06-Nov-2008 Adam Bodette - Cleaned up output and finished commenting
code
#
########################################################################
#############################

###################################
# read in the volume to report on #
###################################

$vol = $ARGV[0];

#############################
# verify a volume was given #
#############################

if ("$ARGV[0]" eq "") {
  die "\nusage: snapsize <volume>\n\n";
}

#######################################
# grab total space used by the volume #
#######################################

$total = int(`zfs get -Hp -o value used $vol` / 1024) or die "\n$vol is
not a valid zfs volume\n\n";

#####################################################################
# grab the total space used by files and overhead as reported by df #
#####################################################################

$fs = `df -k \| grep $vol \| awk \'\{s \+\=\$3\} END \{print s\}\'`;

##############################
# Convert sizes to Megabytes #
##############################

$total = int($total / 1024);
$fs = int($fs / 1024);

########################################################################
##########
# subtract space used by files from total space used to calculate
snapshot space #
########################################################################
##########

$snap = $total - $fs;

#################################
# print out the storage results #
#################################

print "\nSpace utilization for volume $vol\n\n";
printf('%10s',$total);
print " MB Total Used\n";
printf('%10s',$fs);
print " MB Used by Files\n";
printf('%10s',$snap);
print " MB Used by Snapshots\n\n";

################
# exit happily #
################

exit;
_______________________________________________
zfs-discuss mailing list
zfs-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/zfs-discuss

Reply via email to