#!/bin/sh # moses -- make backups set -e CMD=$1 DIR=$2 usage() { echo "usage:\n\ moses new - make a new backup\n\ moses del - delete the oldest backup" exit 1 } if [ -z $CMD ]; then usage; fi if [ -z $DIR ]; then usage; fi new() { NAME=$DIR-$(date +%s).bak echo "creating $NAME..." cp -r $DIR $DIR-$(date +%s).bak } del() { OLDEST=$(find $(dirname $DIR) \ -name "$(basename $DIR)-*.bak" \ | sort \ | head -n 1) echo "deleting $OLDEST..." rm -r $OLDEST } $CMD || usage