How to Use `rsync` for File Synchronization on Arch Linux
rsync
for File Synchronization on Arch LinuxCategories:
5 minute read
In the realm of file synchronization, data backups, and mirroring, one tool stands out for its flexibility, performance, and reliability: rsync
. This powerful command-line utility has become a cornerstone in Linux-based systems for efficient data transfer. Whether you’re syncing directories across systems, backing up important files, or keeping folders in sync in real-time, rsync
has got your back.
In this article, we’ll explore how to use rsync
for file synchronization on Arch Linux, discuss common use cases, and walk through practical examples to help you get started.
What is rsync
?
rsync
is a fast and versatile command-line utility for copying and synchronizing files and directories between two locations. It can sync files locally (on the same machine) or remotely (over SSH or rsync daemons). What makes rsync
so efficient is its ability to perform differential transfers—meaning it only copies the differences between source and destination files.
Key features of rsync
include:
- Delta transfer algorithm (transfers only changed parts of files)
- Compression support during data transfer
- Preserving file permissions, ownership, timestamps, and symbolic links
- Ability to exclude files with patterns
- Sync over SSH or using the rsync daemon
- Verbose and dry-run modes for safer operations
Installing rsync
on Arch Linux
Arch Linux typically provides rsync
out of the box, but if it’s not installed, you can install it easily using pacman
:
sudo pacman -S rsync
Once installed, verify the version and that it’s available:
rsync --version
Basic rsync
Syntax
The general syntax of the rsync
command is:
rsync [options] source destination
Here are some basic options you’ll frequently use:
-a
– Archive mode (recursive copy and preserve permissions, symbolic links, etc.)-v
– Verbose output-z
– Compress file data during the transfer-P
– Show progress and allow resumption of interrupted transfers-e ssh
– Specify SSH as the remote shell
Local File Synchronization
Let’s say you want to sync a local directory /home/user/documents/
to /mnt/backup/documents/
.
rsync -avh /home/user/documents/ /mnt/backup/documents/
Explanation:
-a
enables archive mode.-v
enables verbose output.-h
makes the output human-readable.
Note: The trailing slash /
in the source path is important. If included, rsync
copies contents of the source directory. Without it, it copies the directory itself.
Without Trailing Slash
rsync -avh /home/user/documents /mnt/backup/
This will result in /mnt/backup/documents/
.
With Trailing Slash
rsync -avh /home/user/documents/ /mnt/backup/documents/
This results in only the contents of documents/
being synced.
Remote File Synchronization over SSH
To sync files from your local system to a remote Arch Linux server, you can use rsync
over SSH. Assume your remote username is archadmin
, and the server’s IP is 192.168.1.100
.
rsync -avz -e ssh /home/user/documents/ archadmin@192.168.1.100:/home/archadmin/documents/
You can also sync in the other direction (remote to local):
rsync -avz -e ssh archadmin@192.168.1.100:/home/archadmin/documents/ /home/user/documents/
Adding the -z
option enables compression, which is useful for speeding up transfers over slow connections.
Excluding Files and Directories
rsync
allows you to exclude specific files or directories using the --exclude
option.
rsync -av --exclude 'node_modules' --exclude '*.log' /home/user/project/ /mnt/backup/project/
You can also use an exclude file:
rsync -av --exclude-from='exclude-list.txt' /home/user/project/ /mnt/backup/project/
Contents of exclude-list.txt
:
*.log
node_modules/
*.tmp
Performing a Dry Run
A dry run simulates what rsync
will do, without making any changes. This is very useful for testing.
rsync -av --dry-run /home/user/docs/ /mnt/backup/docs/
Using rsync
for Incremental Backups
Since rsync
only transfers changes, it’s a great choice for incremental backups. You can set up a daily cron job or systemd timer to sync changes regularly.
A typical script might look like this:
#!/bin/bash
rsync -a --delete /home/user/documents/ /mnt/backup/documents/
The --delete
flag ensures that deleted files in the source are also removed from the destination, keeping them perfectly in sync.
Scheduling Regular Syncs with systemd
Instead of cron, Arch Linux users may prefer systemd
timers for scheduling. Here’s how:
Step 1: Create a systemd service file
Create a file at /etc/systemd/system/rsync-backup.service
:
[Unit]
Description=Rsync Documents Backup
[Service]
Type=oneshot
ExecStart=/usr/bin/rsync -a --delete /home/user/documents/ /mnt/backup/documents/
Step 2: Create a systemd timer file
Create /etc/systemd/system/rsync-backup.timer
:
[Unit]
Description=Run rsync backup daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
Enable and start the timer:
sudo systemctl enable --now rsync-backup.timer
You can check its status with:
systemctl list-timers
Syncing Over Rsync Daemon
For more advanced network sync setups, rsync
can run as a daemon, listening for connections. While less common in personal setups, it’s useful for servers.
Here’s a very basic /etc/rsyncd.conf
:
uid = nobody
gid = nobody
use chroot = no
max connections = 4
log file = /var/log/rsyncd.log
timeout = 300
[backup]
path = /srv/rsync/backup
comment = Backup directory
read only = no
auth users = rsyncuser
secrets file = /etc/rsyncd.secrets
And in /etc/rsyncd.secrets
:
rsyncuser:yourpassword
Set correct permissions:
chmod 600 /etc/rsyncd.secrets
Start the daemon:
sudo rsync --daemon
Then sync from a client like this:
rsync rsync://rsyncuser@server_ip/backup
Tips for Secure Usage
- Always prefer SSH (
-e ssh
) for encrypted transfers. - Use SSH keys for automation and enhanced security.
- Avoid using
--delete
without a dry run to prevent accidental data loss. - Use
--checksum
if you want rsync to check file contents, not just mod time and size.
Graphical Frontends
For users who prefer GUI tools, there are a few frontends available for rsync
:
Grsync: A simple GTK-based interface.
Install it via:
sudo pacman -S grsync
It’s helpful for learning the command syntax and testing before automating with scripts.
Conclusion
rsync
is an essential tool in any Arch Linux user’s toolkit. Whether you’re managing a home server, performing daily backups, or syncing files across machines, rsync
provides an efficient, reliable, and secure solution. With options ranging from basic local file copy to advanced remote synchronization, rsync
continues to be a go-to utility for file management.
By mastering its options and leveraging its features, you can ensure your data stays safe, consistent, and well-organized—with minimal effort and maximum control.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.