Home » Linux » How to RSYNC a single file?

How to RSYNC a single file?

Posted by: admin December 7, 2017 Leave a comment

Questions:

Currently i only RSync-ing the Directories as like:

* * * * * rsync -avz /var/www/public_html/images [email protected]<remote-ip>:/var/www/public_html

So how do i rsync one single file like, /var/www/public_html/.htaccess ?

Answers:

You do it the same way as you would a directory, but you specify the full path to the filename as the source. In your example:

rsync -avz /var/www/public_html/.htaccess [email protected]<remote-ip>:/var/www/public_html/

Questions:
Answers:

Basic syntax

rsync options source destination

Example

rsync -az /var/www/public_html/filename [email protected]<remote-ip>:/var/www/public_html

Read more

Questions:
Answers:

Michael Place’s answer works great if, relative to the root directory for both the source and target, all of the directories in the file’s path already exist.

But what if you want to sync a file with this source path:

/source-root/a/b/file

to a file with the following target path:

/target-root/a/b/file

and the directories a and b don’t exist?

You need to run an rsync command like the following:

rsync -r --include="/a/" --include="/a/b/" --include="/a/b/file" --exclude="*" [source] [target]