Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use rdiff-backup in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use rdiff-backup in linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Rdiff-backup is a powerful and easy-to-use Python script for local / remote incremental backups for any POSIX operating system, such as Linux, Mac OS X, or Cygwin. It combines the remarkable features of mirrored and incremental backups.

It is worth noting that it retains subdirectories, dev files, hard links, and key file attributes such as permissions, uid/gid ownership, modification time, extended attributes, acl, and resource fork. It works in a bandwidth-efficient mode through pipes, similar to the popular rsync backup tool.

Rdiff-backup backs up a single directory to another directory by using SSH, which means that the data transfer is encrypted and secure. The destination directory (on the remote system) will eventually get a complete copy of the source directory, but additional reverse differences will be stored in a special subdirectory of the destination directory, allowing you to recover files that were lost some time ago.

Dependence

To use rdiff-backup in Linux, you need to install the following software packages on your system:

Python v2.2 or later

Librsync v0.9.7 or later

The pylibacl and pyxattr Python modules are optional, but they are required for POSIX access control list (ACL) and extended attribute support, respectively.

Rdiff-backup-statistics requires Python v2.4 or later.

How to install rdiff-backup in Linux

Important: if you run it over the network, you must install rdiff-backup on both systems, both of which are the same version.

This script already exists in the official repository of mainstream Linux distributions, and you only need to run the following command to install rdiff-backup and its dependencies:

In Debian/Ubuntu

$sudo apt-get update $sudo apt-get install librsync-dev rdiff-backup

In CentOS/RHEL 7

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm # rpm-ivh epel-release-7-9.noarch.rpm # yum install librsync rdiff-backup

In CentOS/RHEL 6

# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm-ivh epel-release-6-8.noarch.rpm # yum install librsync rdiff-backup

In Fedora

# yum install librsync rdiff-backup # dnf install librsync rdiff-backup [Fedora 22 +]

How to use rdiff-backup in Linux

As mentioned earlier, rdiff-backup uses SSH to connect to remote computers on the network, and the default authentication method for SSH is username / password, which usually requires human interaction.

However, to automate tasks such as automatic backups such as scripts, you need to configure to log in to SSH without a password using a SSH key, because the SSH key increases the trust between the two Linux servers to simplify file synchronization or transfer.

After you have set SSH password-less login, you can use the following example to start using the script.

Back up files to different partitions

The following example backs up the / etc folder to the Backup folder of another partition:

$sudo rdiff-backup / etc / media/aaronkilik/Data/Backup/mint_etc.backup

Back up files to different partitions

To exclude a specific folder and its subdirectories, you can use the-- exclude option as follows:

$sudo rdiff-backup-- exclude / etc/cockpit-- exclude / etc/bluetooth / media/aaronkilik/Data/Backup/mint_etc.backup

We can use the following-- include-special-files contains all device files, fifo files, socket files, and linked files:

$sudo rdiff-backup-- include-special-files-- exclude / etc/cockpit / media/aaronkilik/Data/Backup/mint_etc.backup

There are two other important flags for selecting files,-- max-file-size is used to exclude files larger than a given byte size, and-- min-file-size is used to exclude files that are smaller than a given byte size:

$sudo rdiff-backup-- max-file-size 5m-- include-special-files-- exclude / etc/cockpit / media/aaronkilik/Data/Backup/mint_etc.backup

Back up remote files on the local Linux server

To do this, we use:

Remote Server (tecmint): 192.168.56.102 Local Backup Server (backup): 192.168.56.10

As mentioned earlier, you must install the same version of rdiff-backup on both machines, as shown below, try checking the version on both machines:

$rdiff-backup-V

Check the rdiff version in the server

In the backup server, create a directory where backup files are stored like this:

# mkdir-p / backups

Now in the backup server, run the following command to back up / var/log/ and / root from the remote Linux server 192.168.56.102 to / backups:

# rdiff-backup root@192.168.56.102::/var/log/ / backups/192.168.56.102_logs.backup # rdiff-backup root@192.168.56.102::/root/ / backups/192.168.56.102_rootfiles.backup

The following screenshot shows the root folder in the remote server 192.168.56.102 and the backed up files in the 192.168.56.10 backup server:

Back up the remote directory on the local server

Notice the rdiff-backup-data folder created in the "backup" directory in the screenshot, which contains important data about the backup process and incremental files.

Rdiff-backup-backup process files

Now, in the 192.168.56.102 server, additional files have been added to the root directory shown below:

Verify the backup directory

Let's run the backup command again to get the changed data, and we can set the detailed function using the-v [0-9] option (where the number specifies the level of detail, the default is 3, which is silent mode):

# rdiff-backup-v4 root@192.168.56.102::/root/ / backups/192.168.56.102_rootfiles.backup

Incremental backup with summary

To list the number and date of some incremental backups contained in the / backups/192.168.56.102_rootfiles.backup directory, we can run:

# rdiff-backup-l / backups/192.168.56.102_rootfiles.backup/

Automatic rdiff-back backup using cron

After a successful backup using-- print-statistics, we can print summary statistics. However, if we do not set this option, we can still get it from the session statistics. Read more about this option in the STATISTICS section of the man page.

The-remote-schema option enables us to specify an alternative way to connect to the remote computer.

Now, let's create a backup.sh script on the backup server 192.168.56.10, as follows:

# cd ~ / bin # vi backup.sh

Add the following line to the script.

#! / bin/bash # This is a rdiff-backup utility backup script # Backup command rdiff-backup-print-statistics-remote-schema 'ssh-C% s "sudo / usr/bin/rdiff-backup-server-restrict-read-only /"' root@192.168.56.102::/var/logs / backups/192.168.56.102_logs.back # Checking rdiff-backup command success/error status=$? If [$status! = 0]; then # append error message in ~ / backup.log file echo "rdiff-backup exit Code: $status-Command Unsuccessful" > > ~ / backup.log; exit 1; fi # Remove incremental backup files older than one month rdiff-backup-- force-- remove-older-than 1m / backups/192.168.56.102_logs.back

Save the file and exit, and then run the following command to add this script to crontab on server 192.168.56.10:

# crontab-e

Add this line to run your backup script at midnight every day:

0 * / root/bin/backup.sh > / dev/null 2 > & 1

Save crontab and exit, and now we have successfully automated the backup process. Make sure everything works as expected.

Read the rdiff-backup man page for more information, detailed usage options, and examples:

# man rdiff-backup Thank you for reading this article carefully. I hope the article "how to use rdiff-backup in linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report