Linux

Backup Files in Linux using Rsync Command Line

linux rsync  stands for remote sync which was written by Andrew Tridgell and Paul Mackerras back in 1996. It’s one of the most used and power ‘tools’ in the UNIX world and almost a standard for syncing data. Most Linux distributions have rsync pre-installed, but if it’s not there you can install the ‘rsync’ package for your distribution.

What is Rsync

Rsync is an extremely powerful tool and does more than just make copies of your files on your system. it also synchronize files on two directories on the same Server; or synchronize files and/or directories on two different systems on the same network.

Advantages and features of Rsync command

  • rsync faster than scp (Secure Copy) ,because rsync uses remote-update protocol which allows to transfer just the differences between two sets of files. First time rysnc copies the whole content of a file or a directory from source to destination then the next time rsync copies only the changed blocks and bytes to the destination.
  • Rsync consumes less bandwidth because it uses compression and decompression method while sending and receiving data both ends.
  • Rsync Supports copying links, devices, owners, groups and permissions.
  • its support remote copy.

Install rsync in Linux

For Red Hat and Centos
    
     yum install rsync
    
   
On Debian based systems
    
     apt-get install rsync
    
   

The basic syntax of rsync

rsync option Source-Directory Destination-Directory

Common linux rsync options command

  • -v : verbose
  • -r : copies data recursively (but don’t preserve timestamps and permission while transferring data).
  • -a : archive mode, archive mode allows copying files recursively .
  • -z : Saves bandwidth over the network, by compress file data
  • -h : human-readable, output numbers in a human-readable format
  • -P : for partial progress.
  • -e : To specify protocol name you want to use,for example if you are going to use the rsync with ssh protocol to backup or copy data remotely.

Use of –– delete Option :

If you have two sets of directories synced with each other. AND some files or directories deleted ,and you need to be sure that those files or folders will be delete on the destination as well? You need to use the ‘- – delete’ option which will take care of such cases.The command becomes:
    
     rsync -a –-delete Source Destination
    
   

How to sync directories (remotely) over network

ssh protocol help you to backup remotely. Use the following syntax to sync a remote directory with a local directory: Please note that you have to choose option -e to use ssh protocol.
    
     rsync -avzP ––delete -e ssh user@remote-server:source-directory /local-server-destination_directory/
    
   

Automate rsync backup

Now the best benefit and powerful part is to automate backup.
You can achieve this feature by creating cron job on Linux OS.
Run ‘crontab -e’ to create cron jobs. It will open an empty file where you can configure the command that you want to run at a desired time.
The format of crontab is quite simple; just pass the five fields followed by your rsync command:

m h dm m dw command

the following will run corn rsync every day at 6.30 PM:

    
     30 18 * * * rsync your-source your-Destination
    
   
XsoftHost Support

Share

Recent Posts

Add Extra IP addresses to server configuration On Ubuntu 17.10 and later

Each failover IP address will need its own line in the configuration file. The configuration…

4 years ago

Create RAID Arrays with mdadm on Ubuntu

What is mdadm? The mdadm utility can be used to create and manage storage arrays…

4 years ago

How to change the maximum upload file size for PHP

There are several scenarios that you might need to increase or decrease your php maximum…

6 years ago

How to install Let’s Encrypt Plugin in WHM/cPanel

What is Let’s Encrypt? Let’s Encrypt is a free certificate authority provided by the Internet…

6 years ago

How to install python in my cPanel and add py extension

Python normally installed on all cPanel hosting server because most of Centos/red hat update system…

6 years ago

How to install and enable GUI GNOME Desktop on centos 7

Usually CentOS 7 comes in a numbers of variants, For most users, there are two…

6 years ago