diff options
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | backup | 36 | ||||
-rwxr-xr-x | stromboli_backup | 7 |
3 files changed, 29 insertions, 18 deletions
@@ -1,4 +1,6 @@ # backup A wrapper that synchronises the contents of two directories using rsync. Intended for use in stromboli to backup the files from vesuvio. -This script also does some checks to ensure that both data and backup directories are mounted correctly before attempting to copy. +This script also does some checks to ensure that both source and destination directories exist, and it logs the output of rsync. + +`backup` is a generic backup script. `stromboli_backup` is a wrapper that uses `backup` but has some hardcoded parameters specific to stromboli. @@ -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 <src> <dst>" 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" diff --git a/stromboli_backup b/stromboli_backup new file mode 100755 index 0000000..4263065 --- /dev/null +++ b/stromboli_backup @@ -0,0 +1,7 @@ +#!/usr/bin/zsh +# Backup script for stromboli. This synchronises stromboli's local storage with the NFS data from vesuvio. Since this script mounts and umounts the NFS, it should be configured to be mountable without root on fstab. + +mount /home/eddy/data +/home/eddy/bin/backup /home/eddy/data /home/eddy/backup +sync +umount /home/eddy/data |