We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 13
2isn016 Reyne (Remote Syne): 10 Practical Examples of Ryne Commandin Unk
Rsync (Remote Sync): 10 Practical Examples of Rsync Command in
Linux
by Tarunika Shrivastava | Published: September 17, 2013 | Last Updated: January 3, 2015
Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators | 4 Free Shell
Scripting eBooks
Rsyne (Remote Syne) is a most commonly used command
for copying andsynchronizing files and directories remotely as well
as locally in Linux/Unixsystems. With the help of rsync command you
can copy and synchronize your data remotely and locally across
directories, across disks and networks, perform data backups and
mirroring between two Linux machines.
ipuhwuw Ieemintcomirsyne-lcal-remote-le-synctrerizaon-commands! ws2isn016 Reyne (Remote Syne): 10 Practical Examples of Ryne Commandin Unk
10 rsync
Commands
For File Synchronize
Reyne Local and Remote File Synchronization
This article explains 10 basic and advanced usage of
the rsyne command to transfer your files remotely and locally
in Linux based machines. You don't need to be root user to
run rsyne command.
Some advantages and features of Rsync
command
«= Itefficiently copies and sync files to or from a remote system,
= Supports copying links, devices, owners, groups and
permissions.
«Its faster than scp (Secure Copy) because rsync uses remote-
update protocol which allows to transfer just the differences
between two sets of files. First time, it copies the whole content of
a ile or a directory from source to destination but from next time, it
copies only the changed blocks and bytes to the destination
= Rsyne consumes less bandwidth as it uses compression and
decompression method while sending and receiving data both
ends
Basic syntax of rsync command
ipuhwuw Ieemintcomirsyne-lcal-remote-le-synctrerizaon-commands! ane2isn016 Reyne (Remote Syne): 10 Practical Examples of Reyne Commandin Unk
[power
Some common options used with rsync
commands
= -v: verbose
= -1: copies data recursively (but don't preserve timestamps and
permission while transferring data
= -a: archive mode, archive mode allows copying files recursively
and it also preserves symbolic links, file permissions, user &
group ownerships and timestamps
= -z: compress file data
= -h: human-readable, output numbers in a human-readable format
Install rsync in your Linux machine
We can install rsyne package with the help of following command
am l Red Hat 7
-3 Debian |
1. Copy/Sync Files and Directory
Locally
Copy/Sync a File on a Local Computer
This following command will sync a single file on a local machine from
one location to another location. Here in this example, a file
name backup.tameeds to be copied or synced to /tmp/backups/ folder.
ipuhwww Ieemin.comirsyne-lcal-remote-le-synctrerizaon-commands! ans2isn016 Reyne (Remote Syne): 10 Practical Examples of Reyne Commandin Unk
In above example, you can see that if the destination is not already
exists rsync will create a directory automatically for destination.
Copy/Sync a Directory on Local Computer
The following command will transfer or sync all the files of from one
directory to a different directory in the same machine. Here in this
example /root/rpmpkgs contains some rpm package files and you want
that directory to be copied inside /tmp/backups! folder
2. Copy/Sync Files and Directory to
ipuhwuw Ieemintcomirsyne-lcal-remote-le-synctrerizaon-commands! ana2isn016 Reyne (Remote Syne): 10 Practical Examples of Ryne Commandin Unk
or From a Server
Copy a Directory from Local Server to a
Remote Server
This command will syne a directory from a local machine to a remote
machine.For example: There is a folder in your local computer
“pmpkgs” which contains some RPM packages and you want that
local directory’s content send to a remote server, you can use
following command.
Copy/Sync a Remote Directory to a Local
Machine
This command will help you sync a remote directory to a local
directory. Here in this example, a
directory /home/tarunika/rpmpkgs which is on a remote server is being
copied in your local computer in /tmp/myrpms
ipuhwuw Ieemintcomirsyne-lcal-remote-le-synctrerizaon-commands!
532isn016 Reyne (Remote Syne): 10 Practical Examples of Reyne Commandin Unk
3. Rsync Over SSH
With rsyne, we can use SSH (Secure Shell) for data transfer,
using SSHprotocol while transferring our data you can be ensured that
your data is being transferred in a secured connection with encryption
so that nobody can read your data while it is being transferred over the
wire on the internet.
Also when we use rsyne we need to provide the user/root password to
accomplish that particular task, so using SSH option will send your
logins in an encrypted manner so that your password will be safe.
Copy a File from a Remote Server to a Local
Server with SSH
To specify a protocol with rsync you need to give *-e" option with
protocol name you want to use. Here in this example, We will be using
“ssh” with -e" option and perform data transfer.
ipuhwuw Ieemintcomirsyne-lcal-remote-le-synctrerizaon-commands!
anReyne (Remote Syne): 10 Practical Examples of Reyne Commandin Unk
Copy a File from a Local Server to a Remote
Server with SSH
4. Show Progress While
Transferring Data with rsync
To show the progress while transferring the data from one machine to
a different machine, we can use ‘-progress’ option for it. It displays the
files and the time remaining to complete the transfer.
ipuhwww Ieemin.comirsyne-lcal-remote-le-synctrerizaon-commands! m32isn016 Reyne (Remote Syne): 10 Practical Examples of Reyne Commandin Unk
5. Use of —include and —-exclude
Options
These two options allows us to include and exclude files by speci
parameters with these option helps us to specify those files or
directories which you want to include in your syne and exclude files
and folders with you don't want to be transferred.
Here in this example, rsync command will include those files and
directory only which starts with ‘R’ and exclude all other files and
ipuhwuw Ieemintcomirsyne-lcal-remote-le-synctrerizaon-commands! ars2isn016 Reyne (Remote Syne): 10 Practical Examples of Ryne Commandin Unk
directory
6. Use of —delete Option
Ifa file or directory not exist at the source, but already exists at the
destination, you might want to delete that existing file/directory at the
target while syncing .
We can use ‘-delete' option to delete files that are not there in source
directory
Source and target are in sync. Now creating new file test txt at the
target
ipuhwww Ieemin.comirsyne-lcal-remote-le-synctrerizaon-commands! a82isn016 Reyne (Remote Syne): 10 Practical Examples of Reyne Commandin Unk
[Sst ts soot crescents |
Target has the new file called test.txt, when synchronize with the
source with “-delete’ option, it removed the file test.txt.
7. Set the Max Size of Files to be
Transferred
You can specify the Max file size to be transferred or sync. You can
do it with “-max-size” option. Here in this example, Max file size
is 200k, so this command will transfer only those files which are equal
or smaller than 200k
ipuhwww Ieemin.comirsyne-lcal-remote-le-synctrerizaon-commands!
soe2isn016 Reyne (Remote Syne): 10 Practical Examples of Reyne Commandin Unk
8. Automatically Delete source
Files after successful Transfer
Now, suppose you have a main web server and a data backup server,
you created a daily backup and synced it with your backup server,
now you don't want to keep that local copy of backup in your web
server.
So, will you wait for transfer to complete and then delete those local
backup file manually? Of Course NO. This automatic deletion can be
done using ‘“remove-sourcesfiles’ option.
9. Do a Dry Run with rsync
If you are a newbie and using rsync and don't know what exactly your
command going do. Rsyne could really mess up the things in your
destination folder and then doing an undo can be a tedious job
ipuhwuw Ieemintcomirsyne-lcal-remote-le-synctrerizaon-commands! waazote Ryne (Remote Syne): 10 Praceal Examples of Reyne Commandin Linx
Use of this option will not make any changes only do a dry run of the
command and shows the output of the command, if the output shows
exactly same you want to do then you can remove ““