Saturday, 21 March 2020

Rsync and csync in linux


Today, a typical user has several computers: home and workplace machines,a laptop, a smartphone or a tablet. This makes the task of keeping files and documents in sync across multiple devices all more important.


Rsync offers a reliable method of transmitting only changes within files.
Eg:
suppose 2 job scheduled in crontab job at 10:00 am  & 11:00am (at hour intervel of time).
New folder is the folder need to move from source system to target system. and newfolder consists of 4 files at 10:00am, at 10:35 new file created, so total number of files available now in new folder is 5. When crontab job schedules at 11:00am only 5th file will move from source system to target system with Rsync tool.
This applies not only to text files but also binary files. To detect the differences between files.

Few important Facts about rsync:


  1.  Rsync can be particularly useful when large amounts of data containing only minor changes need to be transmitted regularly.
  2.  Rsync is a tool that copies data only in one direction at a time. (for source to target system only).
  3.  If you need a bidirectional tool which is able to synchronize both source and destination, use Csync.
  4.  The SOURCE and DEST placeholders can be paths, URLs, or both.
  5. When working with Rsync, you should pay particular attention to trailing slashes. A trailing slash after the directory denotes the content of the directory. No trailing slash denotes the directory itself.

Pre-requsites:

  • current user has write permissions to the directory in the target system.
  • Ensure that rsync service already installed in both source and target systems.
                                   yum install rsync   
different rsync commands:

  1. Moving the files with in the system to different directory:
               source-dir> rsync -avz backup.tar.gz  /var/backup/

Here: 
  • source_dir - is the source directory where the backup.tar.gz (which file need to move to target) exist.

  • -avz:

-v Outputs more verbose text 
-a Archive mode; copies files recursively and preserves timestamps, user/group ownership, file permissions, and symbolic links.
-z Compresses the transmitted data 
  • backup.tar.gz is the file which needs to move to target.
  • /var/backup/ is the target directory.
2. To sync directories:

tux > rsync -avz tux /var/backup/ 

tux is the directory.

3.Copying Files and Directories Remotely

pre-requisites: for remote system.
  • The Rsync tool is required on both machines.
  •  To copy files from or to remote directories requires an IP address or a domain name.
  •  A user name is optional if your current user names on the local and remote machine are the same. 
  • Make sure that target server user used in rsync is having with write access.
cmd:

tux > rsync -avz  file.tar.xz    tux@192.168.1.1:X:/path in the destination server





 Configuring and Using an Rsync Server

Rsync can run as a daemon ( rsyncd ) listing on default port 873 for incoming connections. This daemon can receive “copying targets”. 







1 comment:

  1. Hi Naveen
    Your blog is excellent . Completely read rsync for Linux. Can you please post the same rsync for RHEL .
    Please help me

    ReplyDelete