Kiến Thức Linux Linux Căn Bản

How to Backups Using Rsync Incremental

congdonglinux-rsyunc-increamental

Introduction

Data backup is a critical aspect of data management, ensuring the safety and availability of important information. Incremental backups, which only capture changes made since the last backup, offer an efficient and space-saving approach. In the Linux environment, the powerful file synchronization utility called Rsync provides a flexible and reliable solution for creating incremental backups. In this blog post, we will explore how to create incremental backups using Rsync on Linux, specifically focusing on the utilization of the “–backup” and “–backup-dir” options for enhanced data protection.

congdonglinux-rsyunc-increamental

Step 1: Installing Rsync

First, ensure that Rsync is installed on your Linux system. Most Linux distributions come with Rsync pre-installed, but if not, you can easily install it using your distribution’s package manager. For example, on Ubuntu or Debian, you can run the following command in the terminal:

sudo apt-get install rsync

Step 2: Identifying Source and Destination

Next, identify the source directory that you want to back up and the destination directory where you want to store the backups. It is recommended to use a separate external storage device or a remote server as the destination to maintain data redundancy.

Step 3: Initiating the Initial Backup

To perform the initial backup using Rsync, execute the following command:

rsync -avz --backup --backup-dir=/path/to/backup/dir/ /path/to/source/ /path/to/destination/

Replace “/path/to/backup/dir/” with the directory path where you want to store the backup copies. This command initiates the initial backup and creates backup copies of any files that are modified or deleted during subsequent backups.

Step 4: Creating Incremental Backups

For subsequent incremental backups, you can use the same command as in Step 3:

rsync -avz --backup --backup-dir=/path/to/backup/dir/ /path/to/source/    /path/to/destination/

Rsync will compare the source and destination directories, and any modified or deleted files will be backed up and stored in the backup directory specified by “–backup-dir”. The original files in the destination directory will be replaced with the updated versions from the source directory.

example:

sudo mkdir -p /opt/destination/full
sudo mkdir -p /opt/destination/increment
#!/bin/bash
# Path to folder for backups
dest=/opt/destination
# Source server IP address
ip=10.5.5.10
# Rsync user on source server
user=backup-user
# The resource we configured in the /etc/rsyncd.conf file on the source server
src=data
# Set the retention period for incremental backups in days
retention=30

# Start the backup process
rsync -a --delete --password-file=/etc/rsyncd.passwd ${user}@${ip}::${src} ${dest}/full/ 
--backup --backup-dir=${dest}/increment/`date +%Y-%m-%d`/

# Clean up incremental archives older than the specified retention period
find ${dest}/increment/ -mindepth 1 -maxdepth 2 -type d -mtime +${retention} -exec rm -rf {} \;

Step 5: Restoring from Backups

To restore files from a specific backup, you can copy them back from the backup directory to the desired location. Additionally, the “–backup-dir” option allows you to have a complete history of backups, providing an added layer of protection and recovery options.

Conclusion

Creating incremental backups using Rsync on Linux with the “–backup” and “–backup-dir” options is a powerful and efficient method to safeguard your data. By capturing only the changes made since the last backup, Rsync minimizes backup time and optimizes storage usage. With the ability to restore from specific backups and maintain a backup history, you gain increased data protection and flexibility.

Regularly performing incremental backups is crucial for maintaining the integrity and availability of your important files. By implementing Rsync on Linux and following the steps outlined in this blog post, you can establish a robust backup system that ensures the safety of your valuable data.

Remember, data loss can occur unexpectedly, but with Rsync’s incremental backup capabilities, you can have peace of mind knowing that your data is protected and easily recoverable. Start implementing Rsync today and elevate your data backup strategy to new heights.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !