rsync

On-the-fly backup (backup a running system)

sudo rsync -e "ssh -i ${HOME}/.ssh/id_rsa" \
  -av \
  --delete \
  --numeric-ids \
  --exclude=proc/* \
  --exclude=sys/* \
  --exclude=tmp/* \
  root@${HOST}:/ .

limit bandwith to 2 mbit/s

rsync --bwlimit=2000 --delete -avz root@www.example.com:/ /media/backup/www.example.com/$(date -I)/
 
# Specify SSH key and configuration
sudo rsync -av \
    -e "ssh -i /home/foo/.ssh/id_rsa -F /home/foo/.ssh/config" \
    --delete \
    --numeric-ids \
    -av \
    /from/dir/ root@192.168.0.1:/to/dir
 
--ignore-times

Set owner and permissions

rsync -og --chown=nobody:nogroup --chmod=644 file.txt root@example.com:/dir/file.txt

Rsync files betwen two remote hosts withoud direct connection

HOST_FROM=www.example.com
HOST_TO=new.example.com
DIR_FROM=/var/www/html/
DIR_TO=/var/www/html/
ssh -A -R localhost:50000:${HOST_TO}:22 ${HOST_FROM} "rsync -e 'ssh -o StrictHostKeyChecking=no -p 50000' --delete -a ${DIR_FROM} localhost:${DIR_TO}"

Delete files after successfully copy

sshpass -p "${SSH_PASS}" rsync -av --remove-source-files -e ssh ${SSH_USER}@${SSH_HOST}:~/htdocs/*.gz /mnt/backup/