1apt update && apt install rsync
2
3#Access via remote shell:
4# Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
5# Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
6
7# Pull: sync remote with local
8rsync -vhaze ssh user@server.example.com:/var/www/ /var/www
9rsync -vPhaze "ssh -p 1234 -i /root/.ssh/id_rsa" root@server.example.com:/var/www/cakebox.me/public_html/ /var/www/cakebox.me/public_html
10rsync -qaze "ssh -p 1234 -i /root/.ssh/id_rsa" root@server.example.com:/etc/letsencrypt/archive :/etc/letsencrypt/live :/etc/letsencrypt/renewal /etc/letsencrypt/
-v, --verbose increase verbosity
-h, --human-readable output numbers in a human-readable format
-q, --quiet suppress non-error messages
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
-z, --compress compress file data during the transfer
-e, --rsh=COMMAND specify the remote shell to use
--progress show progress during transfer
-P same as --partial --progress
-e
is basically the shell to use, e.g. ssh -p 2234 -i /user/.ssh/id_rsa
, followed by the command-a
is used for preservation (ownership, permissions, soft links etc.)~
will not expand, so you have to use /userhome
-e
flag. -e
determines the remote shell, so if you’re using the option, you’re pulling, i.e. syncing remote changes to local.-e
can not be used when you’re syncing local changes to remoteCreate an unprivileged user for the sake of transferring files
1useradd -d /home/rsyncuser -m -s /bin/bash rsyncuser
2passwd rsyncuser
Create and copy an SSH key for password-less access
1# Generate, copy and connect with an SSH key
2ssh-keygen -t rsa
3ssh-copy-id -i /home/
4rsyncuser/.ssh/id_rsa.pub rsyncuser@webserver.example.com
5ssh rsyncuser@webserver.example.com
Create a cronjob to automate the whole thing
1crontab –e
2*/5 * * * * rsync -vhaze "ssh -p 1234 -i /root/.ssh/id_rsa" root@server.example.com:/var/www/cakebox.me/public_html/ /var/www/cakebox.me/public_html