From 3ee260ee67ee6e17f583c9cc0ac8f7e37c1ae190 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Wed, 4 Apr 2018 20:50:56 +0200 Subject: Made backup script more generic, added specific script for stromboli --- backup | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'backup') diff --git a/backup b/backup index 609c282..c9abda8 100755 --- a/backup +++ b/backup @@ -1,37 +1,39 @@ #!/usr/bin/zsh -# rsyncs data from one mount point to another. By default all subdirectories of the src mount point are copied to the dst mount point. Nothing happens unless both arguments are valid mount points. +# 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. -RSYNC_OPTS='-aP \ +LOG_DIR="$HOME/rsync_logs" +LOG_FILE="$LOG_DIR/$(date --iso-8601).log" + +RSYNC_OPTS="-aP \ --no-owner \ --delete-during \ - --exclude="lost+found"' + --exclude='lost+found' + --log-file='$LOG_FILE'" if [ $# -lt 2 ]; then echo "Usage: backup " exit 1 fi -if [ ! -e $1 ]; then - echo "$1 does not exist" +if [ ! -d "$1" ]; then + echo "$1 does not exist or is not a directory" exit 1 fi -if [ ! -e $2 ]; then - echo "$2 does not exist" +if [ ! -d "$2" ]; then + echo "$2 does not exist or is not a directory" exit 1 fi -lsblk | awk '{ print $7 }' | grep -Fx "$1" > /dev/null -if [ $? -ne 0 ]; then - echo "$1 is not a mount point" - exit 1 -fi +if [ ! -d "$LOG_DIR" ]; then + echo "Log directory does not exist, creating" + mkdir -p "$LOG_DIR" -lsblk | awk '{ print $7 }' | grep -Fx "$2" > /dev/null -if [ $? -ne 0 ]; then - echo "$2 is not a mount point" - exit 1 + if [ $? -ne 0 ]; then + echo "Failed to create log directory, exiting" + exit 1 + fi fi - +rsync $RSYNC_OPTS "${1%/}/*" "$2" -- cgit v1.2.3