Copy and backup files and folders using the Rsync utility
Rsync is a fast and versatile tool for copying files and folders. The utility can copy data both locally and to other hosts, including Cloud Storage from INTROSERV. The utility options allow you to control many aspects of data copying and mirroring. One useful feature is the ability to compress data during transfer, which can reduce network traffic and improve transfer speed when network bandwidth is the limiting factor. Another advantage is that Rsync avoids transferring files that do not need to be updated. By default, it compares file size and modification time, transferring only files that appear to have changed, which will undoubtedly save time synchronizing large directories.
Why use the -a flag? The -a (archive) option is the most common choice. It enables recursive copying and preserves common file attributes: permissions, ownership, group, modification times, and symbolic links. Because -a already includes recursion, you don't need to add -r separately.
Utility options
Let's look at examples of using Rsync to copy files and directories to remote Cloud Storage from INTROSERV using the SSH protocol.
These commands are universal. Simply replace the destination address and path to sync files with any remote server over SSH.
Let's take a look at some of the main utility options that will be used most often. A more detailed list of available options is available in the man documentation (man rsync command):
-v – display detailed information about the process
-c – check file checksums
-q – minimal information
-a – archiving mode
-R – relative paths
-y – do not overwrite newer files
-b – create a backup copy
-l – copy symlinks
-L – copy contents of links
-H – copy hard links
-g – save group
-p – preserve file permissions
-t – save modification time
-x – work only in this FS
-e – use another transport protocol (for example, ssh)
-z – compress files before transfer
--delete – delete files that are not in the source
--exclude – exclude files
--recursive – enumerate directories recursively
--no-recursive – disable recursion
--progress – display file transfer progress
--stat – show transfer statistics
--max-size – maximum file size for transfer
--bwlimit – speed limit for file transfers
Brief syntax explanation
The trailing slash (/) rule. This is where most users make mistakes: /folder (no slash) copies the folder itself. /folder/ (with slash) copies only the contents of the folder.
rsync -az --progress /home/user/test.file boxxxx@storage_ip:/remote_folder/
-a – archive mode: a recursive copy that preserves file attributes
-z – compresses the data during transfer
--progress – displays transfer progress
/home/user/test.file – this is the path to the file and the actual file itself that needs to be transferred
boxxxx@storage_ip: – this is the destination resource (in our example it is cloud storage, but it can also be a remote server). boxxxx is the user name, after the sign @ is the resource name or IP address of the remote server
/remote_folder/ – this is a folder on a remote resource. In our example, in INTROSERV Cloud Storage.
Copy one file to a folder on a remote storage
rsync -az --progress /home/user/Desktop/test.file boxxxx@storage_ip:/remote_folder/
You will be prompted for a password for connecting to the storage. Enter the password and continue, you will see the progress and file transfer speed.
Copy folder to the folder on a remote storage
Pay attention to the slashes in the source folder and destination folder lines. The absence of a slash in the source folder indicates that we want to transfer the local Desktop folder itself, with all its contents, into the remote_folder folder.
rsync -az --progress /home/user/Desktop boxxxx@storage_ip:/remote_folder/
You will see the directory and all the files inside it being transferred.
Copy the contents of a local folder to a folder on a remote storage
Pay attention to the slash at the end of the source folder. Its presence indicates that the utility should copy the contents of the local folder to a folder on the remote storage.
rsync -az --progress /home/user/Desktop/ boxxxx@storage_ip:/remote_folder/
You will see the progress and copying speed.
Copying a folder from a remote storage to a local server folder
Using Rsync, you can initiate a copy of a folder from a remote storage. The command looks like this::
rsync -az --progress boxxxx@storage_ip:/remote_folder /home/user/Desktop/
You will see the progress and speed of copying a remote folder to a folder on the local server.
Copying the contents of a folder from a remote storage to a local server folder
Here it is also worth paying attention to the slash at the end of the source folder path. Its presence indicates that only the contents of the folder need to be copied.
rsync -az --progress boxxxx@storage_ip:/remote_folder/ /home/user/Desktop/
Copying the contents of a folder excluding and/or including files
The utility allows you to explicitly specify which files to transfer and which should be excluded. To do this, use the --include and --exclude options. Rules are processed in order, so an include rule must come before an exclude rule that would otherwise match the same file.
Test with a dry run. Before running a command that modifies or deletes many files, add the -n or --dry-run flag. Rsync will show you exactly what it would do without actually moving or deleting anything.
rsync -az --progress --include='test.file' --exclude='*' /home/user/Desktop/ boxxxx@storage_ip:/remote_folder/
This command transfers test.file and excludes everything else in the source directory. The --exclude='*' rule is what limits the transfer to the single included file, so both options are needed together here.
Copy only files that are different from the files in the destination folder
By default, Rsync decides whether a file needs to be transferred based on its size and modification time. Use the -c option when you want Rsync to compare file contents by checksum instead. This is more reliable when timestamps cannot be trusted, but it is slower, because both sides must read the files to calculate the checksums.
rsync -azc --progress /home/user/Desktop/ boxxxx@storage_ip:/remote_folder/
With -c, Rsync compares the contents of the source and destination files using checksums and transfers only the files whose contents differ.
Using Rsync over SSH with a non-standard SSH port
To transfer files from/to a server with a changed SSH port, use the -e 'ssh -p port_number' option.
The command to copy a file to a server on which the SSH port is changed to 44 will look like this:
rsync -azc --progress -e 'ssh -p 44' /home/user/Desktop/ user@server_ip:/remote_folder/
Security note: Changing the default SSH port can reduce automated scanning and unwanted connection attempts, but it is not a substitute for proper SSH security such as key-based authentication and firewall rules. Always ensure your firewall allows traffic on the port you choose.