•  Home
  •  Dashboard
  •  Company
    • About Us
    • Blog
    • Careers
    • Contact Us
    • Data Centers
    • Looking Glass
    • Network
    • Reseller
  •  Hosting Services
    • Backup
    • Content Delivery Network
    • Colocation Hosting
    • Dedicated Hosting
    • DDoS Mitigation
    • IP Transit
    • Private Cloud
    • Wavelength
  •  Solutions
    • Ecommerce
    • Finance
    • Gaming
    • Hosting
    • Management
    • Security
    • System Integrator
  •  Support
    • Community
    • Knowledge Base
    • Open A Ticket
  •  USA & Canada: 800-933-1517
  •  International: 626-549-2801
  •  Email: sales@psychz.net
  • Services
    • Dedicated Servers
    • Colocation
    • Private Cloud
    • DDos Protection
    • IP Transit
    • CDN
    • Backup
  • Solutions
    • Ecommerce
    • Security
    • Gaming
    • Hosting
    • Management
    • Finance
    • System Integrator
  • Dashboard

How to rsync two directories

  • Home
  • Client
  • Knowledgebase
  • Linux
  • How to rsync two directories

Table Of Content

Related Articles

  • Linux File Permissions Cheat Sheet
  • The ELK Stack: Elasticsearch, Logstash, Kibana.
  • How to install Node.js on AlmaLinux 8
  • Firewalld commands for CentOS 7 and CentOS 8
  • Managing systemd services and units using systemctl commands
  • How to check RAM for error using Ubuntu Live CD?
  • How to remotely connect to a Linux machine using a smartphone?
  • Unable to Access The Server Via SSH
  • How to clone and migrate a Linux hard drive to another server?
  • SCP Command Syntax Examples in Linux
  • Whitelisting Edge Server IPs
  • traceroute in Linux
  • Ubuntu remove mysql
  • ssh host key verification failed error
  • logrotate
  • setup hourly crontab
  • Views: (16116)
  • Votes: (3)
Was this article helpful?
VOTE

How to rsync two directories

Publisher: Psychz Networks,  October 03,2015

Rsync (Remote Sync) is commonly used for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems.
Rsync can be used to pull and send data over local and remote networks. Rsync is not secure unlike SCP and the risk of traffic being spoof is high, you should always make sure that both local and remote locations are secure prior to using this command.

  • Check 'rsync' is installed
  • Install 'rsync'
  • Important handlers

 

Step 1. Check if "rsync" is installed using the following command

rsync --version

 

Step 2. Installing Rsync (Skip this step if "rsync" already exists)

RPM base OS   yum -y install rsync

Debian / Ubuntu family  apt-get install rsync -y

(NOTE: Before sending data across machines, make sure that the local firewall on both servers has the incoming IP address whitelisted to avoid being block by the firewall.)

Rsync has many flags which can be used to send files over the network, well demonstrate a series of live examples our engineers use to send large files when performing customer migrations.

(NOTE: We recommend to use the screen command to start a screen session when migrating large amounts of data across networks otherwise a disconnect can suddenly kill your migration.)


Example 1:

Sending the entire content of a directory using 10Mbps transfer rate. Replace the X with the destination IP address.
"file" is the example source folder, and "/home/new-file" is the destination folder.

rsync -apW --progress --bwlimit=10000 /file/* root@x.x.x.x:/home/new-file

Example 2:

Sending files and showing a progress bar of the amount of data being transfer and elapse time

rsync -pavW --progress /home/file/* root@x.x.x.x.:/home/new-file

Example 3:

For slow network connections, you can use the following command.

rsync -pavz --progress /home/file/* root@x.x.x.x.:/home/new-file

 

Flags of interest:

-v: verbose is optional to show logs in case errors occur when transferring data
-a: archive the files for data transfer to increase transfer speed
-W: This rule is considered as the whole option, its use to speed up the transfer speed by keeping the whole files intact instead. This is perfect when both sides don’t have limits
-z: this option is used to compress data for slow connections
-p: to retain permissions, this is used if bends end will have the same ownership and permissions
--progress: shows the progress of the download

example 4:

Sending files to remote machines who ssh port are not port 22

rsync -pavW --progress --inplace --rsh='ssh -p 2244' file/*  root@x.x.x.x:/file

NOTE: when sending files using this syntax ; rsync -pavW --progress /home/file/* root@x.x.x.x.:/home/file/* you are telling rsync to create another file folder within the remote server ending with a /file/file. Never end the destination path with a wildcard only as the source path.
You do not need to pre-create the destination path prior to migrating the data, you can simply do;rsync -pavW --progress /home/file/* root@x.x.x.x.:/home/file if the file doesn't exist it will create it and move the data to the new directory.

last updated on July, 30th 2018

Hosting Services
  • Dedicated Hosting
  • Colocation Hosting
  • Backup
  • IP Transit
  • DDoS Mitigation
Support
  • Portal Login
  • Knowledgebase
  • Community
Company
  • About Us
  • Contact Us
  • Network
  • Data Centers
  • Looking Glass
  • Affiliates
  • Reseller
  • Blog
Policies
  • Privacy Policy
  • Acceptable Usage Policy
  • Terms and Conditions
  • Service Level Agreement
Company
  • Psychz Networks,
    A Profuse Solutions Company
    611 Wilshire Blvd #300
    Los Angeles,California 90017
    USA
  • US/Canada: 800-933-1517
  • International: 626-549-2801
Subscribe to Our Mailing List
* indicates required
Copyright © 2023 Psychz Networks, A Profuse Solutions Inc Company