"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/geo-rep/slave-upgrade.sh" (16 Sep 2020, 2452 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: slave-upgrade.sh <volfile-server:volname> <gfid-file>
    3 #                        <path-to-gsync-sync-gfid>
    4 #<slave-volfile-server>: a machine on which gluster cli can fetch slave volume info.
    5 #                        slave-volfile-server defaults to localhost.
    6 #
    7 #<gfid-file>: a file containing paths and their associated gfids
    8 #            on master. The paths are relative to master mount point
    9 #            (not absolute). An example extract of <gfid-file> can be,
   10 #
   11 #            <extract>
   12 #            22114455-57c5-46e9-a783-c40f83a72b09 /dir
   13 #            25772386-3eb8-4550-a802-c3fdc938ca80 /dir/file
   14 #            </extract>
   15 
   16 function get_bricks()
   17 {
   18     gluster volume info $1 | grep -E 'Brick[0-9]+' | sed -e 's/[^:]*:\(.*\)/\1/g'
   19 }
   20 
   21 function cleanup_brick()
   22 {
   23     HOST=$1
   24     BRICK=$2
   25 
   26     # TODO: write a C program to receive a list of files and does cleanup on
   27     # them instead of spawning a new setfattr process for each file if
   28     # performance is bad.
   29     ssh $HOST "rm -rf $BRICK/.glusterfs/* && find $BRICK -exec setfattr -x trusted.gfid {} \; 2>/dev/null"
   30 }
   31 
   32 function cleanup_slave()
   33 {
   34     VOLUME_NAME=`echo $1 | sed -e 's/.*:\(.*\)/\1/'`
   35 
   36     BRICKS=`get_bricks $VOLUME_NAME`
   37 
   38     for i in $BRICKS; do
   39     HOST=`echo $i | sed -e 's/\(.*\):.*/\1/'`
   40     BRICK=`echo $i | sed -e 's/.*:\(.*\)/\1/'`
   41     cleanup_brick $HOST $BRICK
   42     done
   43 
   44     # Now restart the volume
   45     gluster --mode=script volume stop $VOLUME_NAME;
   46     gluster volume start $VOLUME_NAME;
   47 }
   48 
   49 function mount_client()
   50 {
   51     local T; # temporary mount
   52     local i; # inode number
   53 
   54     VOLUME_NAME=$2;
   55     GFID_FILE=$3
   56     SYNC_CMD=$4
   57 
   58     T=$(mktemp -d -t ${0##*/}.XXXXXX);
   59 
   60     glusterfs --aux-gfid-mount -s $1 --volfile-id $VOLUME_NAME $T;
   61 
   62     i=$(stat -c '%i' $T);
   63 
   64     cd $T;
   65 
   66     $SYNC_CMD $GFID_FILE
   67 
   68     cd -;
   69 
   70     umount $T || fatal "could not umount $MASTER from $T";
   71 
   72     rmdir $T || warn "rmdir of $T failed";
   73 }
   74 
   75 function sync_gfids()
   76 {
   77     SLAVE=$1
   78     GFID_FILE=$2
   79     SYNC_CMD=$3
   80 
   81     SLAVE_VOLFILE_SERVER=`echo $SLAVE | sed -e 's/\(.*\):.*/\1/'`
   82     SLAVE_VOLUME_NAME=`echo $SLAVE | sed -e 's/.*:\(.*\)/\1/'`
   83 
   84     if [ "x$SLAVE_VOLFILE_SERVER" = "x" ]; then
   85         SLAVE_VOLFILE_SERVER="localhost"
   86     fi
   87 
   88     mount_client $SLAVE_VOLFILE_SERVER $SLAVE_VOLUME_NAME $GFID_FILE $SYNC_CMD
   89 }
   90 
   91 function upgrade()
   92 {
   93     SLAVE=$1
   94     GFID_FILE=$2
   95     SYNC_CMD=$3
   96 
   97     cleanup_slave $SLAVE
   98 
   99     sync_gfids $SLAVE $GFID_FILE $SYNC_CMD
  100 }
  101 
  102 upgrade "$@"