Monday, December 2, 2024

How to use rsync between two servers

For example, to syncronize two servers so they get identical file structures: 

  • Source server: server1.oric.no 
  • Destination server: server2.oric.no 
  • Execute as: root
target=server2.oric.no && rsync -vaz --delete /u01/app/myfiles ebsuser@$target:/u01/app
This will sync the entire "/u01/app/myfiles" folder + all subfolders.

The --delete flag in rsync ensures that files in the destination directory (ebsuser@$target:/u01/app) that are not present in the source directory (/u01/app/inst) are deleted. This helps keep the destination directory synchronized with the source directory.