Understanding rsync: Making a Local Copy
RSync is a powerful and versatile tool for synchronizing files and directories between two or more systems. This article will provide a detailed context on rsync, covering key concepts, subtopics, and proper formatting for code blocks.
Preparing the Remote Sync Server
Before sending files, the remote sync server must be prepared. Here's a step-by-step guide:
-
Install rsync on the remote server:
sudo apt-get install rsync -
Secure the connection by generating SSH keys:
ssh-keygen -t rsa -b 4096 -C "[email protected]" -
Copy the public key to the remote server:
ssh-copy-id user@remote_server
Sending Files
After preparing the remote sync server, you can send files using the rsync command. Here's an example:
rsync -avz /path/to/local/files user@remote_server:/path/to/remote/directory
-a: Archive mode (equivalent to-rlptgoD).-v: Verbose output.-z: Compress data during transfer.
Transfer Page
The transfer page shows the progress of the rsync operation. Here's an example:
sending incremental file list
./file1
./file2
sent 1,678 bytes received 47 bytes 1,631.00 bytes/sec
total size is 1,678 speedup is 1.00
Excluding Files
You can exclude specific files or directories from the sync process using the --exclude option:
rsync -avz --exclude="*.txt" /path/to/local/files user@remote_server:/path/to/remote/directory
Schedules
To automate rsync operations, you can use cron jobs. Here's an example of a cron job that syncs files every hour:
0 * * * * rsync -avz /path/to/local/files user@remote_server:/path/to/remote/directory
Summary
- Rsync is a powerful tool for synchronizing files and directories between systems.
- Prepare the remote sync server by installing rsync and securing the connection with SSH keys.
- Send files using the
rsynccommand, specifying local and remote paths. - Use options like
-a,-v, and-zfor archive mode, verbose output, and data compression. - Exclude specific files or directories using the
--excludeoption. - Automate rsync operations using cron jobs.
References