Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Reorder and group functions by purpose

  • Loading branch information...
commit ecc1265820a9908a1a6f491cc6642c3513de3d4c 1 parent e8f5984
Dave Reisner authored January 12, 2010

Showing 1 changed file with 90 additions and 89 deletions. Show diff stats Hide diff stats

  1. 179  squashfu
179  squashfu
@@ -19,19 +19,6 @@ die () {
19 19
     exit 1
20 20
 }
21 21
 
22  
-check_for_resquash () {
23  
-# Args: none
24  
-# Returns: number of bins needing to be merged
25  
-    local number_of_bins=$(grep -vE "^[ ]*$" "$BINVENTORY" | wc -l)
26  
-    debug "Found $number_of_bins bins"
27  
-
28  
-    if [[ $number_of_bins -gt $MAX_BINS ]]; then
29  
-        return $[ $number_of_bins - $MIN_BINS ]
30  
-    else
31  
-        return 0
32  
-    fi
33  
-}
34  
-
35 22
 create_new_squash () {
36 23
 # Args: number of bins to be squashed (as determined by check_for_resquash), -1 on initial creation
37 24
 # Returns: 0 on success, non-zero on failure
@@ -102,6 +89,31 @@ create_new_incremental () {
102 89
     return $?
103 90
 }
104 91
 
  92
+create_new_bin () {
  93
+# Arguments: 1, the number of the bin to create
  94
+# Returns: 0 on success, non-zero on error
  95
+
  96
+    debug "Asked to create new bin: $1"
  97
+    # Create new directory, fail if it exists (something's wrong)
  98
+    mkdir "${BINS_DIR}/$1"
  99
+    if [[ $? -ne 0 ]]; then
  100
+        return $?
  101
+    fi
  102
+
  103
+    # Update binventory with new bin name and timestamp
  104
+    debug "Updating $BINVENTORY, adding bin $1"
  105
+    echo "${1}:$(date +%s)" >> "$BINVENTORY"
  106
+
  107
+    # If write to bin list fails, remove diretory and exit
  108
+    if [[ $? -ne 0 ]]; then
  109
+        rmdir "${BINS_DIR}/${1}"
  110
+        die "Error writing to '$BINVENTORY'"
  111
+    fi
  112
+
  113
+    return
  114
+}
  115
+
  116
+# Mounting functions
105 117
 mount_squash () {
106 118
 # Arguments: none
107 119
 # Returns: return code of mount command
@@ -130,60 +142,6 @@ mount_union_with_bins () {
130 142
     return $?
131 143
 }
132 144
 
133  
-get_next_available_bin () {
134  
-# Arguments: none
135  
-# Returns: Numeric value of the next unused bin
136  
-    next_bin=$[ $(cut -d: -f1 "$BINVENTORY" | sort -n | tail -1) + 1 ]
137  
-    debug "Next available bin = $next_bin"
138  
-    return $next_bin
139  
-}
140  
-
141  
-sweep_bins () {
142  
-# Arguments: none
143  
-# Returns: none
144  
-    debug "Entering sweep_bins"
145  
-    count=1
146  
-
147  
-    # Make sure bins are numbered in order, clean up if not. In other words,
148  
-    # if we have 10 bins, make sure they're ordered 1 through 10.
149  
-    ls "${BINS_DIR}" | while read bin; do
150  
-    #for bin in "${BINS_DIR}/*"; do
151  
-        if [[ ! -d "${BINS_DIR}/$count" ]]; then
152  
-            high_bin=$(ls "${BINS_DIR}" | sort -n | tail -1)
153  
-            mv "${BINS_DIR}/$high_bin" "${BINS_DIR}/$count"
154  
-            sed -i "/^$high_bin:/s/^$high_bin:/$count:/" "$BINVENTORY"
155  
-        fi
156  
-        count=$[ $count + 1 ]
157  
-    done
158  
-    debug "Leaving sweep_bins"
159  
-    ls "$BINS_DIR"
160  
-
161  
-}
162  
-
163  
-create_new_bin () {
164  
-# Arguments: 1, the number of the bin to create
165  
-# Returns: 0 on success, non-zero on error
166  
-
167  
-    debug "Asked to create new bin: $1"
168  
-    # Create new directory, fail if it exists (something's wrong)
169  
-    mkdir "${BINS_DIR}/$1"
170  
-    if [[ $? -ne 0 ]]; then
171  
-        return $?
172  
-    fi
173  
-
174  
-    # Update binventory with new bin name and timestamp
175  
-    debug "Updating $BINVENTORY, adding bin $1"
176  
-    echo "${1}:$(date +%s)" >> "$BINVENTORY"
177  
-
178  
-    # If write to bin list fails, remove diretory and exit
179  
-    if [[ $? -ne 0 ]]; then
180  
-        rmdir "${BINS_DIR}/${1}"
181  
-        die "Error writing to '$BINVENTORY'"
182  
-    fi
183  
-
184  
-    return
185  
-}
186  
-
187 145
 # Unmounting functions
188 146
 unmount_union () {
189 147
 # Args: none
@@ -216,33 +174,47 @@ unmount_all () {
216 174
     unmount_squash
217 175
 }
218 176
 
219  
-usage () {
220  
-    info "SquashFu: a backup solution hewn out of boredom"
221  
-    cat <<HELP
222  
-
223  
-USAGE
224  
-    squashfu <operation>
  177
+check_for_resquash () {
  178
+# Args: none
  179
+# Returns: number of bins needing to be merged
  180
+    local number_of_bins=$(grep -vE "^[ ]*$" "$BINVENTORY" | wc -l)
  181
+    debug "Found $number_of_bins bins"
225 182
 
226  
-OPERATIONS
227  
-  -B
228  
-    Runs a regular backup, using the config file at /etc/squashfu, unless
229  
-    otherwise specified with the -c option.
  183
+    if [[ $number_of_bins -gt $MAX_BINS ]]; then
  184
+        return $[ $number_of_bins - $MIN_BINS ]
  185
+    else
  186
+        return 0
  187
+    fi
  188
+}
230 189
 
231  
-  -Q
232  
-    Displays the size of the seed, the incrementals, and the actual backup. If
233  
-    you provide no additional options, a basic report will be given. Specifying
234  
-    "full" will give more detail about individual bins.
  190
+get_next_available_bin () {
  191
+# Arguments: none
  192
+# Returns: Numeric value of the next unused bin
  193
+    next_bin=$[ $(cut -d: -f1 "$BINVENTORY" | sort -n | tail -1) + 1 ]
  194
+    debug "Next available bin = $next_bin"
  195
+    return $next_bin
  196
+}
235 197
 
236  
-  -R <number of bins>
237  
-    Rollback specified number of backups and mount union for browsing. The rolled
238  
-    back data will be mounted at $UNION_MOUNT.
  198
+sweep_bins () {
  199
+# Arguments: none
  200
+# Returns: none
  201
+    debug "Entering sweep_bins"
  202
+    count=1
239 203
 
240  
-  -U
241  
-    Unmount squash and union. Although SquashFu will always check and unmount as 
242  
-    necessary before an operation, this is provided as a safeguard.
  204
+    # Make sure bins are numbered in order, clean up if not. In other words,
  205
+    # if we have 10 bins, make sure they're ordered 1 through 10.
  206
+    ls "${BINS_DIR}" | while read bin; do
  207
+    #for bin in "${BINS_DIR}/*"; do
  208
+        if [[ ! -d "${BINS_DIR}/$count" ]]; then
  209
+            high_bin=$(ls "${BINS_DIR}" | sort -n | tail -1)
  210
+            mv "${BINS_DIR}/$high_bin" "${BINS_DIR}/$count"
  211
+            sed -i "/^$high_bin:/s/^$high_bin:/$count:/" "$BINVENTORY"
  212
+        fi
  213
+        count=$[ $count + 1 ]
  214
+    done
  215
+    debug "Leaving sweep_bins"
  216
+    ls "$BINS_DIR"
243 217
 
244  
-HELP
245  
-    exit 0
246 218
 }
247 219
 
248 220
 action_backup () {
@@ -337,6 +309,35 @@ action_report () {
337 309
            "$(du -csh "$BINS_DIR" "$SEED" 2>/dev/null | grep -E "total$" | awk '{print $1}')"
338 310
 }
339 311
 
  312
+usage () {
  313
+    info "SquashFu: a backup solution hewn out of boredom"
  314
+    cat <<HELP
  315
+
  316
+USAGE
  317
+    squashfu <operation>
  318
+
  319
+OPERATIONS
  320
+  -B
  321
+    Runs a regular backup, using the config file at /etc/squashfu, unless
  322
+    otherwise specified with the -c option.
  323
+
  324
+  -Q
  325
+    Displays the size of the seed, the incrementals, and the actual backup. If
  326
+    you provide no additional options, a basic report will be given. Specifying
  327
+    "full" will give more detail about individual bins.
  328
+
  329
+  -R <number of bins>
  330
+    Rollback specified number of backups and mount union for browsing. The rolled
  331
+    back data will be mounted at $UNION_MOUNT.
  332
+
  333
+  -U
  334
+    Unmount squash and union. Although SquashFu will always check and unmount as 
  335
+    necessary before an operation, this is provided as a safeguard.
  336
+
  337
+HELP
  338
+    exit 0
  339
+}
  340
+
340 341
 case $1 in
341 342
     "-B") action_backup ;;
342 343
     "-Q") action_report ;;

0 notes on commit ecc1265

Please sign in to comment.
Something went wrong with that request. Please try again.