When you use rsync -a
or rsync --archive
, you're actually activating a combination of several fundamental options that together create a powerful file synchronization behavior. Let's break down what each component does:
-r, --recursive recurse into directories
-l, --links copy symlinks as symlinks
-p, --perms preserve permissions
-t, --times preserve modification times
-g, --group preserve group
-o, --owner preserve owner
-D same as --devices --specials
The archive mode is particularly useful for creating exact copies of directory structures. Here's what each option preserves:
- -r: Copies all files recursively through directories
- -l: Maintains symbolic links instead of following them
- -p: Keeps original file permissions (chmod values)
- -t: Preserves modification timestamps
- -g and -o: Retains group and owner information (requires root privileges)
- -D: Handles special files and devices (--devices preserves device files, --specials preserves special files like named sockets)
Archive mode is ideal for:
# Backup scenario
rsync -a /source/directory/ /backup/location/
# Remote synchronization
rsync -az user@remote:/path/ /local/path/
Note that -a
doesn't include -H
(hard links), -A
(ACLs), or -X
(extended attributes). You need to add these separately if required.
For more complete backups, you might combine archive mode with additional options:
# Archive mode with compression and progress display
rsync -avz --progress source/ destination/
# Preserving hard links and ACLs
rsync -aH source/ destination/
# Including extended attributes (common on macOS)
rsync -aX source/ destination/
When using archive mode:
- Preserving owners/groups typically requires root privileges
- Be cautious when syncing special files and devices
- Consider using
--numeric-ids
when syncing between different systems
If you encounter issues:
# Check what rsync would do (dry run)
rsync -anv source/ destination/
# Verify preserved attributes
ls -l destination/file
Remember that -a
implies --no-implied-dirs
, which can affect directory structure preservation.
The -a
or --archive
flag in rsync is actually a combination of several fundamental options that together create a powerful file synchronization behavior. When you use archive mode, you're essentially activating these options simultaneously:
-r: recursive copy
-l: preserve symlinks
-p: preserve permissions
-t: preserve modification times
-g: preserve group ownership
-o: preserve owner (superuser only)
-D: preserve devices and special files
Let's examine what each of these flags does in practice:
Recursive (-r): Enables directory tree traversal. Without this, rsync would only copy files in the immediate directory.
Preserve symlinks (-l): Maintains symbolic links as links rather than copying the referenced files.
Preserve permissions (-p): Keeps the original file permissions (mode bits).
Preserve timestamps (-t): Maintains the original modification times of files.
Here's how archive mode behaves in different scenarios:
# Basic archive mode usage
rsync -a /source/directory/ /destination/directory/
# Equivalent explicit version
rsync -rlptgoD /source/directory/ /destination/directory/
When dealing with remote systems, archive mode becomes particularly useful:
# Sync to remote server with archive mode
rsync -avz /local/path/ user@remote:/remote/path/
It's important to note that archive mode doesn't include these preservation options:
- -H: preserve hard links
- -A: preserve ACLs
- -X: preserve extended attributes
If you need these features, you'll need to add them explicitly:
rsync -aHAX /source/ /destination/
Archive mode is particularly useful for:
- Creating exact copies of directory structures
- Maintaining file metadata during backups
- Synchronizing web server content
- Migrating user home directories
For example, when backing up a website:
rsync -a --delete /var/www/ /backups/www-$(date +%Y%m%d)/
While archive mode is convenient, it does have some performance implications:
- Preserving all metadata requires additional system calls
- Timestamp comparisons can slow down large transfers
- Ownership preservation requires root privileges
In some cases, you might want to omit certain options for better performance:
# Faster sync without owner/group preservation
rsync -rltD --no-o --no-g /source/ /destination/