Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 466 lines (373 sloc) 13.235 kB
68b1571 @falconindy Initial commit: extremely alpha
authored
1 #!/bin/bash
9c1a12e @falconindy Bump version to 0.9-beta
authored
2 VER="0.9-beta"
68b1571 @falconindy Initial commit: extremely alpha
authored
3
5a4021b @falconindy Squish some operational bugs. More to go...
authored
4 CONFIG="/etc/squashfu.conf"
5 source "$CONFIG"
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
6
7a830d0 @falconindy Add finish routine, cleanup unneeded code/comments
authored
7 # Informational output w/ happy colors
68b1571 @falconindy Initial commit: extremely alpha
authored
8 debug () {
7130561 @falconindy Convert echo statements in output functions to printf
authored
9 if [[ "$DEBUG" == "true" ]]; then
10 printf '\033[1;33mDEBUG ::\033[1;m %s\n' "$*"
7cf4f20 @falconindy Add more debugging. So much easier to test when aufs doesn't crash ev…
authored
11 fi
e27598c @falconindy Add further debugging -- stop crashing you turd
authored
12 }
13
480d999 @falconindy Implement warn() function in caution yellow
authored
14 warn () {
15 printf '\033[1;33m::\033[1;m %s\n' "$*"
16 }
17
e27598c @falconindy Add further debugging -- stop crashing you turd
authored
18 info () {
7130561 @falconindy Convert echo statements in output functions to printf
authored
19 printf '\033[1;34m::\033[1;m %s\n' "$*"
68b1571 @falconindy Initial commit: extremely alpha
authored
20 }
21
22 die () {
56533c9 @falconindy Tone down die() to only show colons
authored
23 printf '\033[1;31m::\033[1;m %s\n' "$*" >&2
68b1571 @falconindy Initial commit: extremely alpha
authored
24 exit 1
25 }
e27598c @falconindy Add further debugging -- stop crashing you turd
authored
26
93a0e29 @falconindy Reorder functions
authored
27 create_new_squash () {
1b2a164 @falconindy Add option to manually resquash down to MIN_BINS
authored
28 # Args: number of bins to be squashed, -1 on initial creation
93a0e29 @falconindy Reorder functions
authored
29 # Returns: 0 on success, non-zero on failure
30
c307f2f @falconindy Make initial squash directly from sources
authored
31 # If making first seed, create it directly from source
93a0e29 @falconindy Reorder functions
authored
32 if [[ $1 -eq -1 ]]; then
16851c4 @falconindy Refine output for initial squash
authored
33 info "Creating seed from sources (this may take a while)"
908a308 @falconindy Use quoted @ syntax for arrays, don't manually insert quotes
authored
34 mksquashfs "${INCLUDES[@]}" "$SEED" -b 65536 -e "${EXCLUDES[@]}" >/dev/null
4028b77 @falconindy Fix if/then block in create_new_squash
authored
35 if [[ $? -eq 0 ]]; then
faf2c75 @falconindy Be a little more verbose about creating initial squash
authored
36 mount_squash
16851c4 @falconindy Refine output for initial squash
authored
37 info "Seed creation finished. It has been mounted at "$SQUASH_MOUNT" if you would like to make sure the proper files are included"
dfc5d55 @falconindy Return after success in initial seed creation
authored
38 return 0;
faf2c75 @falconindy Be a little more verbose about creating initial squash
authored
39 else
40 die "There was an error creating the initial squash."
41 fi
93a0e29 @falconindy Reorder functions
authored
42 fi
43
44 # Determine oldest $1 bins and mount them with the current squash
45 local old_bins=($(sort -n -r -t: -k2 "$BINVENTORY" | tail -$1 | cut -d: -f1))
46
47 mount_union_with_bins ${old_bins[@]}
48
ceb3329 @falconindy Refine output, at both info and debug levels
authored
49 info "Merging old incrementals"
93a0e29 @falconindy Reorder functions
authored
50 # Create new squash with temp name
ceb3329 @falconindy Refine output, at both info and debug levels
authored
51 mksquashfs "$UNION_MOUNT" "$SEED.replace" -b 65536 >/dev/null
93a0e29 @falconindy Reorder functions
authored
52
53 # If the squash wasn't made correctly, we don't want to continue
54 if [[ $? -ne 0 ]]; then
55 return 1
56 fi
57
58 unmount_all
59
60 # Replace old squash
61 mv "${SEED}.replace" "$SEED"
62
ceb3329 @falconindy Refine output, at both info and debug levels
authored
63 info "Cleaning up inventory"
93a0e29 @falconindy Reorder functions
authored
64 # Delete old bins, and remove entry from binventory
65 for bin in ${old_bins[@]}; do
66 rm -rf "${BINS_DIR}/$bin"
67 sed -i "/^$bin:/d" "$BINVENTORY"
68 done
69
70 # Clean up $binventory
71 sweep_bins
72 }
73
ecc1265 @falconindy Reorder and group functions by purpose
authored
74 create_new_bin () {
75 # Arguments: 1, the number of the bin to create
76 # Returns: 0 on success, non-zero on error
77
78 debug "Asked to create new bin: $1"
79 # Create new directory, fail if it exists (something's wrong)
80 mkdir "${BINS_DIR}/$1"
81 if [[ $? -ne 0 ]]; then
82 return $?
83 fi
84
85 # Update binventory with new bin name and timestamp
86 echo "${1}:$(date +%s)" >> "$BINVENTORY"
87
88 # If write to bin list fails, remove diretory and exit
89 if [[ $? -ne 0 ]]; then
90 rmdir "${BINS_DIR}/${1}"
91 die "Error writing to '$BINVENTORY'"
92 fi
93
94 return
95 }
96
97 # Mounting functions
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
98 mount_squash () {
99 # Arguments: none
100 # Returns: return code of mount command
5a4021b @falconindy Squish some operational bugs. More to go...
authored
101 debug "Mounting Squash"
4c7c890 @falconindy Refer to union mount and squash mount by variables rather than relati…
authored
102 mount -o loop,ro "$SEED" "$SQUASH_MOUNT"
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
103 return $?
104 }
105
106 mount_union_with_bins () {
107 # Arguments: numbers of bins to be mounted (variable number)
108 # Returns: 0 on successful mount, non-zero on failure
959c2c6 @falconindy Cleanup mounting calls. Don't needlessly unmount squash just to mount…
authored
109 info "Mounting union"
88a733e @falconindy Add more debugging, squish more bugs. Still more left.
authored
110 debug "Requested to mount bins: $*"
36a1216 @falconindy EUREKA! Basic backup functionality declared working.
authored
111
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
112 # Mount first as rw, shift, and mount the rest ro
113 branches="br=${BINS_DIR}/$1=rw:"; shift
88a733e @falconindy Add more debugging, squish more bugs. Still more left.
authored
114 if [[ -n $1 ]]; then
115 for bin in $*; do
36a1216 @falconindy EUREKA! Basic backup functionality declared working.
authored
116 branches="${branches}${BINS_DIR}/$bin=ro:"
88a733e @falconindy Add more debugging, squish more bugs. Still more left.
authored
117 done
118 fi
4c7c890 @falconindy Refer to union mount and squash mount by variables rather than relati…
authored
119 branches="${branches}${SQUASH_MOUNT}=ro"
63f83db @falconindy Split off root priviledge check to its own function -- check for each…
authored
120
4c7c890 @falconindy Refer to union mount and squash mount by variables rather than relati…
authored
121 mount -t aufs none "$UNION_MOUNT" -o udba=reval,$branches
97af6e6 @falconindy Split off directory structure creation to its own function
authored
122
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
123 return $?
6f32d3b @falconindy Alphabetize functions
authored
124 }
125
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
126 # Unmounting functions
127 unmount_union () {
128 # Args: none
129 # Returns: return code from umount
ceb3329 @falconindy Refine output, at both info and debug levels
authored
130 info "Unmounting union"
4c7c890 @falconindy Refer to union mount and squash mount by variables rather than relati…
authored
131 while [[ $(mountpoint "$UNION_MOUNT" | grep "is a mount") ]]; do
132 umount "$UNION_MOUNT" 2>/dev/null
5a4021b @falconindy Squish some operational bugs. More to go...
authored
133 sleep 1
134 done
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
135 return $?
eef98cf @falconindy Add support for checking custom mounts
authored
136 }
137
5a4021b @falconindy Squish some operational bugs. More to go...
authored
138 unmount_squash () {
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
139 # Args: none
140 # Returns: return code from umount
ceb3329 @falconindy Refine output, at both info and debug levels
authored
141 info "Unmounting squash"
4c7c890 @falconindy Refer to union mount and squash mount by variables rather than relati…
authored
142 while [[ $(mountpoint "$SQUASH_MOUNT" | grep "is a mount") ]]; do
143 umount "$SQUASH_MOUNT" 2>/dev/null
c40f0ef @falconindy More debugging. Temp filthy hack until I figure out what's causing no…
authored
144 sleep 1
145 done
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
146 return $?
9aab188 @falconindy Split unmount_all into two separate functions, calling both for _all
authored
147 }
148
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
149 unmount_all () {
150 # Args: none
151 # Returns: none
152
955ad5b @falconindy Add checks for root user in rollback, backup, and unmount
authored
153 if [[ $UID -ne 0 ]]; then
154 die "Must be root to unmount."
155 fi
156
985d175 @falconindy Complete rewrite with new structure. Basic framework and backup funct…
authored
157 # Union MUST be unmounted first
158 unmount_union
5a4021b @falconindy Squish some operational bugs. More to go...
authored
159 unmount_squash
7a830d0 @falconindy Add finish routine, cleanup unneeded code/comments
authored
160 }
161
ecc1265 @falconindy Reorder and group functions by purpose
authored
162 check_for_resquash () {
163 # Args: none
164 # Returns: number of bins needing to be merged
165 local number_of_bins=$(grep -vE "^[ ]*$" "$BINVENTORY" | wc -l)
166 debug "Found $number_of_bins bins"
1f96ce1 @falconindy Add usage function and mount checking (and unmounting) in rollback fu…
authored
167
ecc1265 @falconindy Reorder and group functions by purpose
authored
168 if [[ $number_of_bins -gt $MAX_BINS ]]; then
169 return $[ $number_of_bins - $MIN_BINS ]
170 else
171 return 0
172 fi
173 }
1f96ce1 @falconindy Add usage function and mount checking (and unmounting) in rollback fu…
authored
174
ecc1265 @falconindy Reorder and group functions by purpose
authored
175 get_next_available_bin () {
176 # Arguments: none
177 # Returns: Numeric value of the next unused bin
178 next_bin=$[ $(cut -d: -f1 "$BINVENTORY" | sort -n | tail -1) + 1 ]
179 debug "Next available bin = $next_bin"
180 return $next_bin
181 }
1f96ce1 @falconindy Add usage function and mount checking (and unmounting) in rollback fu…
authored
182
ecc1265 @falconindy Reorder and group functions by purpose
authored
183 sweep_bins () {
184 # Arguments: none
185 # Returns: none
1f96ce1 @falconindy Add usage function and mount checking (and unmounting) in rollback fu…
authored
186
ceb3329 @falconindy Refine output, at both info and debug levels
authored
187 info "Rotating chickens"
ecc1265 @falconindy Reorder and group functions by purpose
authored
188 # Make sure bins are numbered in order, clean up if not. In other words,
189 # if we have 10 bins, make sure they're ordered 1 through 10.
035364b @falconindy More cleanup -- comments, output, and deprecated/unused code
authored
190 count=1
ecc1265 @falconindy Reorder and group functions by purpose
authored
191 ls "${BINS_DIR}" | while read bin; do
192 if [[ ! -d "${BINS_DIR}/$count" ]]; then
193 high_bin=$(ls "${BINS_DIR}" | sort -n | tail -1)
ceb3329 @falconindy Refine output, at both info and debug levels
authored
194 debug "Sweeping bin $high_bin into bin $count"
ecc1265 @falconindy Reorder and group functions by purpose
authored
195 mv "${BINS_DIR}/$high_bin" "${BINS_DIR}/$count"
196 sed -i "/^$high_bin:/s/^$high_bin:/$count:/" "$BINVENTORY"
197 fi
198 count=$[ $count + 1 ]
199 done
1f96ce1 @falconindy Add usage function and mount checking (and unmounting) in rollback fu…
authored
200 }
201
20fe278 @falconindy Create skeletons for action handlers
authored
202 action_backup () {
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
203 # Args: options array squashfu was invoked with, shifted 1
204 # Returns: none
205
955ad5b @falconindy Add checks for root user in rollback, backup, and unmount
authored
206 if [[ $UID -ne 0 ]]; then
207 die "Must be root to perform a backup"
208 fi
209
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
210 # Does the binventory exist? If not, prompt to make sure this is an initialization
211 if [[ ! -f "$BINVENTORY" || ! -f "$SEED" ]]; then
5a4021b @falconindy Squish some operational bugs. More to go...
authored
212 read -p "Looks like this is your first time running SquashFu. Is this correct? (y/n) " ans
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
213 while [[ true ]]; do
214 case $ans in
215 [yY]) break ;;
216 [nN]) die "Your bin inventory and/or seed seem to be missing. Please fix this before continuing." ;;
217 *) ;;
218 esac
219 done
220
221 # If we got here, the user answered yes, so initialize a new structure
4c7c890 @falconindy Refer to union mount and squash mount by variables rather than relati…
authored
222 mkdir -p "$UNION_MOUNT"
223 mkdir -p "$SQUASH_MOUNT"
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
224 mkdir -p "${BINS_DIR}"
225 touch "$BINVENTORY"
226 create_new_squash -1
c307f2f @falconindy Make initial squash directly from sources
authored
227 exit 0
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
228 fi
229
ceb3329 @falconindy Refine output, at both info and debug levels
authored
230 info "Backup requested at $(date --rfc-3339=seconds)"
231
959c2c6 @falconindy Cleanup mounting calls. Don't needlessly unmount squash just to mount…
authored
232 # Cleanup union, in case user was doing a rollback and forgot to unmount (or error on last run)
5e7d593 @falconindy Squelch output on mountpoint checks
authored
233 mountpoint "$UNION_MOUNT" &>/dev/null && unmount_union
6ad518d @falconindy Debug action_rollback. Ensure unmount_all runs before we try to do a …
authored
234
5570ac4 @falconindy Merge create_new_incremental() into action_backup()
authored
235 info "Creating new bin"
236 # Make a new bin for this incremenetal
237 get_next_available_bin
7710ab2 @falconindy define new_bin in action_backup so it can be later used to remove the…
authored
238 local new_bin=$?
239 create_new_bin $new_bin
5570ac4 @falconindy Merge create_new_incremental() into action_backup()
authored
240
241 # Determine the mount order via binventory
242 local bin_order=($(sort -n -r -t: -k2 "$BINVENTORY" | cut -d: -f1))
243
244 mountpoint "${SQUASH_MOUNT}" &>/dev/null || mount_squash
245 mount_union_with_bins ${bin_order[@]}
246
247 # Die with error on mount, else start rsync
248 if [[ $? -ne 0 ]]; then
249 return 1;
250 fi
251
252 # Includes are pulled in directly from config
253 EXCLUDES=$(for excl in ${EXCLUDES[@]}; do echo --exclude $excl; done)
254
255 debug "rsync ${RSYNC_OPTS[@]} ${INCLUDES[@]} ${EXCLUDES[@]} "$UNION_MOUNT""
256 info "Creating new incremental"
257 /usr/bin/rsync ${RSYNC_OPTS[@]} ${INCLUDES[@]} ${EXCLUDES[@]} "$UNION_MOUNT"
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
258
647eb3e @falconindy New branch. Goal: optional rollback when rsync fails
authored
259 if [[ $? -gt 0 && $DEL_BIN_ON_FAIL == "true" ]]; then
c2ea987 @falconindy Create function to remove a bin, optionally interactive
authored
260 action_remove_bin $new_bin override
647eb3e @falconindy New branch. Goal: optional rollback when rsync fails
authored
261 fi
262
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
263 check_for_resquash
264 if [[ val=$? -gt 0 ]]; then
265 create_new_squash $val
266 fi
20fe278 @falconindy Create skeletons for action handlers
authored
267
63c55ee @falconindy Flesh out action_backup functionality -- commence testing
authored
268 # TODO: Report if requested
269
ea9d479 @falconindy Keep unmount_all calls in both create_new_squash and in action_backup…
authored
270 unmount_all
ceb3329 @falconindy Refine output, at both info and debug levels
authored
271
272 info "Backup completed at $(date --rfc-3339=seconds)"
20fe278 @falconindy Create skeletons for action handlers
authored
273 }
274
c2ea987 @falconindy Create function to remove a bin, optionally interactive
authored
275 action_remove_bin () {
276 # check if the bin exists both in the binventory AND in the bins directory
4e10aff @falconindy Round1 of bug fixes
authored
277 if [[ $UID -ne 0 ]]; then
205426e @falconindy Check UID and that .bin.list is writeable before proceeding with delete
authored
278 die "Must be root to remove a backup"
279 fi
280
281 if [[ ! -w "$BINVENTORY" ]]; then
282 die "Error writing to ${BINVENTORY}"
283 fi
284
de0275d @falconindy Restructure action_remove_bin
authored
285 if [[ $(grep -E "^$1:" ${BINVENTORY}) && -d "${BINS_DIR}/$1" ]]; then
286 if [[ -z $2 ]]; then
287 echo "Are you SURE you want to remove this bin?"
288 local timestamp=$(sed -n "/$1/s/^[0-9]*://" "${BINVENTORY}")
289 printf "\t%15s %s\n\t%15s %s\n\t%15s %s\n" \
290 "Bin:" "$1" \
291 "Date Created:" "$(date --rfc-3339=seconds --date="1970-01-01 $timestamp sec GMT")" \
292 "Size:" "$(du -sh "${BINS_DIR}/$1" 2>/dev/null | awk '{print $1}')"
293
294 read -p "Confirm deletion (y/N)" confirm
295 if [[ $confirm != "y" ]]; then
296 info "Delete operation aborted"
297 exit 1
298 fi
c2ea987 @falconindy Create function to remove a bin, optionally interactive
authored
299 fi
300
de0275d @falconindy Restructure action_remove_bin
authored
301 info "Deleting bin $1"
302 sed -i "/^$1:[0-9]*/d" "${BINVENTORY}"
303 rm -rf ${BINS_DIR}/$1
304
305 # tidy up!
306 sweep_bins
307 else
308 die "Bin $1 not found."
309 fi
c9e85ab @falconindy Call sweep_bins after a bin is deleted
authored
310
c2ea987 @falconindy Create function to remove a bin, optionally interactive
authored
311 }
312
20fe278 @falconindy Create skeletons for action handlers
authored
313 action_rollback () {
955ad5b @falconindy Add checks for root user in rollback, backup, and unmount
authored
314 # Args: number of backups to roll back
315 # Returns: none
316
317 if [[ $UID -ne 0 ]]; then
318 die "Must be root to perform a rollback"
319 fi
320
146d12d @falconindy Create rollback action handler. Don't rely on wc -l alone to count bi…
authored
321 # Validate input with test cases
322 if [[ -z $1 ]]; then
323 die "The rollback action requires 1 additional argument."
324 fi
325
326 # Form a chronologically ordered list of bins, assuming the user didn't give bogus input
6ad518d @falconindy Debug action_rollback. Ensure unmount_all runs before we try to do a …
authored
327 local bin_list=($(grep -vE "^[ ]*$" "$BINVENTORY" | sort -t: -r -n -k2 | cut -d: -f1))
146d12d @falconindy Create rollback action handler. Don't rely on wc -l alone to count bi…
authored
328
6ad518d @falconindy Debug action_rollback. Ensure unmount_all runs before we try to do a …
authored
329 if [[ $1 -gt ${#bin_list[@]} ]]; then
330 die "Cannot rollback more than ${#bin_list[@]} backups"
146d12d @falconindy Create rollback action handler. Don't rely on wc -l alone to count bi…
authored
331 fi
332
6ad518d @falconindy Debug action_rollback. Ensure unmount_all runs before we try to do a …
authored
333 local num_to_mount=$[ ${#bin_list[@]} - $1 ]
146d12d @falconindy Create rollback action handler. Don't rely on wc -l alone to count bi…
authored
334
5e7d593 @falconindy Squelch output on mountpoint checks
authored
335 mountpoint "$UNION_MOUNT" &>/dev/null && unmount_union
959c2c6 @falconindy Cleanup mounting calls. Don't needlessly unmount squash just to mount…
authored
336 mountpoint "$SQUASH_MOUNT" &>/dev/null || mount_squash
146d12d @falconindy Create rollback action handler. Don't rely on wc -l alone to count bi…
authored
337
6ad518d @falconindy Debug action_rollback. Ensure unmount_all runs before we try to do a …
authored
338 mount_union_with_bins ${bin_list[@]:(-$num_to_mount)}
20fe278 @falconindy Create skeletons for action handlers
authored
339
5f75b00 @falconindy Show date of rollback when operation completes
authored
340 local rb_timestamp=$(grep -E "^${bin_list[@]:(-$num_to_mount):1}:" "$BINVENTORY" | cut -d: -f2)
341
342 info "You have rolled back to $(date --rfc-3339=seconds --date="1970-01-01 $rb_timestamp sec GMT")"
343 info "Your files can be found at '${UNION_MOUNT}'"
20fe278 @falconindy Create skeletons for action handlers
authored
344 }
345
346 action_report () {
7130561 @falconindy Convert echo statements in output functions to printf
authored
347 info "SquashFu Usage Report"
827b1cd @falconindy Add seed size and totals to usage report
authored
348 echo
7130561 @falconindy Convert echo statements in output functions to printf
authored
349 # Enumerate bins, sort date order, print human readable create date and size
41c0916 @falconindy Use preloaded array to generate report
authored
350
e3ff4b6 @falconindy Append to IFS, don't replace it
authored
351 OLDIFS=$IFS;IFS=${IFS}:
41c0916 @falconindy Use preloaded array to generate report
authored
352 # Collect all data into an array to 'preload' it. Index 0 is the entire
353 # folder. The following indicies correspond to the bin number of that index
4cc2382 @falconindy Send reporting loading msg to STDERR
authored
354 printf "%30s\r" " .: Loading :." >&2
41c0916 @falconindy Use preloaded array to generate report
authored
355 DATA=($(du -sh ${BINS_DIR} ${BINS_DIR}/* 2>/dev/null | awk '{print $1}'))
4cc2382 @falconindy Send reporting loading msg to STDERR
authored
356 printf "%30s\r" " " >&2
41c0916 @falconindy Use preloaded array to generate report
authored
357
904f8e1 @falconindy Change first column heading of report to 'Bin ID'
authored
358 printf "%10s\t%25s\t%7s\n" "Bin ID" "Date Created" "Size"
dde831e @falconindy Fix sorting error in report. Sort apparently doesn't honor the IFS to…
authored
359 grep -vE "^[\t ]*$" "$BINVENTORY" | sort -r -t: -k2 -n | while read bin stamp; do
12bd9ee @falconindy Fix incorrect value displaying for seed size
authored
360 printf "%10d\t%25s\t%7s\n" "$bin" \
361 "$(date --rfc-3339=seconds --date="1970-01-01 $stamp sec GMT")" \
362 "${DATA[$bin]}"
b7c5aa2 @falconindy Implement insanely simple bin report with creation date only
authored
363 done
364 IFS=$OLDIFS
41c0916 @falconindy Use preloaded array to generate report
authored
365 printf "%10s\t%25s\t%7s\n" "" "Incremental Total" "${DATA[0]}"
20fe278 @falconindy Create skeletons for action handlers
authored
366
757e28d @falconindy Convert include/exclude heredocs to simple variables. I'm sure I'll e…
authored
367 # Print totals (not efficient -- reruns du on things we already ran it on)
12bd9ee @falconindy Fix incorrect value displaying for seed size
authored
368 printf "\n%10s\t%25s\t%7s\n" "" "$(basename $SEED)" "$(du -h "${SEED}" | awk '{print $1}')"
757e28d @falconindy Convert include/exclude heredocs to simple variables. I'm sure I'll e…
authored
369 printf "\n%10s\t%25s\t%7s\n" "" "Grand Total" \
41c0916 @falconindy Use preloaded array to generate report
authored
370 "$(du -csh "$BINS_DIR" "$SEED" 2>/dev/null | grep -E "total$" | awk '{print $1}')"
20fe278 @falconindy Create skeletons for action handlers
authored
371 }
372
1b2a164 @falconindy Add option to manually resquash down to MIN_BINS
authored
373 action_resquash_now () {
374 # Args: none
375 # Returns: none
376
377 if [[ $UID -ne 0 ]]; then
378 die "Must be root to perform a resquash"
379 fi
380
381 info "Voluntary resquash requested"
382
383 local number_of_bins=$(grep -vE "^[ ]*$" "$BINVENTORY" | wc -l)
384 if [[ $number_of_bins -le $MIN_BINS ]]; then
385 die "Nothing to do. Current backups do not exceed MIN_BINS value."
386 else
387 create_new_squash $[ $number_of_bins - $MIN_BINS ]
388 fi
389
197efd1 @falconindy Exit with return value on action_resquash_now
authored
390 exit $?
1b2a164 @falconindy Add option to manually resquash down to MIN_BINS
authored
391 }
392
de17d54 @falconindy Conform -U option to set action and not immediately execute
authored
393 action_unmount () {
394 unmount_all
395 }
396
ecc1265 @falconindy Reorder and group functions by purpose
authored
397 usage () {
955ad5b @falconindy Add checks for root user in rollback, backup, and unmount
authored
398 info "SquashFu: Super Awesome Backup Express (Professional Edition)"
dd62660 @falconindy Add versioning
authored
399 echo "version: $VER"
ecc1265 @falconindy Reorder and group functions by purpose
authored
400 cat <<HELP
401
402 USAGE
40ca97e @falconindy Add -c option for specifying alternate config
authored
403 squashfu <action> [options]
ecc1265 @falconindy Reorder and group functions by purpose
authored
404
2818589 @falconindy Change 'operations' to 'actions' in usage heredoc
authored
405 ACTIONS
ecc1265 @falconindy Reorder and group functions by purpose
authored
406 -B
a52b1f4 @falconindy Update usage heredoc to actually be accurate for currently supported …
authored
407 Runs a regular backup, using the config file at /etc/squashfu.
ecc1265 @falconindy Reorder and group functions by purpose
authored
408
1b2a164 @falconindy Add option to manually resquash down to MIN_BINS
authored
409 -C
410 Create a new squash by merging old bins. This will still leave you
ddcb110 @falconindy Fix typo in usage
authored
411 with $MIN_BINS backups (as per the MIN_BINS setting in your config).
1b2a164 @falconindy Add option to manually resquash down to MIN_BINS
authored
412
168655f @falconindy Add remove bin option to usage heredoc and options parser
authored
413 -D <bin number>
414 Delete an incremental backup. This is done interactively and you will have
415 a chance to confirm before any files are deleted.
416
ecc1265 @falconindy Reorder and group functions by purpose
authored
417 -Q
a52b1f4 @falconindy Update usage heredoc to actually be accurate for currently supported …
authored
418 Displays the size of the seed, the incrementals, and totals.
ecc1265 @falconindy Reorder and group functions by purpose
authored
419
420 -R <number of bins>
421 Rollback specified number of backups and mount union for browsing. The rolled
422 back data will be mounted at $UNION_MOUNT.
423
424 -U
425 Unmount squash and union. Although SquashFu will always check and unmount as
426 necessary before an operation, this is provided as a safeguard.
427
1723f51 @falconindy Correct spacing on usage heredoc
authored
428 OPTIONS
40ca97e @falconindy Add -c option for specifying alternate config
authored
429 -c <path_to_config>
430 Specify an alternate config file. Options defined will override options in
431 the default config. If you specify alternate locations via a supplmenetal config,
432 you will need to provide the config for all actions
433
ecc1265 @falconindy Reorder and group functions by purpose
authored
434 HELP
cb379d9 @falconindy Clean up verbiage in action_remove_bin()
authored
435 exit 1
ecc1265 @falconindy Reorder and group functions by purpose
authored
436 }
437
dcff2dd @falconindy Reimplement options using getopts
authored
438 [[ -z $1 ]] && ( usage; exit 1; )
439
168655f @falconindy Add remove bin option to usage heredoc and options parser
authored
440 while getopts :BCD:QR:Uc: opt; do
dcff2dd @falconindy Reimplement options using getopts
authored
441 case $opt in
442 B)
56533c9 @falconindy Tone down die() to only show colons
authored
443 action=backup ;;
dcff2dd @falconindy Reimplement options using getopts
authored
444 C)
56533c9 @falconindy Tone down die() to only show colons
authored
445 action=resquash_now ;;
168655f @falconindy Add remove bin option to usage heredoc and options parser
authored
446 D)
447 action="remove_bin $OPTARG" ;;
dcff2dd @falconindy Reimplement options using getopts
authored
448 Q)
56533c9 @falconindy Tone down die() to only show colons
authored
449 action=report ;;
dcff2dd @falconindy Reimplement options using getopts
authored
450 R)
56533c9 @falconindy Tone down die() to only show colons
authored
451 action="rollback $OPTARG" ;;
dcff2dd @falconindy Reimplement options using getopts
authored
452 U)
56533c9 @falconindy Tone down die() to only show colons
authored
453 action=unmount ;;
dcff2dd @falconindy Reimplement options using getopts
authored
454 c)
56533c9 @falconindy Tone down die() to only show colons
authored
455 [[ -f $OPTARG ]] && source $OPTARG ;;
dcff2dd @falconindy Reimplement options using getopts
authored
456 \:)
56533c9 @falconindy Tone down die() to only show colons
authored
457 die "Argument missing from -$OPTARG"
dcff2dd @falconindy Reimplement options using getopts
authored
458 usage ;;
459 \?)
56533c9 @falconindy Tone down die() to only show colons
authored
460 die "Unrecognized option -$OPTARG"
dcff2dd @falconindy Reimplement options using getopts
authored
461 usage ;;
462 esac >&2
463 done
464
cb379d9 @falconindy Clean up verbiage in action_remove_bin()
authored
465 [[ -n $action ]] && action_$action
Something went wrong with that request. Please try again.