Add sync-up script

ce203c1846c78c404b5c0e46b2fd14ecae21924c
Alexis Sellier committed ago 1 parent bb1afd6f
bin/sync-up added +28 -0
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"
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 --del --info=progress2 \
27 +
  --filter=':- .gitignore' \
28 +
  . "${REMOTE_USER}@${REMOTE_HOST}:$REMOTE_DIR/"