Operations 7 min read

Master Incremental Backups with rsync: Local, Remote, and Automated Solutions

Learn how to use rsync for efficient incremental backups, covering basic local and remote synchronization, scheduling with cron, advanced options like file exclusion and bandwidth limiting, and practical examples such as website and database backups, all with clear command-line instructions.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Incremental Backups with rsync: Local, Remote, and Automated Solutions

Introduction

File backup is a critical task in system administration, and as data volumes grow, full backups become time‑consuming and storage‑intensive. rsync provides an efficient solution by copying only the parts of files that have changed, enabling fast incremental backups.

Basic Usage

1. Local Backup

Synchronize a source directory with a destination on the same machine using the archive and verbose options. rsync -av /path/to/source /path/to/destination The -a flag preserves permissions, timestamps, and other attributes, while -v shows detailed progress.

2. Remote Backup

Combine rsync with SSH to copy files to a remote host. Adding -z compresses the data during transfer.

rsync -avz -e ssh /path/to/source user@remotehost:/path/to/destination

Incremental Backup

Use the -u or --update option so that only newer files are transferred, avoiding overwriting unchanged files.

rsync -avu /path/to/source /path/to/destination

Scheduled Backup

Integrate rsync with cron to run backups automatically at a chosen time. For example, schedule a nightly backup at midnight:

crontab -e
0 0 * * * rsync -av /path/to/source /path/to/destination

Advanced Usage

1. Excluding Files

Skip specific files or directories using --exclude. The pattern below excludes all .log files.

rsync -av --exclude='*.log' /path/to/source /path/to/destination

2. Bandwidth Limiting

Control transfer speed with --bwlimit, useful for remote backups over limited networks.

rsync -av --bwlimit=1000 /path/to/source user@remotehost:/path/to/destination

Practical Cases

1. Automated Website Backup

Back up a website directory nightly to a remote server.

0 0 * * * rsync -avz /var/www/html/ user@remotehost:/backup/website

2. Excluding Unnecessary Files

Exclude temporary files and log directories during backup.

rsync -av --exclude='*.tmp' --exclude='logs/' /path/to/source /path/to/destination

3. Bandwidth‑Limited Backup

Apply a bandwidth cap of 1000 KB/s.

rsync -av --bwlimit=1000 /path/to/source user@remotehost:/path/to/destination

4. Incremental Database Backup

Combine mysqldump with rsync to back up only changed database dumps.

mysqldump -u username -p database_name > /backup/db_backup.sql
rsync -av /backup/db_backup.sql user@remotehost:/backup/

Conclusion

rsync is a powerful and flexible tool for file backup. Its incremental capability saves time and storage while ensuring data integrity. By mastering basic commands, scheduling with cron, and leveraging advanced options such as exclusion patterns and bandwidth limits, you can tailor rsync to a wide range of backup scenarios.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxcronrsyncIncremental Backupbackup automation
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.