Following test structure:
src/
one/
one/
file.txt
two/
file.txt
two/
file.txt
I only want to sync the file /one/two/file.txt.
I tried this but it does not work..
rsync -r --include='/one/two/file.txt' --exclude='*' src/ target/
Is there a reason you're using --include? If it's a single file then rsync /one/two/file.txt /target/ would work.
Have a look at this answer:
How to RSYNC a single file?
If you're trying to send more than one file then you can use this, based on a pattern:
Using Rsync include and exclude options to include directory and file by pattern
Related
I want to use rsync to copy some files from a folder structure and in the new location have the structure modified slightly. Below is what I currently have and what I'm trying to achive
Folders:
Parent/A/1/a,b,c
Parent/A/2/j,k,l
Parent/A/3/x,y,z
Parent/B/1/a1,b1,c1
Parent/B/2/j1,k1,l1
Parent/B/3/x1,y1,z1
In the new location what I want is
Parent/A/x,y,z
Parent/B/x1,y1,z1
what I have is
PathToParent/A/3/x,y,z
PathToParent/B/3/x1,y1,z1
after using the following command sequence
rsync -avzP --exclude=*/1 --exclude=*/2 ../Parent/ remote:../ParentPath/
I can easily work around this issue but I was hoping that rsync had an option to allow me to run this is as a single command.
Thanks in advance!
No, it can't do that transformation.
You can put multiple rsync invocations in a script, however ...
rsync -a Parent/A/3/ remote:../ParentPath/A/
rsync -a Parent/B/3/ remote:../ParentPath/B/
I am on Mac OS.
I have a directory with round about 3000 files and several subdirectories (wordpress installation)
Now I have to find all the files in a similar directory (have to separate master and child installation) that are additional files and have to copy them away into another directory.
I use this command:
$ diff -rq dt-the7 dt-the7-master-from-Yana|grep 'Only in dt-the7'|awk {' print $3 $4 '}|sed 's/:/\//g'|xargs -J {} rsync -av {} neu/
but somehow a certain file 3d.png and a list of other that should be in a subdir of the destination dir are copied into the root dir of the destination.
Any idea why that might be?
It makes no difference whether I use cp, rsync or ditto
You need the -R relative option on your rsync command.
Without this rsync just copies the item referenced rather than the path referenced, so items at the root level are copied as you expected but items in sub-directories are also copied to the root, which is not what you wanted.
With the option rsync takes account of the relative path and recreates it at the destination.
An example with another command might help, consider:
cp A/B.txt C/
that will copy B.txt into C, it does not create a folder A in C which in turn contains the file B.txt. rsync without -R behaves like that cp command, with -R it creates the A directory in C.
HTH
I'm doing an rsync trial where I have two files in the current folder:
share_2014_09_08.tar.gz share_2014_10_08.tar.gz
I want to rsync to a remote folder that contains three older files. I use the command:
rsync -avz --del ./*.tar.gz backups#pc01:/home/backups/monthly/
And the result int the destination folder is:
share_2014_03_05.tar.gz share_2014_09_08.tar.gz share_2014_10_08.tar.gz
As I understand it, this file:
share_2014_03_05.tar.gz
should have been deleted, so my question is what am I doing wrong.
You're passing to rsync a list of files that you want to synchronize. Not existing files are not passed, so delete option has no effects.
If you want to delete files, you'll have to synchronize the parent directory that contained removed files. You can use a include mask to only sync tarballs:
rsync -avz --include "*.tar.gz" --exclude "*" --del . backups#pc01:/home/backups/monthly/
I have some files that are .py and others that are ".txt". Instead of
cp *.py myDir/
cp *.txt myDir/
is there a way to perform this in one line on the command line?
Thanks
Try this:
cp *.{py,txt} myDir/
More info about *nix wildcards you can find here.
When rsync prints out the details of what it did for each file (using one of the verbose flags) it seems to include both files that were updated and files that were not updated. For example a snippet of my output using the -v flag looks like this:
rforms.php is uptodate
robots.txt is uptodate
sorry.html
thankyou.html is uptodate
I'm only interested about the files that were updated. In the above case that's sorry.html. It also prints out directory names as it enters them even if there is no file in that directory that is updated. Is there a way to filter out uptodate files and directories with no updated files from this output?
You can pipe it through grep:
rsync -vv (your other rsync options here) | grep -v 'uptodate'
Rsync's output can be extensively customized, take a look at rsync --info=help; -v is a fairly coarse way to get information from a modern rsync.
In your case, I'm not sure exactly what you consider "updated" to mean. For example, deleted on the receiver too? Only files/dirs, but also pipes and symlinks too? Mod/access times or only content?
As a simple test I suggest you look at: rsync --info=name1 <other opts>.
Here's my take... (work-proven and very happy with it.)
rsync -arzihv --stats --progress \
/media/frank/foo/ \
/mnt/backup_drive/ | grep -E '^[^.]|^$'
The important bit is the -i for itemize.
The grep lets all output lines pass (also any summary as in -h --stats, also empty ones before that, which benefits legibility) except those starting with a dot: These are the ones, that describe unchanged files:
A . means that the item is not being updated (though it
might have attributes that are being modified).