"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/disk_usage_sync.sh" (16 Sep 2020, 2340 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 # This script can be used to sync disk usage before activating quotas on GlusterFS.
    4 # There are two scenarios where quotas are used and this script has to be used accordingly - 
    5 #
    6 # 1. Server side
    7 # The script needs to be run with backend export directory as the argument.  This script updates
    8 # the current disk usage of the backend directory in a way that is intelligible to the GlusterFS quota 
    9 # translator. Make sure you run this script before starting glusterfsd (GlusterFS server process):
   10 #   * for the first time
   11 #   * after any server outage (reboot, etc.)
   12 
   13 # 2. Client side
   14 # The script needs to be run with the client mount point as the argument. It updates the current disk
   15 # of the GlusterFS volume is a way that is intelligible to the GlusterFS quota translator. Make sure
   16 # you run this script after a fresh mount of the GlusterFS volume on the client:
   17 #   * For the first time
   18 #   * After any client outage (reboot, remount, etc.)
   19 
   20 # Please note that this script is dependent on the 'attr' package, more specifically 'setfattr' to set 
   21 # extended attributes of files.
   22 # GlusterFS
   23 # 
   24 # (c) 2010 Gluster Inc <http://www.gluster.com/> 
   25 
   26 PROGRAM_NAME="disk_usage_sync.sh"
   27 
   28 #check if setfattr is available
   29 check_for_attr ()
   30 {
   31     `command -v setfattr >/dev/null`
   32     if [ "${?}" -gt 0 ]; then
   33     echo >&2 "This script requires the 'attr' package to run. Either it has not been installed or is not present currently in the system path."
   34     exit 1
   35     fi
   36 
   37 }
   38 
   39 usage () {
   40     echo >&2 "$PROGRAM_NAME - Command used to sync disk usage information before activating quotas on GlusterFS.
   41 
   42 usage: $PROGRAM_NAME <target-directory>"
   43 
   44 exit 1
   45 }
   46 
   47 TARGET_DIR=$1
   48 EXT_ATTR_NAME="trusted.glusterfs-quota-du"
   49 
   50 #output of du in number of bytes
   51 get_disk_usage ()
   52 {
   53     if [ ! -d $TARGET_DIR ]; then
   54     echo >&2 "Error: $TARGET_DIR does not exist."
   55     exit 1
   56     fi
   57 
   58     DISK_USAGE=`du -bc $TARGET_DIR | grep 'total' | cut -f1`
   59     if [ "${?}" -gt 0 ]; then
   60     exit 1
   61     fi
   62 
   63 }
   64 
   65 #set the extended attribute of the root directory with du size in bytes
   66 set_disk_usage ()
   67 {
   68    ` setfattr -n $EXT_ATTR_NAME -v $DISK_USAGE $TARGET_DIR`
   69     if [ "${?}" -gt 0 ]; then
   70     exit 1
   71     fi
   72 }
   73 
   74 main ()
   75 {
   76     [ $# -lt 1 ] && usage
   77 
   78     check_for_attr
   79 
   80     get_disk_usage
   81     set_disk_usage
   82 
   83     printf "Disk Usage information has been sync'd successfully.\n"
   84 }
   85 
   86 main "$@"