Backup to Encrypted USB Key Fob

dale's picture

I described creating an Encrypted USB Key Fob previously. Here is a script I use to backup my data to it. It rsyncs a few directories and will also download your calendar and contacts from Zimbra if you are so blessed.

Just put this script on the key in bin/backup. Put the key in each computer and cd to /mnt/disk/bin and run the script. If you are not prompted for the password when you insert the key run 'sudo /sbin/cryptsetup luksOpen /dev/sdb1 dm-usb'.

#!/bin/bash
################################################################################
# Dale Bewley  Tue Dec 11 14:14:04 PST 2007
#-------------------------------------------------------------------------------
# Script to backup misc private and settings files to usb key.
# You might stick the key in each of your machines and
# run this script to backup your important or sentimental
# personal files.
#
# Be sure to encrypt the key first: 
#   http://tofu.org/drupal/node/27
#
# Todo:
#   o Think more about what is useful to backup (.kde? .gnome?)
#     .kde has a whole lot of application data in it such as amarok podcasts...
################################################################################

#- Config ----------------------------------------------------------------------
# where is the key mounted?
ROOT=$(df `pwd`|tail -1| awk '{print $6}')
# what host are we on?
# this won't work on seitan for some reason
#HOST=`hostname -s`
HOST=`hostname | awk -F. '{print $1}'`
# remove files on backup that are gone on source
PURGE=''
# backup contacts from zimbra?
CONTACTS=''
#-------------------------------------------------------------------------------

echo "Backing up files to $ROOT/$HOST"
if [ -z "$PURGE" ]; then
    echo -n "Delete files in backup that have been removed from source?: [y/N] "
    read PURGE
fi

if [ "y" == "$PURGE" ]; then
    PURGE='--delete'
else
    PURGE=''
fi

# backup favorite settings
cd ~
mkdir -p "$ROOT/$HOST"
rsync -avr $PURGE bin     "$ROOT/$HOST/"
rsync -avr $PURGE .ssh    "$ROOT/$HOST/"
rsync -avr $PURGE .bash* .profile   "$ROOT/$HOST/"
rsync -avr $PURGE .gnupg  "$ROOT/$HOST/"
rsync -avr $PURGE .purple "$ROOT/$HOST/"
rsync -avr $PURGE .mozilla --exclude Cache "$ROOT/$HOST/"

# backup zimbra contacts and calendar
if [ -z "$CONTACTS" ]; then
    echo -n "Download contacts and calendar from Zimbra?: [y/N] "
    read CONTACTS
fi

if [ "y" == "$CONTACTS" ]; then
    mkdir -p "$ROOT/zimbra"
    echo "Downloading Zimbra contacts to $ROOT/zimbra/${USER}-zimbra.vcf:"
    curl -k -u "${USER}" \
        "https://zimbra/home/${USER}/contacts?fmt=vcf" \
        > "$ROOT/zimbra/${USER}-zimbra.vcf"

    echo "Downloading Zimbra calendar to $ROOT/zimbra/${USER}-zimbra.ics:"
    curl -k -u "${USER}" \
        "https://zimbra/home/${USER}/calendar?fmt=ics" \
        > "$ROOT/zimbra/${USER}-zimbra.ics"
fi