NEW VPS PLANS

Experience Ultra-high Performance of NVMe Storage on New UK VPS Plans.

Deploy Instantly
  • +357 2425 0808
  • Login
  • English

Home

Blog

How To Copy or Transfer Files on Linux S...

How To Copy or Transfer Files on Linux Servers with RSync

How To Copy or Transfer Files on Linux Servers with RSync

NetShop ISP

NetShop ISP · Blog Author

Nov 10, 2021 · Dedicated Servers

Nowadays Linux system admins have a lot of tools and options to facilitate the transfer of data and files from and to servers. SSH and FTP are the most popular protocols for data transfer. FTP, in one hand, is popular due to its ease of use but, on the other hand, SSH is far more secure and reliable.

For SSH-based data transfer scp and sftp are two specialized tools used by system admins for many years. However, none of these offer all the features and capabilities that rsync provides.

In this tutorial we will explain how Rsync works and how you can use it for transferring files and folders from and to Linux Servers. In the end of this tutorial you can also find an Rsync Cheat Sheet with explanation of rsync command parameters.

What is RSync

rsync is a utility for efficiently transferring and synchronizing files between computers and servers across local and public networks (source: https://en.wikipedia.org/wiki/Rsync). Rsync stands for “remote sync” and it uses an algorithm that minimizes the amount of data copied by only transferring files which have changed.

How to Install Rsync on Linux Server

To install Rsync on your Linux server, you can use the following commands below according to your Linux distribution:

sudo apt-get install rsync // for Debian/Ubuntu
pacman -S rsync // for Arch Linux
sudo dnf install rsync // for Fedora/CentOS/RHEL and Rocky Linux/AlmaLinux

Example 1: Copy an Entire Directory from Local Server to a Remote Server

Assuming you are connected on a Server A and you wish to transfer an entire directory named public_html which is under “/home” to a Server B (IP: 192.168.1.3), you can use the following command:

rsync -arvzh /home/public_html root@192.168.1.3:/home/

Example 2: Copy a Directory from Remote Server to a Local machine

The following command will help you sync the entire directory /var/backup from a remote server (IP: 192.168.1.3) to a server you are currently connected:

rsync -arvzh root@192.168.1.3:/var/backup /var/

Example 3: Use RSync for Files Transfer between Servers with Custom SSH Port

If you wish to transfer files to a Server which uses a non-standard SSH Port, then you need to supply the rsync command with the -e argument and specify the custom SSH port that the destination server uses. In our example below we assume that the SSH port is 2222, and we are going to transfer the file /home/public_html/index.html.

rsync -avzh -e 'ssh -p 2222' /home/public_html/index.html root@192.168.1.3:/home/public_html/

Example 4: Automatically Delete Files on Source Server after Successful Transfer

In cases when you are initiating data transfer for, lets say, backup purposes you may want to have the files on the originating server deleted after they have been transferred to the backup/destination server.

rsync -avzh --remove-source-files /root/backup.tar.gz root@192.168.1.3:/root/

Example 5: Test RSync Command with Dry Run

If you are not yet familiar with rsync, you may not want to execute commands that may mess up your data on source or destination servers. In this case, rsync provides a wonderful parameter that will not make any real changes but instead will show the output of what your command would do.

rsync -avzh --dry-run /root/backup.tar.gz root@192.168.1.3:/root/

Sample Output:

[root@ubuntu-server:~]# rsync --dry-run --remove-source-files -zvh /root/backup.tar.gz root@192.168.1.3:/root/

root@192.168.1.3's password: 
backup.tar.gz

sent 50 bytes  received 94 bytes  95.15 bytes/sec
total size is 267.30K  speedup is 3,873.97 (DRY RUN)

Rsync Cheat Sheet

Here is a cheat sheet for all rsync’s arguments which you may need to supply in your command for data transfer/sync.

-v–verboseincrease verbosity
-q–quietsuppress non-error messages
–no-motdsuppress daemon-mode MOTD (see caveat)
-c–checksumskip based on checksum, not mod-time & size
-a–archivearchive mode; equals -rlptgoD (no -H,-A,-X)
–no-OPTIONturn off an implied OPTION (e.g., –no-D)
-r–recursiverecurse into directories
-R–relativeuse relative path names
–no-implied-dirsdon’t send implied dirs with –relative
-b, –backupmake backups (see –suffix & –backup-dir)
–backup-dir=DIRmake backups into hierarchy based in DIR
–suffix=SUFFIXbackup suffix (default ~ w/o –backup-dir)
-u–updateskip files that are newer on the receiver
–inplaceupdate destination files in-place
–appendappend data onto shorter files
–append-verify–append w/old data in file checksum
-d–dirstransfer directories without recursing
-l–linkscopy symlinks as symlinks
-L–copy-linkstransform symlink into referent file/dir
–copy-unsafe-linksonly “unsafe” symlinks are transformed
–safe-linksignore symlinks that point outside the tree
-k–copy-dirlinkstransform symlink to dir into referent dir
-K–keep-dirlinkstreat symlinked dir on receiver as dir
-H–hard-linkspreserve hard links
-p–permspreserve permissions
-E–executabilitypreserve executability
–chmod=CHMODaffect file and/or directory permissions
-A–aclspreserve ACLs (implies -p)
-X–xattrspreserve extended attributes
-o–ownerpreserve owner (super-user only)
-g–grouppreserve group
–devicespreserve device files (super-user only)
–specialspreserve special files
-Dsame as –devices –specials
-t–timespreserve modification times
-O–omit-dir-timesomit directories from –times
–superreceiver attempts super-user activities
–fake-superstore/recover privileged attrs using xattrs
-S, –sparsehandle sparse files efficiently
-n–dry-runperform a trial run with no changes made
-W–whole-filecopy files whole (w/o delta-xfer algorithm)
-x–one-file-systemdon’t cross filesystem boundaries
-B–block-size=SIZEforce a fixed checksum block-size
-e–rsh=COMMANDspecify the remote shell to use
–rsync-path=PROGRAMspecify the rsync to run on remote machine
–existingskip creating new files on receiver
–ignore-existingskip updating files that exist on receiver
–remove-source-filessender removes synchronized files (non-dir)
–delan alias for –delete-during
–deletedelete extraneous files from dest dirs
–delete-beforereceiver deletes before transfer, not during
–delete-duringreceiver deletes during the transfer
–delete-delayfind deletions during, delete after
–delete-afterreceiver deletes after transfer, not during
–delete-excludedalso delete excluded files from dest dirs
–ignore-errorsdelete even if there are I/O errors
–forceforce deletion of dirs even if not empty
–max-delete=NUMdon’t delete more than NUM files
–max-size=SIZEdon’t transfer any file larger than SIZE
–min-size=SIZEdon’t transfer any file smaller than SIZE
–partialkeep partially transferred files
–partial-dir=DIRput a partially transferred file into DIR
–delay-updatesput all updated files into place at end
-m–prune-empty-dirsprune empty directory chains from file-list
–numeric-idsdon’t map uid/gid values by user/group name
–timeout=SECONDSset I/O timeout in seconds
–contimeout=SECONDSset daemon connection timeout in seconds
-I–ignore-timesdon’t skip files that match size and time
–size-onlyskip files that match in size
–modify-window=NUMcompare mod-times with reduced accuracy
-T–temp-dir=DIRcreate temporary files in directory DIR
-y–fuzzyfind similar file for basis if no dest file
–compare-dest=DIRalso compare received files relative to DIR
–copy-dest=DIR… and include copies of unchanged files
–link-dest=DIRhardlink to files in DIR when unchanged
-z–compresscompress file data during the transfer
–compress-level=NUMexplicitly set compression level
–skip-compress=LISTskip compressing files with suffix in LIST
-C–cvs-excludeauto-ignore files in the same way CVS does
-f–filter=RULEadd a file-filtering RULE
-Fsame as –filter=’dir-merge /.rsync-filter’

repeated: –filter=’- .rsync-filter’
–exclude=PATTERNexclude files matching PATTERN
–exclude-from=FILEread exclude patterns from FILE
–include=PATTERNdon’t exclude files matching PATTERN
–include-from=FILEread include patterns from FILE
–files-from=FILEread list of source-file names from FILE
-0–from0all *from/filter files are delimited by 0s
-s–protect-argsno space-splitting; wildcard chars only
–address=ADDRESSbind address for outgoing socket to daemon
–port=PORTspecify double-colon alternate port number
–sockopts=OPTIONSspecify custom TCP options
–blocking-iouse blocking I/O for the remote shell
–statsgive some file-transfer stats
-8–8-bit-outputleave high-bit chars unescaped in output
-h–human-readableoutput numbers in a human-readable format
–progressshow progress during transfer
-Psame as –partial –progress
-i, –itemize-changesoutput a change-summary for all updates
–out-format=FORMAToutput updates using the specified FORMAT
–log-file=FILElog what we’re doing to the specified FILE
–log-file-format=FMTlog updates using the specified FMT
–password-file=FILEread daemon-access password from FILE
–list-onlylist the files instead of copying them
–bwlimit=KBPSlimit I/O bandwidth; KBytes per second
–write-batch=FILEwrite a batched update to FILE
–only-write-batch=FILElike –write-batch but w/o updating dest
–read-batch=FILEread a batched update from FILE
–protocol=NUMforce an older protocol version to be used
–iconv=CONVERT_SPECrequest charset conversion of file names
–checksum-seed=NUMset block/file checksum seed (advanced)
-4–ipv4prefer IPv4
-6–ipv6prefer IPv6
–versionprint version number
-h–helpshow help
Press Releases
72

Free VPS Trial

No Credit Card Required.

Recent Posts

How To Migrate from MongoDB Atlas to self-hosted Ubuntu 22.04 Server

How To Migrate from MongoDB Atlas to self-hosted Ubuntu 22.04 Server

15 April, 2024

How NetShop ISP Improves Trading Infrastructure Resilience through Equinix LD7 Data Center Hosting

How NetShop ISP Improves Trading Infrastructure Resilience through Equinix LD7 Data Center Hosting

21 March, 2024

Introducing New Cutting-Edge VPS Plans: OKTAPLUS, HYPER, and TITAN Enhanced with NVMe Technology

Introducing New Cutting-Edge VPS Plans: OKTAPLUS, HYPER, and TITAN Enhanced with NVMe Technology

12 March, 2024

How To Install Let’s Encrypt SSL on Ubuntu Server 22.04 for Apache or Nginx

How To Install Let’s Encrypt SSL on Ubuntu Server 22.04 for Apache or Nginx

04 March, 2024

Navigating Forex Server Hosting: Key Distinctions from Conventional Providers

Navigating Forex Server Hosting: Key Distinctions from Conventional Providers

23 February, 2024

#letushostyou

Award Winning Hosting Provider established in 2004.

120 Faneromenis Avenue, Imperial Tower, 2nd Floor, Larnaca 6031, Cyprus

Products

Bare Metal Servers

Customized Servers

Virtual / Cloud Servers

Forex VPS

Storage VPS

cPanel Web Hosting

Reseller Web Hosting

Colocation

Addons

Premium DNS

Email Hosting

Cloud Backup

DDoS Protection

Licenses

SSL Certificates

Domain Names

Premium SLAs

About Us

Data Center Locations

Looking Glass

Our Company

Contact Us

Careers in Cyprus

Become a Partner

Awards

Certifications

© 2024 S.S. NetShop Internet Services Ltd. All rights reserved.  Terms & Conditions  |  Privacy Policy
CY Reg. Number: HE 217340 | EU VAT Number: CY10217340J

Visa
Mastercard
PayPal
Bitcoin
Tether
Ethereum
Litecoin
Wise
Revolut
Wire Transfer