"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/geo-rep/generate-gfid-file.sh" (16 Sep 2020, 1373 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/bash
    2 #Usage: generate-gfid-file.sh <master-volfile-server:master-volume> <path-to-get-gfid.sh> <output-file> [dirs-list-file]
    3 
    4 function get_gfids()
    5 {
    6     GET_GFID_CMD=$1
    7     OUTPUT_FILE=$2
    8     DIR_PATH=$3
    9     find "$DIR_PATH" -exec $GET_GFID_CMD {} \; >> $OUTPUT_FILE
   10 }
   11 
   12 function mount_client()
   13 {
   14     local T; # temporary mount
   15     local i; # inode number
   16 
   17     VOLFILE_SERVER=$1;
   18     VOLUME=$2;
   19     GFID_CMD=$3;
   20     OUTPUT=$4;
   21 
   22     T=$(mktemp -d -t ${0##*/}.XXXXXX);
   23 
   24     glusterfs -s $VOLFILE_SERVER --volfile-id $VOLUME $T;
   25 
   26     i=$(stat -c '%i' $T);
   27 
   28     [ "x$i" = "x1" ] || fatal "could not mount volume $MASTER on $T";
   29 
   30     cd $T;
   31     rm -f $OUTPUT;
   32     touch $OUTPUT;
   33 
   34     if [ "$DIRS_FILE" = "." ]
   35     then
   36         get_gfids $GFID_CMD $OUTPUT "."
   37     else
   38         while read line
   39         do
   40             get_gfids $GFID_CMD $OUTPUT "$line"
   41         done < $DIRS_FILE
   42     fi;
   43 
   44     cd -;
   45 
   46     umount $T || fatal "could not umount $MASTER from $T";
   47 
   48     rmdir $T || warn "rmdir of $T failed";
   49 }
   50 
   51 
   52 function main()
   53 {
   54     SLAVE=$1
   55     GET_GFID_CMD=$2
   56     OUTPUT=$3
   57 
   58     VOLFILE_SERVER=`echo $SLAVE | sed -e 's/\(.*\):.*/\1/'`
   59     VOLUME_NAME=`echo $SLAVE | sed -e 's/.*:\(.*\)/\1/'`
   60 
   61     if [ "$#" -lt 4 ]
   62     then
   63         DIRS_FILE="."
   64     else
   65         DIRS_FILE=$4
   66     fi
   67     mount_client $VOLFILE_SERVER $VOLUME_NAME $GET_GFID_CMD $OUTPUT $DIRS_FILE
   68 }
   69 
   70 main "$@";