Basic backups through rsync

Rsync is powerful, but not that simple. Here is a script I use to backup data on a remote server. Script is launched by the client (i.e. laptop / source) and logs stored on tyhe server (dest) for easier parsing and monitoring

#! /bin/bash

# backup
# logs on the receiver side
# $1 : source folder
# $2 : dest folder 

USER="my_dedicated_user_for_backups"
KEY="my_passwordless_strong_ssh_key"
PORT=22 # or whatever ..
SERVER="server_address"
BACKUP_DIR="00-BACKUP`date '+%Y%m'`--\(nosync\)/"
BASE_SYNC_DIR="/mnt/backup"
LOGFILE="/var/log/rsync/$2.log"

SOURCE="$1/"
DEST="$USER@$SERVER:$BASE_SYNC_DIR/$2/"

echo "copying data From : $SOURCE"
echo "             To   : $DEST"

rsync -avirze "ssh -p$PORT -i$KEY" --chmod=u+w \
      --exclude="**(nosync)**" \
      --exclude="Trash/" \
      --exclude=".mozilla/" \
      --exclude=".cache/" \
      --exclude=".thumbnails/" \
      --delete-after --backup --backup-dir="$BACKUP_DIR" \
      --remote-option=--log-file="$LOGFILE" \
      $SOURCE $DEST

# -a archive : includes recursion (as long as --file-from is not used), preserve everything (but not hard links)
# -v some logs
# -i itemize-changes : give more information about each change done on the file
# -r recursion : not needed apparently ... extra-paranoïa
# -z compress
# -e remote shell (and required params) 

links

social