aboutsummaryrefslogtreecommitdiffstats
path: root/backup
blob: c98539917faa73d2d7d12ed94e7bf1bfa4710838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/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 <src> <dst>"
    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"