#!/bin/bash SRCDIR=$1 DSTDIR=$2 CURRENTDATE=$(date +%s) #CHECK FOR THE LAST UPDATE LOG if [[ -s lastupdate.log ]]; then LASTUPDATE=$(lastupdate.log LASTUPDATE=${CURRENTDATE} fi echo "Creating a backup of ${SRCDIR} in ${DSTDIR}" if [[ -z "${SRCDIR}" ]]; then echo "You must specify a source directory" exit 1 fi if [[ -z "${DSTDIR}" ]]; then echo "You must specify a destination directory" exit 1 fi # Logical flaw, if CURRENTDATE is now, then nothing was updated... DSTDIR="${DSTDIR}/${CURRENTDATE}" mkdir -p "${DSTDIR}" find "${SRCDIR}" -maxdepth 1 -type f -newer lastupdate.log -exec cp {} "${DSTDIR}/" \; -exec echo "{} was updated, creating a copy" \; find "${SRCDIR}" -maxdepth 1 \( -newer lastupdate.log \) -prune -o -type f -exec ln {} "${DSTDIR}/" \; -exec echo "{} was not updated, creating a hard link" \; #Store the new date in the log echo "${CURRENTDATE}" > lastupdate.log