bin/sync-up 661 B raw
1
#!/bin/sh
2
set -e
3
4
REMOTE_HOST=backup
5
REMOTE_USER=$USER
6
7
# Check if directory parameter is provided.
8
if [ $# -ne 1 ]; then
9
  echo "usage: $0 <dir>"
10
  exit 1
11
fi
12
13
# Check if the provided path exists and is a directory.
14
if [ ! -d "$1" ]; then
15
  echo "Error: '$1' is not a directory or does not exist"
16
fi
17
18
# Enter directory to upload.
19
cd "$1" && shift
20
# Get absolute path.
21
DIR=$(pwd)
22
# Get the relative path from current directory.
23
REMOTE_DIR=$(echo "$DIR" | sed "s#^$HOME/##")
24
25
echo "$DIR -> ${REMOTE_USER}@${REMOTE_HOST}:$REMOTE_DIR"
26
exec rsync -avz -R --mkpath --info=progress2 \
27
  --filter=':- .gitignore' "$@" \
28
  . "${REMOTE_USER}@${REMOTE_HOST}:$REMOTE_DIR/"