Announcement

Collapse
No announcement yet.

How To Use the Rsync Command in Linux

Collapse
X
Collapse
  •  

  • How To Use the Rsync Command in Linux



    Synchronizing files and data among multiple servers is crucial for smooth functioning. Fortunately, many tools are available online for file synchronization, and Rsync is one of them. Rsync is one of the most popular and widely used utilities for remotely syncing data in Linux.
    Rsync features efficient file transfer, preservation of file metadata, updating existing files, partial transfers, and more. This makes Rsync an ideal choice for nearly all administrators. So, this guide will be all about using the Rsync command in Linux without hassles.
    How To Use the Rsync Command in Linux

    Most Linux distributions contain the Rsync utility, but you have to install it through the following command: 
    Operating System Command
    Debian/Ubuntu sudo apt install rsync 
    Fedora sudo dnf install rsync 
    Arch Linux sudo pacman -Sy rsync
    After completing the installation, please run the below command to initiate data syncing between the source and the target:
    rsync -o source target


    Here, you should replace the source with the directory from where you want to synchronize the data and target with the directory where you want to store that data. For example, let’s sync the Videos and Documents directories by running the following command:
    rsync  -o Videos Documents




    If you want to copy-paste data within the same system, use the following command:
    sudo rsync -avz /source/path /target/path/

    1. The ‘-a’ or ‘–archive’ keeps the file attributes intact during a data transfer.
    2. The ‘-v’ or ‘–verbose’ option is to display what data is being transferred.
    3. Although optional, you should use the ‘-z’ or ‘–compress’ option to compress the data during transfer. This aids in speeding up the synchronization process.

    Let’s take an example and use the above rsync command to synchronize files from the Scripts directory to the Python directory:
    sudo rsync -avz ~/Scripts ~/Python


    Moreover, the primary purpose of rsync is to transfer data remotely between two devices or servers connected over a network:
    rsync -av -e ssh user@remote_host:/source/path/ /target/path


    Here, the ‘-e ssh’ option commands your system to use the secure shell/SSH for this transaction. Furthermore, if the system encounters any interruption during a remote file transfer, don’t worry. You can resume it through the ‘–partial’ option:
    rsync --partial -av -e ssh user@remote_host:/source/path/ /target/path




    Dry Run

    Rsync initiates the file transfer immediately after you enter a command. Therefore, to avoid any unintended consequences, you should always perform a dry run first. During a dry run, your system simply demonstrates the actions of your command without an actual data transfer. Hence, here you can add the ‘–dry-run’ option to start a dry run. For instance, to see what’s going to happen during a data sync from Python to Scripts directory, use:
    rsync -avz --dry-run ~/Python ~/Scripts




    Make Identical Servers

    In case there are some files in the target directory that are not available in the source directory, This results in non-uniformity, and in some cases, it even causes unnecessary disk consumption. So you can use the ‘–delete’ option to delete the data from the target which is not present at the source. For example:
    rsync -av --delete /source/path/ /target/path/




    Show Progress During Transfers

    If you want to see the progress of your transfer, enter the ‘–progress’ option to display the progress indicator. For instance, on enabling the progress indicator, the above example will produce the following results:
    rsync -avz --progress ~/Python ~/Scripts




    A Quick Summary

    Mastering rsync commands enables you to efficiently transfer files to both local and remote hosts. It’s a robust tool for synchronizing data across different locations. This guide comprehensively explains how to use the rsync command in Linux. First, we look at rsync’s installation on Linux systems. Then, it comprehensively demonstrates different rsync commands and methods according to the use cases. 






    More...
      Posting comments is disabled.

    Categories

    Collapse

    Article Tags

    Collapse

    There are no tags yet.

    Latest Articles

    Collapse

    • Using MAXQDA for Qualitative Data Analysis on Linux
      by Kasimba



      by George Whittaker


      Introduction

      Qualitative data analysis (QDA) is a cornerstone of research across various fields, from social sciences to marketing. It involves uncovering patterns, themes, and meanings within non-numerical data such as interviews, focus groups, and textual narratives. In this era of digital tools, MAXQDA stands out as a premier software solution for QDA, empowering researchers to organize...
      11-21-2024, 11:31 PM
    • HAProxy on Ubuntu: Load Balancing and Failover for Resilient Infrastructure
      by Kasimba



      by german.suarez


      Introduction

      In today’s fast-paced digital landscape, ensuring the availability and performance of applications is paramount. Modern infrastructures require robust solutions to distribute traffic efficiently and maintain service availability even in the face of server failures. Enter HAProxy, the de facto standard for high-performance load balancing and failover.


      This article...
      11-21-2024, 03:00 PM
    • Providing a license for package sources
      by Kasimba
      Arch Linux hasn't had a license for any package sources (such as PKGBUILD files) in the past, which is potentially problematic. Providing a license will preempt that uncertainty.

      In RFC 40 we agreed to change all package sources to be licensed under the very liberal 0BSD license. This change will not limit what you can do with package sources. Check out the RFC for more on the rationale and prior discussion.

      Before we make this change, we will provide contributors with...
      11-19-2024, 09:21 AM
    • Linux Binary Analysis for Reverse Engineering and Vulnerability Discovery
      by Kasimba



      by George Whittaker


      Introduction

      In the world of cybersecurity and software development, binary analysis holds a unique place. It is the art of examining compiled programs to understand their functionality, identify vulnerabilities, or debug issues—without access to the original source code. For Linux, which dominates servers, embedded systems, and even personal computing, the skill of binary analysis is...
      11-18-2024, 07:10 PM
    • Ubuntu vs Debian: Linux Distributions Compared Deep Dive
      by Kasimba
      Debian and Ubuntu are two popular Linux distributions. In this deep dive we will guide you on the key differences between them from perspective of both corporate enterprise and personal productivity or pleasure usage. After reading this blog post you should be in a better position to decide to select Ubuntu or Debian.
      Stewardship, Licensing, Community and Cost

      Where as Debian is 100% fully committed to free software as defined by the Debian Free Software Guidelines, Ubuntu is created...
      11-17-2024, 08:30 PM
    • Debian Backup and Recovery Solutions: Safeguard Your Data with Confidence
      by Kasimba



      by George Whittaker


      Introduction

      In the digital age, data loss is a critical concern, and effective backup and recovery systems are vital for any Debian system administrator or user. Debian, known for its stability and suitability in enterprise, server, and personal computing environments, offers a multitude of tools for creating robust backup and recovery solutions. This guide will explore these solutions,...
      11-13-2024, 05:30 PM
    Working...
    X