Skybinary

View Categories

1.2.4 Copying Files Between Systems and Creating Backups

1 min read

Transferring files between systems is an essential Linux administration skill. It is required for system backups, file synchronization, and data migration. Linux provides several commands to perform these tasks efficiently. The most commonly used tools are rsync, scp, and nc.


1. rsync (Remote Synchronization) #

rsync is one of the most powerful tools for copying and synchronizing files or directories between local and remote systems. It transfers only the differences between files, which saves both bandwidth and time.

Syntax:

rsync [options] SOURCE DESTINATION

Common Options:

OptionDescription
-aArchive mode; preserves permissions, ownership, timestamps, and symbolic links
-vVerbose mode; displays detailed information during transfer
-zCompress file data during transfer
--progressShows file transfer progress
--backupCreates backups of existing files before overwriting
--deleteRemoves files in the destination that no longer exist in the source

Examples:

  1. Copy files locally: rsync -avz --progress /home/user/docs/ /backup/docs/
  2. Copy files over SSH: rsync -avz --progress user@192.168.1.10:/home/user/docs/ /backup/docs/
  3. Create a synchronized backup: rsync -avz --progress --backup /data/ /backup/data/

This command keeps files synchronized between directories while maintaining backups of modified files.


2. scp (Secure Copy Protocol) #

scp is used for securely transferring files between systems over an SSH connection. It is simpler than rsync but less efficient because it always copies entire files rather than just the changes.

Syntax:

scp [options] SOURCE DESTINATION

Common Options:

OptionDescription
-rRecursively copy directories
-vVerbose mode to show progress
-pPreserve modification times and permissions
-CEnable compression during transfer

Examples:

  1. Copy a file to a remote system: scp file.txt user@192.168.1.10:/home/user/
  2. Copy a directory recursively: scp -r /home/user/docs user@192.168.1.10:/backup/
  3. Copy a file from a remote system to the local machine: scp user@192.168.1.10:/home/user/report.txt /home/localuser/

3. nc (Netcat) #

nc, or Netcat, is a lightweight and versatile tool that can be used to copy files between systems over a TCP connection. It does not use SSH, which makes it faster but less secure. Netcat is often used for quick file transfers within a trusted local network.

Example:

On the receiving system:

nc -l -p 1234 > backup.tar.gz

On the sending system:

cat backup.tar.gz | nc 192.168.1.10 1234

Explanation:

  • The receiving system listens on port 1234 and saves incoming data to backup.tar.gz.
  • The sending system sends the file through a TCP connection to the receiver’s IP address.

Comparison Table #

ToolProtocolSecureResume SupportCommon Use
rsyncSSH/LocalYesYesIncremental backups and file synchronization
scpSSHYesNoSecure file transfers
nc (netcat)TCPNoManualFast transfers on local networks

Summary #

  • rsync is ideal for backups and synchronization, as it transfers only changed data.
  • scp is best for simple, secure file transfers using SSH.
  • nc is useful for quick, manual file transfers in a trusted network environment.
  • Always verify backups after transfer using checksum tools such as sha256sum or md5sum.

Powered by BetterDocs

Leave a Reply

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

Scroll to Top