elfsightSkip to content
Complete Guide to rsync Commands in Linux

Complete Guide to rsync Commands in Linux

Complete Guide to rsync Commands in Linux. rsync is an essential tool for Linux administrators and developers.

With its help, you can perform quick backups, file transfers via SSH, automated synchronizations and many more, all with minimal resource consumption.

Understanding rsync commands and integrating them into your daily processes can significantly improve security and efficiency of data management.

What is rsync?

rsync is a command-line tool in Linux used for synchronizing files and directories between two locations, either locally or remotely.

It is appreciated for its efficiency, as it only transfers modified files, saving time and bandwidth.

Advantages of using rsync

Complete Guide to rsync Commands

1. General syntax of rsync command

rsync [options] source destination

Simple example:

rsync -avh /home/user/documents/ /media/backup/documents/

2. Most commonly used rsync options

  • -a: archive (preserves permissions, symbolic links, times, etc.)
  • -v: verbose (displays process details)
  • -h: human-readable (displays sizes in easy-to-read format)
  • --progress: shows progress of each file
  • --delete: deletes files from destination that no longer exist in source

3. Local synchronization

Command for synchronizing one local folder with another:

rsync -avh --delete /var/www/html/ /backup/html/

4. Transfer via SSH

To copy files between a local server and a remote one:

rsync -avz -e ssh /home/user/ user@192.168.1.10:/backup/

Explanations:

5. Excluding certain files or directories

rsync -av --exclude 'node_modules' --exclude '*.log' /project/ /backup/project/

Files and directories can be excluded using the --exclude syntax.

6. Bidirectional synchronization?

rsync is unidirectional: it synchronizes from source to destination.

For bidirectional synchronization, custom scripts or tools like unison must be used.

7. Scheduling backups with cron

Example of daily backup at 2:00 AM:

0 2 * * * rsync -a /etc/ /backup/etc/

The line is added to the crontab file with the crontab -e command.

8. Checking without making modifications (dry-run)

rsync -avh --dry-run /home/user/ /backup/user/

The --dry-run option shows you what would happen, without actually copying files.

9. Logging rsync operations

rsync -av --log-file=/var/log/rsync.log /data/ /backup/data/

Logs are useful for debugging or auditing.

10. Synchronizing only recently modified files

find /source -type f -mtime -1 -print0 | rsync -av --files-from=- --from0 / /destination/

This example synchronizes only files modified in the last 24 hours.

Special SEO Services – We offer specialized SEO optimization and search engine marketing services. Contact us now!

Previous post
Next article

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top
ROEN