rsync read from multiple list of files - rsync

To copy from a list, I can this
rsync -av --files-from=/pathtofolder/file1.txt rootdir destdir
but what if I have multiples list of files (file1.txt, file2.txt, etc) that has to be rsync'ed. For example none of the wildcard work
rsync -av --files-from=/pathtofolder/*.txt rootdir destdir
rsync -av --files-from=/pathtofolder/* rootdir destdir
this one works but I have to write every file name
rsync -av --files-from=/pathtofolder/{file1.txt,file2.txt,file3.txt} rooter destdir
How to do this?

You might try to create virtual file with concatenation of all the files you want to rsync:
rsync -av --files-from=<(cat /pathtofolder/*.txt) rootdir destdir

Related

MacOS: xargs cp does not copy subdirectories

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

Cannot get rsync to ignore my git folder and my todo file

I'm uploading a web page to my server and I simply want the rsync to ignore 3 things: The .git/ folder, my .gitignore file and my TODO. I have tried serveral formats. My latest command being:
rsync -avz --include "*" --exclude .git/ --exclude .gitignore --exclude TODO --del ariela#pc01:/home/web/taskadmin /home/web/tests/
However the all the unwanted files are still being copied. I don't understand. What am I doing wrong?
All files are included by default. Simply exclude those you don't want to be copied
rsync -avz --exclude .git/ --exclude .gitignore --exclude TODO --del ariela#pc01:/home/web/taskadmin /home/web/tests/

Delete over rsync using ssh is not working

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/

How to use rsync --list-only source to list all the files in that directory?

Rsync can be used to list directories in the server as:
rsync --list-only username#servername:/directoryname
This lists the directory with detail information. Is there any option to rsync to list all the files in the directory instead of listing the directory with detailed information?
Simply insert a slash at the end of the command and it will show the folder contents, thus:
rsync --list-only username#servername:/directoryname/

Rsync --link-dest option for single file

I have been using rsync with --link-dest option to backup directories.
I want to achieve the same thing with single files, i.e., I want to copy file srcfile to dstfile knowing that I have a previous version of the file named prevfile in destfile directory.
For directories I use: rsync -a --link-dest=prevdir srcdir dstdir
However link-dest can only take directory values. It cannot take files. I would like to do something like: rsync -a --link-dest=prevfile srcfile dstfile
It's a pity this doesn't work--I agree it would be very useful. But all you have to do to simulate it is make the link yourself:
ln prevfile dstfile
rsync -a srcfile dstfile
By the way, I filed this as a bug: https://bugzilla.samba.org/show_bug.cgi?id=8594

Resources