How to use Rsync for local and remote transfers

Backing up information can be a tiresome task, sometimes requiring backing up entire disks and finding a method that saves time is always welcome.

Here you will see how to make the process less tiresome with rsync.

Rsync copies files recursive, minding all the the files under the selected folder

It also allows remote transfer data compression.

Let’s start by downloading rsync on Linux, this software allows preserving group and ownership structure of the files and it is used by several backup tools on Linux.

Timeshift Wizard

On Ubuntu, Elementary and Debian based OS run:

$ sudo apt-get install rsync

But how do we use rsync?

If we write down $ rsync –help

we will see many useful functions but let be practical and focus on the utility:

Usage: rsync [OPTION]… SRC [SRC]… DEST for local files or rsync [OPTION]… SRC [SRC]… [USER@]HOST:DEST for remote files -v, --verbose increase verbosity -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X) (preserves ownership, groups, links and more, pretty much equal copy...) -P same as --partial --progress (show progress by file) ﻿ --existing skip creating new files on receiver --ignore-existing skip updating files that already exist on receiver --remove-source-files sender removes synchronized files (non-dirs) --del an alias for --delete-during -e, --rsh=COMMAND specify the remote shell to use -r, --recursive recurse into directories

Examples:

# For local transfers run: $ rsync -avP ~/lab/afolder/normal.txt \ /home/$USER/lab/ (replace the source address accordingly followed by the destination address) --- THIS IS THE OUTPUT: --- sending incremental file list normal.txt 0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/1) sent 104 bytes received 35 bytes 278.00 bytes/sec total size is 0 speedup is 0.00

For remote transfers using ssh connection protocol run:

$ rsync -avPe ~/lab/afolder/normal.txt \ "ssh" $USER@192.168.1.105:/home/$USER/ (replace source address and $USER@IP-ADDRESS:DESTINATION-FOLDER/ accordingly)

Now lets jump into some more advanced options:

Maximum compression for remote transfers:

$ rsync --compress-level=9 -avrPe "ssh" \ ~/lab/afolder/VIDEOS "ssh" $USER@192.168.1.105:/home/$USER/ (This will compress the files to the maximum before remote transfer and decompress afterward on the destination folder. Very useful for remote transfers

Moving files instead of copying?

$ sync --remove-source-files -avrPe "ssh" \ ~/lab/afolder/MOVING-FOLDER "ssh" \ $USER@192.168.1.105:/home/$USER/ (This will remove the files from the source folder after a successful transfer, similar to moving the files)

Liked this post or have suggestions?

Leave a comment!