rsync

last edited Sat, 20 Jul 2024 12:26:17 GMT
backlinks: null


You must have established SSH between two hosts

The most wonderul synchronization tool that can be used locally or remote host. Knowing how to properly utilize rsync can streamline backups.

Additional Examples direct link to this section

root@debian-nginx2:~# rsync /root/myveryimportantdirectory root@192.168.0.150:/root/
skipping directory myveryimportantdirectory
root@debian-nginx2:~# rsync -a /root/myveryimportantdirectory root@192.168.0.150:/root/

using ZIP direct link to this section

root@debian-nginx2:~# zip -r backup-$(date --iso-8601) /root/myveryimportantdirectory/
  adding: root/myveryimportantdirectory/ (stored 0%)
  adding: root/myveryimportantdirectory/myveryimportanttext.txt (stored 0%)

send backup to desired host:

root@debian-nginx2:~# rsync backup-$(date --iso-8601).zip root@192.168.0.150:/root/backups/

mirror a directory direct link to this section

Web server example where the /var/www/html directory tree will be copied to the remote host:

$ rsync -av --progress	\
	--exclude '*.swp'	\
	--exclude '/old-css/'	\
	--exclude '/old-js/'	\
	/var/www/html/ example.com:/var/www/html

Where -a denotes archive mode and -v denotes verbose mode (all transfers are narrated).

mirror an entire system direct link to this section

sudo rsync -aAXv amaya:/ –dry-run –-delete –exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/cdrom/*,/lost+found}  /backup

remote host to local host (pull) direct link to this section

rsync -aiv --remove-source-files rhost:/tmp/{file1,file2}.c ~/src/
# or
rsync -av bob@173.82.232.55:remote-file.txt  /home/cherry/data

local to remote host (push) direct link to this section

rsync [options] source [user@host-ip]:dest-on-remote-machine
rsync [options] [user@host-ip]:source dest-on-local-machine