Saturday, August 26, 2023

10 rsync command examples in Linux | rsync command in Linux

10 examples of  `rsync` commands in Linux that cover a range of use cases:


1. Basic Local Copy:

   Copy files and directories from one location to another on the same machine.

   rsync -av /source/path/ /destination/path/

   

2. Local Copy with Progress:

   Copy with progress indicator showing the transfer progress.

   rsync -av --progress /source/path/ /destination/path/

   

3. Copy to Remote Servers (SSH):

   Copy files to remote servers using SSH.

   rsync -avz  /source/path/ user@destination:/destination/path/

   

4. Exclude Files/Directories:

   Copy while excluding specific files or directories.

   rsync -av --exclude='file.txt' --exclude='dir/' /source/path/ /destination/path/

   

5. Sync Two Directories:

   Synchronize two directories, making the destination an exact copy of the source.

   rsync -av --delete /source/path/  /destination/path/

   

   

6. Copy from Remote with SSH and Port:

   Copy from remote servers using SSH and specifying a custom SSH port.

   rsync -avz -e "ssh -p 2222" user@source:/source/path/   /destination/path/

   

7. Dry Run (Simulation):

   Perform a dry run to see what would be transferred without actually copying.

   rsync -av --dry-run /source/path/ /destination/path/

   

8. Copy Only Newer Files:

   Copy only newer or updated files.

   rsync -av --update /source/path/ /destination/path/

   

9. Bandwidth Limitation:

    Copy with a specific bandwidth limit to avoid overloading the network.

    rsync -avz --bwlimit=1000 /source/path/ user@destination:/destination/path/

    

10 - Copying with a specific SSH key 

rsync -avz -e "ssh -i id_rsa.pem" user@source:/source/path/   /destination/path/


Options 

-a  or --archive : archive mode; equals -rlptgoD (no -H,-A,-X) 

-v or --verbose : increase verbosity

-p  or --perms   : This option causes the receiving rsync to set                  the destination permissions to be the same as
                the source permissions

-u or --update  : skip files that are newer on the receiver

-P is equivalent to --partial --progress

Remember to adapt these commands to your specific paths, usernames, and hostnames as needed. Always exercise caution, especially when working with commands that involve deletions or remote transfers.

No comments:

Post a Comment

Installing Jenkins on RHEL 8 is a straightforward process. Here's a step-by-step guide

Introduction  Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) pipelines...