All pastes #793778 Raw Edit

kojiro

public shellscript v1 · immutable
·published 2007-11-22 16:28 UTC
rendered paste body
#!/bin/bashSRCDIR=$1DSTDIR=$2CURRENTDATE=$(date +%s)#CHECK FOR THE LAST UPDATE LOGif [[ -s lastupdate.log ]]; then	LASTUPDATE=$(<lastupdate.log)else	>lastupdate.log	LASTUPDATE=${CURRENTDATE}fiecho "Creating a backup of ${SRCDIR} in ${DSTDIR}"if [[ -z "${SRCDIR}" ]]; then	echo "You must specify a source directory"	exit 1fiif [[ -z "${DSTDIR}" ]]; then	echo "You must specify a destination directory"	exit 1fi# 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 logecho "${CURRENTDATE}" > lastupdate.log