#!/usr/bin/zsh # rsyncs data from one directory to another. By default all subdirectories of the src directory are copied to the dst directory. Nothing happens unless both arguments are valid directories. LOG_DIR="$HOME/rsync_logs" LOG_FILE="$LOG_DIR/$(date --iso-8601).log" RSYNC_OPTS="-aP \ --no-owner \ --delete-during \ --exclude='lost+found' --log-file='$LOG_FILE'" if [ $# -lt 2 ]; then echo "Usage: backup " exit 1 fi if [ ! -d "$1" ]; then echo "$1 does not exist or is not a directory" exit 1 fi if [ ! -d "$2" ]; then echo "$2 does not exist or is not a directory" exit 1 fi if [ ! -d "$LOG_DIR" ]; then echo "Log directory does not exist, creating" mkdir -p "$LOG_DIR" if [ $? -ne 0 ]; then echo "Failed to create log directory, exiting" exit 1 fi fi rsync $RSYNC_OPTS "${1%/}/*" "$2"