#!/bin/bash # Makes a backup of a DreamHost user's account # # Step 1: creates backups into the directory '~/{USER}.backups' # Step 2: calls the '~/bin/makeLocalBackups.sh' script, if it exists # Step 3: rsyncs the contents of the '~/{USER}.backups' directory to the # DreamHost provided backup space (an ssh key is installed there.) # symlinks are followed in this backup, so dirs to-be-backed-up can be symlinked there # # Requires the template file to be completed to supply constants. # Also requires an passphrase-less ssh key be supplied to enable ssh backups to the backup user. # See README file. # # # Call the template file if available templateFile="`dirname ${0}`/dhsetup.sh" if [ -x "${templateFile}" ]; then . "${templateFile}" fi # # Constants. # These are based on the DreamHost setup. # If USER is not defined, try 'LOGNAME' which is defined by cron if [ -z "${USER}" ]; then USER="${LOGNAME}" fi export HOME="/home/${USER}" export BIN="${HOME}/bin" export BACKUP_DIR="${HOME}/${USER}.backups" # Dreamhost backup user information # The backup username, DH_BACKUP_USER, is defined in the template file DH_BACKUP_HOST="backup.dreamhost.com" if [ -n "${DH_BACKUP_PREFIX}" ]; then DH_BACKUP_DIR="/home/${DH_BACKUP_USER}/${DH_BACKUP_PREFIX}" else DH_BACKUP_DIR="/home/${DH_BACKUP_USER}" fi # The backup script name LOCAL_BACKUP_SCRIPT="makeLocalBackups.sh" # # Begin backup echo -e "\n*** *** Performing backup for user '${USER}'" # Backup the bin directory. Does not follow links. echo -e "*** Backing up bin directory" rsync -rptgov ${BIN} ${BACKUP_DIR} # Call local backup script to create backup stuff # Find locally first, then within links localScript="`find "${BIN}" -name "${LOCAL_BACKUP_SCRIPT}" -perm /u+x | head -1`" if [ ! -x "${localScript}" ]; then localScript="`find -L "${BIN}" -name "${LOCAL_BACKUP_SCRIPT}" -perm /u+x | head -1`" fi if [ -x "${localScript}" ]; then echo "*** Calling '${localScript}'" ${localScript} echo "*** Call to '${localScript}' complete." fi # # Begin rsync to backup account if [ -n "${DH_BACKUP_USER}" ]; then echo "*** Performing rsync to backup account." rsync -rLptgov --delete -e ssh ${BACKUP_DIR} ${DH_BACKUP_USER}@${DH_BACKUP_HOST}:${DH_BACKUP_DIR} fi echo -e "\n*** *** Backup complete for user '${USER}'"