August 19, 2017


Returning from the Tamara in Coorg last week, my only vacation this year, I knew my following week would be nothing short of a back-breaking stone quarry work. So on Monday, just as I was about to get-on, my otherwise reliable work notebook began flashing BSOD. Post frantic calls to IT helpdesk, they dispatched a helpful hardware engineer at running speed. While he patiently went through system diagnostics, I kept my crushed look in-check. In the end, he said it’s software, and the book needs a wipe + reimage routine. I lifted my hands up in exasperation, thinking about my planned work week that just got flushed.

The good thing is that on any given day, I am fully backed-up and up to speed. Ten years ago when I got hit by a bad crash, I vowed to never let this happen to me again. So, everyday my scripts run for about ten minutes before I call it a day, differentially backing everything-up with the ever reliable rsync. So when he asked if I needed more time to manage my data on disk, I said no, and that he should continue. The engineer then proceeded to reimage my machine, while I sat twiddling pencil on print-outs, still hoping to get some work done. Here’s the thing though, and I am trying very hard not to swear, the official images are never up to speed! This makes any freshly reimaged machine all but usable for the next 48 hours, as auto-downloading updates and profiled software, punctuated by countless reboots, completely consumes the computer. It’s often longer as these down-the-wire updates need the corporate hose.

While waiting for my machine to be back on its feet, my thoughts wandered around about the backup routine, the tools I’ve been using, and our pleasant stay at the Tamara. Then I remembered merging a pull request (on my phone) from Rüedlinger, while still on vacation, who wrote a helpful Makefile for the repo. Inspired by this, and by Endler’s wonderful post, I thought of making one for all my backup/restore routines too, which would simplify my scattered backup shell scripts into just one Makefile. So, I wrote one this week. Here it is.

# Makefile for backup and restore routines
# 2017 ckunte



    @echo "Makefile for backup and restore routines"
    @echo 'Usage:'
    @echo '    make backup    backup all mail projects references'
    @echo '    make restore   restore all mail projects references'
    @echo '    make mail      backup all mail'
    @echo '    make proj      backup all projects'
    @echo '    make curr      backup only current projects'
    @echo '    make past      backup only past projects'
    @echo '    make ref       backup all references'
    @echo '    make cref      backup only current references'
    @echo '    make pref      backup only past references'

backup: mail proj ref

    @echo "Backing up all email .."
    @rsync -auv --delete ${SRCE}/mail/ ${DEST}/mail

proj: curr past

ref: cref pref

    @echo "Backing up current projects .."
    @rsync -auv --delete ${SRCE}/${CPRJ}/ ${DEST}/${CPRJ}

    @echo "Backing up past projects .."
    @rsync -auv --delete ${SRCE}/${PPRJ}/ ${DEST}/${PPRJ}

    @echo "Backing up current references .."
    @rsync -auv --delete ${SRCE}/${CREF}/ ${DEST}/${CREF}

    @echo "Backing up past references .."
    @rsync -auv --delete ${SRCE}/${PREF}/ ${DEST}/${PREF}

    @echo "Restoring mail .."
    @rsync -auvmn ${DEST}/mail/ ${SRCE}/mail
    @echo "Restoring projects .."
    @rsync -auvmn ${DEST}/${CPRJ}/ ${SRCE}/${CPRJ}
    @rsync -auvmn ${DEST}/${PPRJ}/ ${SRCE}/${PPRJ}
    @echo "Restoring references .."
    @rsync -auvmn ${DEST}/${CREF}/ ${SRCE}/${CREF}
    @rsync -auvmn ${DEST}/${PREF}/ ${SRCE}/${PREF}

Note: Makefile is fussy about its format: [i] Tabs only (no spaces!) of indent-size 4; [ii] No inline comments to ensure predictable behaviour.

Now instead of running different shell scripts, I just have to run make backup (or time make backup to also know the time taken) or make restore (or time make restore) in the terminal and be done with it. The above Makefile also can run only select pre-defined folders, e.g., I can only choose to backup current projects with make curr, and so on. If I run only make, then it offers these options:

ckunte at air in ~
$ make
Makefile for backup and restore routines


    make backup    backup all mail projects references
    make restore   restore all mail projects references
    make mail      backup all mail
    make proj      backup all projects
    make curr      backup only current projects
    make past      backup only past projects
    make ref       backup all references
    make cref      backup only current references
    make pref      backup only past references

With time option (as in time make backup), 5:44.57 in the example below is the real (clock) time (listed in in this example) the job takes to complete.

sent 1,382,904,905 bytes  received 118 bytes  4,014,238.09 bytes/sec
total size is 4,753,411,072  speedup is 3.44
make mail  17.20s user 48.51s system 19% cpu 5:44.57 total

This downtime gave me a pause, and an opportunity to make my workflow simpler, which I think isn’t bad at all.