Coda File System

createvol_rep patch

From: root <contract_work_at_voidembraced.net>
Date: Fri, 12 Feb 2010 19:48:04 -0500
>> I will patch in support for a backup cli option and provide the patch.  I 
>> should have something along shortly for your review. 
> 
> I guess I will not have time for some time so do not hold your breath.

Whoever wants it, is welcome to it. 


> I would also suggest learning more about the internals before spending
> your (and the reviewer's) time on modifications. Otherwise you may try
> to fix a wrong thing at a wrong place.

Don't know what is meant by this.  Again, anyone who finds it useful is 
welcome to it.  Let me know if I can be of further assistance to anyone 
wanting to apply the patch. 


Script hack details:
*) Checks for volname length and errors if it exceeds 30 bytes
*) Coded in support for limiting to 23 bytes, but I don't know the 
conditions that result in a .backup being appended (or if we can make that a 
'.b' instead)
*) Coded in an optional parameter '--backup=':
* ) it should be able to be anywhere on the command line except 1st (as 
always reserved for volname)
* ) options match options allowed for interactive: partial or full day names 
permitted with case-insensitivity
* ) to disable interactive with no backups = "--backup=n"
* ) to disable interactive with backup default = "--backup=y" (as always, 
set for Monday)
* ) interactive invalid backup day selection results in loop w/re-query
* ) non-interactive invalid backup day selection results in immediate exit 1 

NOTE 1:  There was a special function called "echon" that uses printf for 
echoing to the terminal.  It is used sporadically in the script in lieu of 
echo -- since both were used, I simply used echo. 

NOTE 2:  I use wc, awk & sed which I noted are used elsewhere in the script. 

NOTE 3:  I use echo -n for a non carriage-return echo, which is NOT used 
elsewhere in the script, and as such, I do not know whether it's 
functionality is guaranteed. 


I have done reasonable testing: 

# /vice/bin/createvol_rep
Usage:  /vice/software/ibin/createvol_rep <volname> <server>[/<partition>] 
[<server>[/<partition>]]* [groupid] [--backup=<N|Y|Tue|Wed|...>] 

# /vice/bin/createvol_rep foo `hostname -f`
[typical interactive backup selection behavior] 

# /vice/bin/createvol_rep foo `hostname -f` --backup=N
[non-interactive, with no backups] 

# /vice/bin/createvol_rep foo `hostname -f` --backup=Y
[non-interactive, with defaulted backup day -- currently Monday] 

# /vice/bin/createvol_rep foo `hostname -f` --backup=Tue
[non-interactive, with explicit Tuesday backup day] 


NOTE:  Could see adding a feature to permit the use of 0-7 day selection 
syntax, as well as the raw "cycle" form of IFIIIII and such.  If folks 
thought such a feature might be useful, it would be trivial to add in. 


Patch follows: 

[------------BEGIN_PATCH-------------]
 --- /vice/software/ibin/createvol_rep   2009-03-11 02:10:29.000000000 -0500
+++ /vice/software/ibin/createvol_rep.new       2010-02-12 
10:51:50.373334673 -0500
@@ -22,6 +22,21 @@
  printf "%s" "$*"
} 

+fUsage () {
+  echo "Usage:  $0 <volname> <server>[/<partition>] 
[<server>[/<partition>]]* [groupid] [--backup=<N|Y|Tue|Wed|...>]"
+  exit 1
+}
+
+case "x$1" in
+       x--[Hh]elp)
+               fUsage
+       ;;
+esac
+
+if [ $# -lt 2 ]; then
+  fUsage
+fi
+
# just in case we have an empty server.conf?
vicedir="/vice" 

@@ -44,10 +59,6 @@
fi 

# Parse arguments
 -if [ $# -lt 2 ]; then
 -  echo "bad args:  createvol_rep <volname> <server>[/<partition>] 
[<server>[/<partition>]]* [groupid]"
 -  exit
 -fi 

# Initialize local variables
SERVERS=
@@ -55,6 +66,35 @@
NSERVERS=0
MAXSERVERS=8 

+chkDay () {
+  [ -z "$day" ] && day='Y'
+
+  # NOTE: if set to [Yy] or any case of Yes, cycle is set for Monday
+  case "$day" in
+  [Yy]|[Yy][Ee][Ss])
+    _cycle_="IFIIIII" ;;
+  [Ss][Uu][Nn]*)
+    _cycle_="FIIIIII" ;;
+  [Mm][Oo][Nn]*|[Yy]|[Yy][Ee][Ss])
+    _cycle_="IFIIIII" ;;
+  [Tt][Uu][Ee]*)
+    _cycle_="IIFIIII" ;;
+  [Ww][Ee][Dd]*)
+    _cycle_="IIIFIII" ;;
+  [Tt][Hh][Uu]*)
+    _cycle_="IIIIFII" ;;
+  [Ff][Rr][Ii]*)
+    _cycle_="IIIIIFI" ;;
+  [Ss][Aa][Tt]*)
+    _cycle_="IIIIIIF" ;;
+  *)
+    echo "invalid selection:  $day"
+    return 1
+    ;;
+  esac
+  return 0
+}
+
# deal with Parameters
VOLNAME="$1" 

@@ -83,6 +123,9 @@ 

while [ $# -gt 1 ]; do
  shift
+
+  echo "$1"|grep '^--backup=' >/dev/null && VOLBAK=`echo "$1"|sed 
's/^--backup=//'` && break
+
  PRE=`echo "$1" | sed 's/\(..\).*/\1/'`
  if [ "$PRE" = "7f" -o "$PRE" = "7F" ] ; then
    GROUPID="$1"
@@ -150,6 +193,24 @@
  exit 1
fi 

+case "x$VOLBAK" in
+       x[Nn]|x[Nn][Oo])
+               VOLBAK='N'
+       ;;
+esac
+
+if [ -z "$VOLBAK" -o "$VOLBAK" = 'N' ]; then
+       VOLLENLIM=30
+else
+       day="$VOLBAK"
+       chkDay
+       [ "$?" -ne 0 ] && echo "aborting!" && exit 1
+
+       VOLLENLIM=30  # thought this would be 23, but 30 seems reasonable
+fi
+VOLLEN=`echo -n "$VOLNAME"|wc -c|awk '{print $1}'`
+[ "$VOLLEN" -gt "$VOLLENLIM" ] && echo "Volume name $VOLNAME ($VOLLEN) 
exceeds $VOLLENLIM character limit" && exit 1
+
# Allocate a new groupid if necessary
if [ -z "$GROUPID" ]; then
  if  [ -f "$vicedir"/db/maxgroupid ]; then
@@ -224,40 +285,27 @@
mv "$vicedir"/db/VRList "$vicedir"/db/VRList.old
mv "$vicedir"/db/VRList.new "$vicedir"/db/VRList 

 -echon "Do you wish this volume to be Backed Up (y/n)? [n] "
 -
 -read _ans_
 -
 -if [ "$_ans_" = y -o "$_ans_" = yes ]; then
 -  echon "Day to take full dumps: [Mon] "
 -
 -  read day
 -
 -  if [ "$day" = "" ]; then
 -    day="Mon"
 -  fi
 -
 -  case "$day" in
 -  [Ss][Uu][Nn]*)
 -    _cycle_="FIIIIII" ;;
 -  [Mm][Oo][Nn]*)
 -    _cycle_="IFIIIII" ;;
 -  [Tt][Uu][Ee]*)
 -    _cycle_="IIFIIII" ;;
 -  [Ww][Ee][Dd]*)
 -    _cycle_="IIIFIII" ;;
 -  [Tt][Hh][Uu]*)
 -    _cycle_="IIIIFII" ;;
 -  [Ff][Rr][Ii]*)
 -    _cycle_="IIIIIFI" ;;
 -  [Ss][Aa][Tt]*)
 -    _cycle_="IIIIIIF" ;;
 -  *)
 -    echo "$day" is not a valid day, not adding "$VOLNAME" to backup list.
 -    exit
 -    ;;
 -  esac
+if [ -z "$VOLBAK" ]; then
+       echon "Do you wish this volume to be Backed Up (y/n)? [n] "
+       read _ans_
+       case "x$_ans_" in
+               x[Yy]|x[Yy][Ee][Ss])
+                       _ans_='Y'
+               ;;
+       esac
+
+       if [ "$_ans_" = 'Y' ]; then
+               unset day
+               while [ -z "$day" ]; do
+                       echon "Day to take full dumps (or ctrl+c to cancel): 
[Mon] "
+                       read day
+                       chkDay
+                       [ "$?" -ne 0 ] && unset day
+               done
+       fi
+fi 

+if [ -n "$_cycle_" ]; then
  echo "echoing $HEXGROUPID        $_cycle_        $VOLNAME 
>>${vicedir}/db/dumplist"
  echo "$HEXGROUPID        $_cycle_         $VOLNAME" 
>>"$vicedir"/db/dumplist 

[------------END_PATCH-------------] 


I use tabs, which I know annoys some developers.  If a patch using the 
spaced out method is desired, I can provide one (especially since pasting to 
mailing lists frequently corrupts/converts tabs to spaces). 


Enjoy!
 -Don
{void} 
Received on 2010-02-12 20:44:25