How to use rsync for data backup under Linux

  
        

For all organizations and companies, data is the most important to them, and even for e-commerce, data is just as important. Rsync is a tool/software that backs up important data over the network. It is also a network protocol for synchronizing folders and files between systems over a network on Unix-like and Window-based systems. Rsync can copy or display directories and copy files. By default, Rsync listens on TCP port 873 and copies files through remote shells such as rsh and ssh. Rsync must be installed on both remote and local systems.

main benefits

rsync is:

Speed: initially will copy all the content between the local and remote. Next time, only the block or byte that changed is transmitted.

Security: Transport can encrypt data via the ssh protocol.

Low bandwidth: rsync can compress and decompress data blocks at both ends.

Syntax:

  1. #rsysnc [options] source path destination path

    Examples: 1 - Enable compression
    1. [root@localhost /]# rsync -zvr /home/aloft//backuphomedir
    2. building file list ... done
    3. .bash_logout
    4. .bash_profile< Br>
    5. .bashrc
    6. sent 472 bytes received 86 bytes 1116.00 bytes/sec
    7. total size is 324 speedup is 0.58

      The above rsync command is used -z to enable compression, -v is visualization, and -r is recursive. The above is synchronized between the local /home/aloft/and /backuphomedir.
      Example: 2 - Keep properties of files and folders

      1. [root@localhost /]# rsync -azvr /home/aloft//backuphomedir
      2. building File list ... done
      3. ./
      4. .bash_logout
      5. .bash_profile
      6. .bashrc

      7. Sent 514 bytes received 92 bytes 1212.00 bytes/sec
      8. total size is 324 speedup is 0.53

        Above we used the -a option, which preserves the owner and group, time Stamp, soft link, permissions, and run in recursive mode.
        Example: 3 - Synchronous local to remote host

        1. root@localhost /]# rsync -avz /home/aloft/[email protected]:192.168.1.4:/share /rsysnctest/
        2. Password:

        3. building file list ... done
        4. ./
        5. .bash_logout
          < Li> .bash_profile
        6. .bashrc
        7. sent 514 bytes received 92 bytes 1212.00 bytes/sec
        8. total size is 324 speedup is 0.53

          The above command allows you to synchronize between local and remote machines. You can see that you are prompted to enter a password when synchronizing files to another system. When doing remote synchronization, you need to specify the username and IP or hostname of the remote system.
          Example: 4 - Remote sync to local

          1. [root@localhost /]# rsync -avz [email protected]:192.168.1.4:/share/rsysnctest//home /aloft/
          2. Password:
          3. building file list ... done
          4. ./
          5. .bash_logout
          6. .bash_profile
          7. .bashrc
          8. sent 514 bytes received 92 bytes 1212.00 bytes/sec
          9. total size is 324 speedup is 0.53

            The above command synchronizes remote files Go to the local.
            Example: 5 - Find differences between files

            1. [root@localhost backuphomedir]# rsync -avzi /backuphomedir /home/aloft/
            2. building file List ... done
            3. cd+++++++ backuphomedir/
            4. >f+++++++ backuphomedir/.bash_logout
            5. >f+++++++ backuphomedir/.bash_profile
            6. >f+++++++ backuphomedir /.bashrc
            7. >f+++++++ backuphomedir/abc
            8. >f+++++++ backuphomedir/xyz

            9. sent 650 bytes received 136 bytes 1572.00 bytes/sec< Br>
            10. total size is 324 speedup is 0.41

              The above command helps you find out the difference between a source or destination file or directory.
              Example: 6 - Backup

              The rsync command can be used to back up linux.

              You can use rsync to schedule backups in cron.

              1. 0 0 * * * /usr/local/sbin/bkpscript &> /dev/null

                1. vi /Usr/local/sbin/bkpscript

                2. rsync -avz -e ‘ssh -p2093′ /home/test/[email protected]:/oracle/data/
                  < Br>
Copyright © Windows knowledge All Rights Reserved