• About Us
  • Disclaimers
  • Privacy Policy
  • Sitemap
Linux Tutorials for Beginners
Advertisement
  • Ubuntu
    Install and Secure phpMyAdmin on Ubuntu 22.04

    How To Install and Secure phpMyAdmin on Ubuntu 22.04

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Ubuntu 22.04

    Install Uptime Kuma on Ubuntu 22.04

    How To Install Uptime Kuma on Ubuntu 22.04

    Install Ubuntu Server 22.04

    How To Install Ubuntu Server 22.04 LTS with Screenshots

    Set Up Firewall on Ubuntu 22.04

    How To Set Up a Firewall with UFW on Ubuntu 22.04

    Install Nginx on Ubuntu

    How To Install Nginx on Ubuntu 22.04: A Comprehensive Guide

    Install MySQL 8.0 on Ubuntu 22.04

    How To Install MySQL 8.0 on Ubuntu Server 22.04

    install-php74-ubuntu2204

    How To Install PHP 7.4 on Ubuntu 22.04

    Install Snipe-IT on Ubuntu 22.04

    How To Install Snipe-IT Asset Management on Ubuntu 22.04

  • Debian
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Debian 11

    Install Debian 11 Server

    How To Install Debian 11 (Bullseye) Server with Pictures

    Install and Setup Node.js on Debian 11

    How To Install and Setup Node.js on Debian 11

    Install PHP 8.2 on Debian 11

    How To Install PHP 8.2 on Debian 11

    Install Nginx on Debian 11

    How To Install Nginx on Debian 11: A Comprehensive Guide

    Set Up Firewall with UFW on Debian

    How To Set Up a Firewall with UFW on Debian 11

    install php74 on debian 11

    How To Install PHP 7.4 on Debian 11

    Install MariaDB 10.9 on Debian 11

    How To Install MariaDB 10.9 on Debian 11 Server

    Initial Setup Debian Server

    Initial Setup Debian 11 Server: Secure and Efficient

  • Rocky Linux
    Install phpMyAdmin on Rocky Linux 9

    How To Install phpMyAdmin on Rocky Linux 9

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Rocky Linux 9

    Install Rocky Linux 9.2 Server

    How To Install Rocky Linux 9.2 Server with Screenshots

    setup Firewall Using Firewalld Rocky Linux 9

    How To Set Up a Firewall Using FirewallD on Rocky Linux 9

    Install Nginx on Rocky Linux 9

    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide

    Install Apache on Rocky Linux

    How To Install and Configure Apache on Rocky Linux 9

    Install MongoDB on Rocky Linux 9

    How To Install MongoDB 6.0 on Rocky Linux 9

    Install Docker on Rocky Linux

    How To Install Docker CE on Rocky Linux 9

  • CentOS
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on CentOS 7

    Install PHP8.2 on CentOS 7

    How To Install PHP 8.2 on CentOS 7 / RHEL 7

    Install Apache on CentOS 7

    How To Install Apache Web Server on CentOS 7

    Set Up FirewallD on CentOS 7

    How To Set Up a Firewall Using FirewallD on CentOS 7

    Initial Setup CentOS 7 Server

    Initial Setup CentOS 7 Server: Secure and Efficient

    Install Nginx on CentOS 7

    How To Install Nginx on CentOS 7: A Comprehensive Guide

    Build NGINX from Source on Centos 7

    How To Build NGINX from Source (Compile) on Centos7

    Install Docker Swarm on CentOS 7

    Install and Configure Docker Swarm Mode on Centos 7

    Install Docker Compose on Centos 7

    How To Install and Use Docker Compose on Centos 7

  • Linux
    Manage Groups on Linux

    A Simple Guide: How To Manage Groups on Linux

    Logrotate In Linux

    How To Manage Log Files Using Logrotate In Linux

    Check File Size in Linux

    The Easy Ways to Check File Size in Linux

    Linux server security system administrators

    Best Practices Linux Server Security for System Administrator

    Backup Files From Remote Linux VPS Using Rsync Script

    How To Backup Files From Remote Linux VPS Using Rsync Script

    SSH Key-based Authentication

    How To Configure SSH Key-based Authentication In Linux

    Linux File Permissions

    Understanding Linux File Permissions for Beginners

    Create Multiboot USB with Ventoy

    How To Create Multiboot USB with Ventoy in Linux

    Find Hard Disk Drive Information in Linux

    How To Find Hard Disk Drive Information in Linux

No Result
View All Result
Linux Tutorials for Beginners
  • Ubuntu
    Install and Secure phpMyAdmin on Ubuntu 22.04

    How To Install and Secure phpMyAdmin on Ubuntu 22.04

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Ubuntu 22.04

    Install Uptime Kuma on Ubuntu 22.04

    How To Install Uptime Kuma on Ubuntu 22.04

    Install Ubuntu Server 22.04

    How To Install Ubuntu Server 22.04 LTS with Screenshots

    Set Up Firewall on Ubuntu 22.04

    How To Set Up a Firewall with UFW on Ubuntu 22.04

    Install Nginx on Ubuntu

    How To Install Nginx on Ubuntu 22.04: A Comprehensive Guide

    Install MySQL 8.0 on Ubuntu 22.04

    How To Install MySQL 8.0 on Ubuntu Server 22.04

    install-php74-ubuntu2204

    How To Install PHP 7.4 on Ubuntu 22.04

    Install Snipe-IT on Ubuntu 22.04

    How To Install Snipe-IT Asset Management on Ubuntu 22.04

  • Debian
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Debian 11

    Install Debian 11 Server

    How To Install Debian 11 (Bullseye) Server with Pictures

    Install and Setup Node.js on Debian 11

    How To Install and Setup Node.js on Debian 11

    Install PHP 8.2 on Debian 11

    How To Install PHP 8.2 on Debian 11

    Install Nginx on Debian 11

    How To Install Nginx on Debian 11: A Comprehensive Guide

    Set Up Firewall with UFW on Debian

    How To Set Up a Firewall with UFW on Debian 11

    install php74 on debian 11

    How To Install PHP 7.4 on Debian 11

    Install MariaDB 10.9 on Debian 11

    How To Install MariaDB 10.9 on Debian 11 Server

    Initial Setup Debian Server

    Initial Setup Debian 11 Server: Secure and Efficient

  • Rocky Linux
    Install phpMyAdmin on Rocky Linux 9

    How To Install phpMyAdmin on Rocky Linux 9

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Rocky Linux 9

    Install Rocky Linux 9.2 Server

    How To Install Rocky Linux 9.2 Server with Screenshots

    setup Firewall Using Firewalld Rocky Linux 9

    How To Set Up a Firewall Using FirewallD on Rocky Linux 9

    Install Nginx on Rocky Linux 9

    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide

    Install Apache on Rocky Linux

    How To Install and Configure Apache on Rocky Linux 9

    Install MongoDB on Rocky Linux 9

    How To Install MongoDB 6.0 on Rocky Linux 9

    Install Docker on Rocky Linux

    How To Install Docker CE on Rocky Linux 9

  • CentOS
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on CentOS 7

    Install PHP8.2 on CentOS 7

    How To Install PHP 8.2 on CentOS 7 / RHEL 7

    Install Apache on CentOS 7

    How To Install Apache Web Server on CentOS 7

    Set Up FirewallD on CentOS 7

    How To Set Up a Firewall Using FirewallD on CentOS 7

    Initial Setup CentOS 7 Server

    Initial Setup CentOS 7 Server: Secure and Efficient

    Install Nginx on CentOS 7

    How To Install Nginx on CentOS 7: A Comprehensive Guide

    Build NGINX from Source on Centos 7

    How To Build NGINX from Source (Compile) on Centos7

    Install Docker Swarm on CentOS 7

    Install and Configure Docker Swarm Mode on Centos 7

    Install Docker Compose on Centos 7

    How To Install and Use Docker Compose on Centos 7

  • Linux
    Manage Groups on Linux

    A Simple Guide: How To Manage Groups on Linux

    Logrotate In Linux

    How To Manage Log Files Using Logrotate In Linux

    Check File Size in Linux

    The Easy Ways to Check File Size in Linux

    Linux server security system administrators

    Best Practices Linux Server Security for System Administrator

    Backup Files From Remote Linux VPS Using Rsync Script

    How To Backup Files From Remote Linux VPS Using Rsync Script

    SSH Key-based Authentication

    How To Configure SSH Key-based Authentication In Linux

    Linux File Permissions

    Understanding Linux File Permissions for Beginners

    Create Multiboot USB with Ventoy

    How To Create Multiboot USB with Ventoy in Linux

    Find Hard Disk Drive Information in Linux

    How To Find Hard Disk Drive Information in Linux

No Result
View All Result
Linux Tutorials for Beginners
No Result
View All Result

Home » Linux » How To Use Rsync to Sync Local and Remote Directories in Linux

How To Use Rsync to Sync Local and Remote Directories in Linux

sammbysamm
November 9, 2023
Rsync to Sync Local and Remote

How To Use Rsync to Sync Local and Remote Directories

Share on FacebookShare on LinkedinShare on Whatsapp

Introduction

In the world of Linux, efficient data management is key, and Rsync stands out as a potent tool for synchronizing files and directories between local and remote systems seamlessly. This comprehensive guide will walk you through the process “How To Use Rsync to Sync Local and Remote Directories on your Linux system”. By the end of this guide, you’ll have a solid understanding of how to optimize your data synchronization workflow.

Table of Contents

  • Introduction
  • Understanding the Significance of Data Synchronization
  • Prerequisites
  • Setting Up Rsync on Your Linux
    • CentOS:
    • Rocky Linux
    • Debian/Ubuntu
    • OpenSUSE
  • Rsync Syntax for Directory Sync
    • Syncing Local to Remote
    • Syncing Remote to Local
    • Exclude Files or Directories in Rsync
    • Preserve File Permissions and Ownership
    • Automation Made Easy: Scheduling Sync Tasks with Cron
    • Ensuring Security in Data Synchronization
  • Conclusion

Understanding the Significance of Data Synchronization

Effective data synchronization is vital in maintaining consistency across multiple systems. Whether you’re a developer collaborating on a project or a system administrator managing critical files, ensuring data is mirrored accurately between local and remote systems is imperative.

OTHER POSTS

A Simple Guide: How To Manage Groups on Linux

How To Manage Log Files Using Logrotate In Linux

The Easy Ways to Check File Size in Linux

Prerequisites

In order to practice using rsync to sync files between a local and remote system, you will need two machines to act as your local computer and your remote machine, respectively. These two machines could be virtual private servers, virtual machines, containers, or personal computers as long as they’ve been properly configured.

If you plan to follow this guide using servers, it would be prudent to set them up with administrative users and to configure a firewall on each of them. To set up these servers, follow our guides :

  • Initial Setup Debian 11 Server: Secure and Efficient
  • Initial Setup Ubuntu Server 22.04: Secure and Efficient
  • Initial Setup Rocky Linux 9 Server: Secure and Efficient
  • Initial Setup CentOS 7 Server: Secure and Efficient

Setting Up Rsync on Your Linux

Before delving into using Rsync, ensure it’s available on your Linux distribution. The installation process varies:

CentOS:

sudo yum update
sudo yum install rsync

Rocky Linux

sudo dnf update
sudo dnf install rsync

Debian/Ubuntu

sudo apt update
sudo apt install rsync

OpenSUSE

sudo zypper update
sudo zypper install rsync

Rsync Syntax for Directory Sync

The fundamental syntax of Rsync is as follows:

rsync [optional] [source] [destination]
  • Options: These fine-tune the synchronization process.
  • Source: The directory or file you want to sync.
  • Destination: The target location for synchronization.

There are optional modifiers that function to determine the action of our command. A group of main options from rsync includes:

-rRecursive. Include directories and subdirectories as well as any files contained within the subdirectories.
-aArchive. The complete version from –r, where –a is an alias from group of options: -rlptgoD
Include the recursion option, preserves authorizations, file modification date/time, and group as well as user ownership.
-vVerbose. Displays a list of files that were copied during the sync process.
–deleteDelete, if the destination directory includes a folder or file which is missing from the source directory, delete it (can be done vice versa).
-zCompress the files that we will synchronize so that the file size can be much smaller. Rsync is smart enough to determine which file types need to be compressed or not
–excludeSpecify which file or folder patterns we want to exclude from the sync process.
–includeThe opposite of the –exclude option, it defines a pattern of file or directory names to include in the sync process. Usually, users combine the “option include” with the “option exclude”.
–dry-runOnly shows what process your command will do without actually doing it.
–progressIt displays the Kb transferred, and the Kb/s transfer rate.
Rsync Options (Rsync to Sync Local and Remote)

Syncing Local to Remote

To synchronize a local directory with a remote one, employ the following command structure:

rsync -avz /path/to/local/directory username@remote:/path/to/remote/directory

Replace “/path/to/local/directory” with the source directory on your local system. Replace “username” with your username on the remote system, and “remote:/path/to/remote/directory” with the destination directory on the remote system.

Syncing Remote to Local

Synchronizing a remote directory with a local one is similarly straightforward:

rsync -avz username@remote:/path/to/remote/directory /path/to/local/directory

Replace “username” with your username on the remote system, “remote:/path/to/remote/directory” with the source directory on the remote system, and “/path/to/local/directory” with the destination directory on your local system.

Exclude Files or Directories in Rsync

You can exclude specific files or directories from the synchronization process using the --exclude option. For example, to exclude a directory named “logs” from being synced, modify the command as follows:

rsync -avz --exclude 'logs/' /path/to/local/directory username@remote:/path/to/remote/directory

Preserve File Permissions and Ownership

If you want to preserve file permissions and ownership during the synchronization, you can add the --perms and --owner options to the command:

rsync -avz --perms --owner /path/to/local/directory username@remote:/path/to/remote/directory

Automation Made Easy: Scheduling Sync Tasks with Cron

Cron jobs let you automate Rsync synchronizations:

  • Open the terminal and type crontab -e.
  • Add a line with your desired schedule and Rsync command. For instance, syncing daily at midnight:
0 0 * * * rsync -avz /path/to/local/directory user@remote:/path/to/remote/directory

Ensuring Security in Data Synchronization

When dealing with remote systems, prioritize security. Utilize secure protocols like SSH for encrypted connections to maintain data integrity.

Conclusion

Using Rsync, you can easily sync local and remote directories, allowing for efficient file synchronization between different systems. By following the steps outlined in this guide, you can ensure that your files and directories remain up to date and consistent across multiple locations. Rsync’s versatility and flexibility make it a reliable choice for various synchronization tasks, including backups, data transfers, and mirroring. Experiment with different options and explore additional features of Rsync to tailor the synchronization process according to your specific requirements.

Also Read Our Other Guides :

  • How To Backup Files From Remote Linux VPS Using Rsync Script
  • How To Get Total Inodes and Increase Disk Inode Number in Linux
  • How To Create and Use Swap File on Linux System
  • How To Use Git Version Control on Linux: For Beginner
  • The 40 Most-Used Linux Commands You Should Know
  • 6 Methods To Search For Files By Name In Linux
  • How To Find Hard Disk Drive Information in Linux

Finally, now you have learned How To Use Rsync to Sync Local and Remote Directories in Linux.

Tags: LinuxRsyncSync

If you got help by our tutorials, please buy me a coffee..!

Buy Me a Coffee

Thank you so much for your support!!

Previous Post

How To Install and Configure NFS Server Client on Ubuntu 22.04

Next Post

How To Install RTMP Server with Nginx on CentOS 7

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

RECENT POST

Install and Secure phpMyAdmin on Ubuntu 22.04

How To Install and Secure phpMyAdmin on Ubuntu 22.04

by samm
July 22, 2024
0

Are you ready to take control of your MySQL databases on Ubuntu 22.04? In this step-by-step guide, we'll walk you...

Manage Groups on Linux

A Simple Guide: How To Manage Groups on Linux

by samm
November 12, 2023
0

Are you a Linux enthusiast looking to enhance your system administration skills? One fundamental aspect you should master is how...

Install phpMyAdmin on Rocky Linux 9

How To Install phpMyAdmin on Rocky Linux 9

by samm
November 11, 2023
0

If you're navigating the world of Rocky Linux 9 and looking to streamline your MariaDB or MySQL database management, installing...

Logrotate In Linux

How To Manage Log Files Using Logrotate In Linux

by samm
November 10, 2023
0

Log files are an essential part of any Linux system. They provide valuable insights into the system's activities, helping administrators...

Load More

RECOMMENDED.

Install Redis on Debian

How To Install Redis on Debian 11 Server

October 16, 2023
Secure SSH with Fail2Ban

How To Secure SSH with Fail2Ban on Rocky Linux 9

October 29, 2023
sammlinux sammlinux sammlinux

Related Posts

Manage Groups on Linux
Linux

A Simple Guide: How To Manage Groups on Linux

November 12, 2023
Logrotate In Linux
Linux

How To Manage Log Files Using Logrotate In Linux

November 10, 2023
Check File Size in Linux
Linux

The Easy Ways to Check File Size in Linux

November 10, 2023
Linux server security system administrators
Linux

Best Practices Linux Server Security for System Administrator

November 10, 2023
Load More
Next Post
Install RTMP with Nginx on CentOS

How To Install RTMP Server with Nginx on CentOS 7

  • About Us
  • Disclaimers
  • Privacy Policy
  • Sitemap

© 2023 sammlinux - Learn Today for Lead Tomorrow.

No Result
View All Result
  • Ubuntu
  • Debian
  • Rocky Linux
  • CentOS
  • Linux

© 2023 sammlinux - Learn Today for Lead Tomorrow.