+
+function deleteLock {
+    if ! rmdir /var/lock/$(basename $0); then
+        scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!"
+    fi
+}
+
+function cleanup_abort {
+    scottyerror "Caught exit signal! Cleaning up."
+
+    cleanup ABORT
+
+    if [ $(jobs -p) ]; then
+        scottyerror "TERMinating remaining child processes."
+        kill $(jobs -p)
+    fi
+
+    deleteLock
+
+    exit
+}
+
+function cleanup {
+    scottyinfo "No cleanup function was defined."
+}
+
+function prepare {
+    scottyinfo "No prepare function was defined."
+}
+
+function cleanup_normal {
+    cleanup
+    deleteLock
+}
+
+function printhelp {
+    cat <<EOF
+Usage: $(basename $0) [OPTION]...
+
+Recognized options:
+  -q   Only output errors
+  -n   Run only on nth day
+  -f   Force backup
+  -h   Print out this help
+EOF
+}
+
+function backmeupscotty {
+    while getopts "qn:fh" opt; do
+        case $opt in
+            q)
+                exec > /dev/null
+                ;;
+            n)
+                BACKUP_RUNEVERYNTHDAY=$OPTARG
+                ;;
+            f)
+                BACKUP_FORCE=1
+                ;;
+            h)
+                printhelp
+                exit 0
+                ;;
+        esac
+    done
+
+    ssh255 $REMOTE_HOST exit
+
+    if [ $BACKUP_FORCE -eq 1 ]; then
+        scottyinfo "Backup was enforced."
+    elif latestTooOld; then
+        scottyerror "The latest backup is too old."
+    elif isNthDay; then
+        scottyinfo "This is the nth day."
+    else
+        scottyinfo "No backup has to be done. Exiting."
+        exit 0
+    fi
+
+    scottyinfo "Performing backup."
+
+    trap cleanup_abort EXIT
+
+    prepare
+    scottysync
+
+    trap cleanup_normal EXIT
+
+    exit 0
+}
+
+if ! mkdir /var/lock/$(basename $0); then
+    scottyerror "Another instance of $(basename $0) is still running!"
+    exit 1
+else
+    trap deleteLock EXIT
+fi