rsync transferring and synchronizing files directories
rsync files folders deploy
Let’s create a testrsync directory and inside it make two other directories.
mkdir foo bar
Generate a large amount of dummy files inside ./foo directory by:
for i in `seq 1 100`;do touch ./foo/file$i;done
We have 100 files in foo directory while in bar still have none.
when we are in testrsync dirctory we can do :
rsync ./foo/* ./bar
to copy all of the files from./foo over to./bar:
Let’s create Zoo directory inside ./foo.
and again run the above command. It won’t be transferred.
We need to use the -r flag (–recursive) to traverse the directory, transferring every file inside:
rsync -r ./foo/ ./bar
Create a symlink to one file in ./foo,
ln -s file99 file999
and then use rsync to recursively copy all files:
We see that rsync has omitted the symlink we created.
This time use the -a flag:
rsync -a ./foo/ ./bar
There are flags to preserve permissions, ownerships, groups, symlinks, and so on. Because these flags are so often used, the -a (–archive) flag acts as an alias to incorporate them all, including -r.
So the -a (–archive) flag is an alias for a collection of other flags,
-a is equal to all -rltpgoD , each flag does the following:
r - Recursive
l - Transfer any symlinks encountered
t - Preserve time stamps
p - Preserve permissions
g -Preserve groups
o -Preserve ownership
D - Preserve block and character devices
You may want to add the following to your command for easier to read file sizes:
h — Human-readable format of file sizes
v (–verbose) flag will give you more output about the state of the transfer, including a summary at the end, which will look something like this:
q (–quiet) will suppress all output, which can be used for scripts when feedback is not required.
rsync comes with a large list of available options:
Exclude files based on a pattern. Rsync doesn’t support regex yet, so only standard file matching and globbing work
Exclude files listed in a line-separated file
Update files at the destination ONLY if the source copy has been modified more recently
Delete files on the destination ONLY if the source copy no longer exists.