aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2010-01-08 01:06:04 -0500
committerDave Reisner <d@falconindy.com>2010-01-08 01:06:04 -0500
commite27598c20d02b14075eba6a0386b205e982a0ee0 (patch)
tree7ff05928ce82c1eff76ad490741029030d83cc20
parent68b1571b8c0deedf6366c24fabb69b4ed3b8348f (diff)
downloadsquashfu-e27598c20d02b14075eba6a0386b205e982a0ee0.tar.gz
Add further debugging -- stop crashing you turd
-rwxr-xr-xsquashfu89
1 files changed, 58 insertions, 31 deletions
diff --git a/squashfu b/squashfu
index 7b42d46..8612594 100755
--- a/squashfu
+++ b/squashfu
@@ -1,48 +1,56 @@
#!/bin/bash
-# Declare base options, overwrite with user specs as necessary
-# MAKE SURE TO CHANGE THIS BEFORE PUSHING PUBLIC
-CONFIG=/home/haruko/dev/git/squashfu/etc/squashfu
-source $CONFIG
-if [[ $? -gt 0 ]]; then
- echo "FATAL: Error in config file. Please check your syntax"
- exit 1
-fi
-
-# Informational output w/ happy colors
+DEBUG=true
debug () {
- echo -e '\033[1;33m??\033[1;m ' $*
+ [[ $DEBUG ]] && echo -e '\033[1;33m??\033[1;m ' $*
+}
+
+info () {
+ echo -e '\033[1;34m::\033[1;m ' $*
}
die () {
echo -e '\033[1;31m!!\033[1;m ' $*
exit 1
}
+
+# Declare base options, overwrite with user specs as necessary
+# MAKE SURE TO CHANGE THIS BEFORE PUSHING PUBLIC
+CONFIG=/home/haruko/dev/git/squashfu/etc/squashfu
+source $CONFIG
+[[ $? -gt 0 ]] && die "Error in config file. Please check your syntax"
+
+# Informational output w/ happy colors
mount_aufs_by_num () {
# Check for the union already being mounted
- grep "${BKUP_ROOT}/rw" /proc/mounts >/dev/null && umount "$BKUP_ROOT/rw"
+ grep "${BKUP_ROOT}/rw" /proc/mounts && umount "$BKUP_ROOT/rw"
# build branch string
branches="br="
- for i in `seq $1 -1 1`; do
- branches="${branches}${BKUP_ROOT}/bins/${i}:"
+ for i in `seq 7 -1 1`; do
+ branches="${branches}${BKUP_ROOT}/bins/${i}=ro:"
done
- branches="${branches}${BKUP_ROOT}/ro"
+ branches="${branches}${BKUP_ROOT}/ro=ro"
# build and execute mount command
+ debug "Mounting union as entirely read only"
mount -t aufs none $BKUP_ROOT/rw -o udba=reval,$branches
+
+ debug "Remount branch $i as read-write"
+ mount -o remount,mod:bins/$1=rw "${BKUP_ROOT}/rw"
}
create_new_seed () {
# For our very first seed, we're writing directly to disk, so
# Delete the data after the squashed seed has been created
- [[ "$1" == "--initial" ]] && run_rsync
+ #[[ "$1" == "--initial" ]] && run_rsync
# Create a new squashfs based on the contents of the union
+ debug "Making new squash seed $(basename $SEED)"
mksquashfs "${BKUP_ROOT}/rw" "$SEED" -b 65536
# Delete the rsync source since its now squashed
- [[ "$1" == "--initial" ]] && rm -rf "${BKUP_ROOT}/rw/*"
+ #[[ "$1" == "--initial" ]] && rm -rf "${BKUP_ROOT}/rw/*"
}
move_old_tree () {
@@ -55,8 +63,7 @@ mount_seed () {
debug "Mounting seed"
# Mount the squashed seed, failing if we can't
mount -o loop,ro "${SEED}" "${BKUP_ROOT}/ro" || {
- echo FATAL: Error mounting $SEED;
- exit 1;
+ die FATAL: Error mounting $SEED;
}
}
@@ -73,48 +80,60 @@ run_rsync() {
EXCLUDES=($(grep ^#- $CONFIG | cut -d- -f2-))
# rsync source to $BKUP_ROOT/rw
- echo Rsync executing with:
- echo Options: ${RSYNC_OPTS[@]}
- echo Includes: ${INCLUDES[@]}
- echo Excludes: ${EXCLUDES[@]}
+ debug "Rsync executing with:"
+ debug " Options: ${RSYNC_OPTS[@]}"
+ debug " Includes: ${INCLUDES[@]}"
+ debug " Excludes: ${EXCLUDES[@]}"
rsync ${RSYNC_OPTS[@]} ${INCLUDES[@]} ${EXCLUDES[@]} ${BKUP_ROOT}/rw || return 1
}
# Unmount union and squash
unmount_all () {
#Union must be unmounted first, or bad things happen
+ debug Unmounting union...
+ read -p "Continue..."
umount "${BKUP_ROOT}/rw"
+ debug Unmounting squash...
+ read -p "Continue..."
umount "$SEED"
}
# Sanity checks
# - Are we root?
-[[ $UID -eq 0 ]] || { echo "Must be root!"; exit 1; }
+[[ $UID -eq 0 ]] || die Must be root!
# - is our BKUP_ROOT valid? (FAIL)
-[[ -w "${BKUP_ROOT}" ]] ||
- { echo "FATAL: Backup root '$BKUP_ROOT' is not a valid location!";
- echo "Please check the setting in /etc/squashfu"; exit 1; }
+[[ -w "${BKUP_ROOT}" ]] ||
+ die "Backup root is not accessible. Please check your setting in /etc/squashfu"
# Blindly unmount all just in case
unmount_all
+read -p "Continue..."
+
# - do we have a proper (expected) directory structure in place?
# Use cd to BKUP_ROOT to avoid issues with brace expansion in a quoted path
cd "$BKUP_ROOT" && mkdir -p {rw,ro,bins/{1,2,3,4,5,6,7}}
# Prep work
# - does seed exist? (if not, our backup is creating the seed)
-[[ -f "$SEED" ]] || {
- echo "No seed found -- creating a new one...";
- create_new_seed "--initial";
+[[ -f "$SEED" ]] || {
+ debug "No seed found -- creating a new one...";
+ create_new_seed;
}
+
+read -p "Continue..."
+
# mount seed if it exists and is not already mounted
-grep "${BKUP_ROOT}/ro" /proc/mounts >/dev/null || mount_seed
+grep "${BKUP_ROOT}/ro" /proc/mounts || mount_seed
+
+read -p "Continue..."
# Prepare union mount with proper bins
mount_aufs_by_num $(( $(date +%u) + $MODIFIER ))
+read -p "Continue..."
+
# Ready for backup!
run_rsync
@@ -132,8 +151,16 @@ run_rsync
fi
}
+read -p "Continue..."
unmount_all
+# Do another sanity check -- check sizes of bins versus squash.
+bin_size=$(du -s ${BKUP_ROOT}/bins | awk '{print $1}')
+sfs_size=$(du -s $SEED awk '{print $1}')
+if [[ bin_size -gt sfs_size ]]; then
+ info "Your incrementals are larger than your seed! You might consider resquashing your backup with $0 --resquash"
+fi
+
# 6) Optional behavior
# --seed-initial Create new seed
# --rollback $1 $2 Rollback to the day specified by $1, mounting at $2