I have this rsync command:
'rsync -va --delete --exclude-from=rsync_exclusions.txt SourceA DestinationB'
rsync_exclusions.txt contains a single line:
#script.sh#
The command runs fine, except the #script.sh# file gets added to the destination.
I tried escaping the file name in the exclusion file so:
/#script.sh/#
which also did not work. Any idea how to exclude this file, without resorting to renaming it without the sharps? Note that other file names in the the same dir get excluded fine with the same command when added to the exclusion file.
Try using [#]script.sh[#] in the excludes file.
Related
I am using rdiff-backup. Really awesome simple powerful backup tool. However I am fighting with wildcard glob patterns. I have this directory structure:
/data/aaa/cache
/data/bbb/cache
/data/ccc/cache
etc....
In each cache directory are original files and cache files. Original files are named simply 1.jpg, 2.png, 3.gif, and so on. Cache files have some string attached to the original filename.
So I want to backup all the /data/*/cache directories, but to include only original files, not the cache files.
I am using this command:
rdiff-backup --exclude **/cache --include **/cache/+([0-9]).+([a-z]) /data /backup
But rdiff-backup returns this and I am lost:
Found interrupted initial backup. Removing...
Fatal Error: Last selection expression:
Command-line include glob: **/cache/+([0-9]).+([a-z])
only specifies that files be included. Because the default is to
include all files, the expression is redundant. Exiting because this
probably isn't what you meant.
You might want to do a two step process:
create a list of all files you want to exclude e.g. with find . -name "**/cache" > excludes.lst
use the list with --exclude-filelist excludes.lst
This way you can avoid fighting with the glob option and you have full control over your excludes
From http://rdiff-backup.nongnu.org/rdiff-backup.1.html :
A given file is excluded by the file selection system exactly
when the first matching file selection condition
specifies that the file be excluded; otherwise the file is included.
...
For instance,
rdiff-backup --include /usr --exclude /usr /usr /backup
is exactly the same as
rdiff-backup /usr /backup
because the include and exclude directives match exactly the same
files, and the --include comes first, giving it precedence.
So, in your case, it is complaining about the final --include because if a file gets there (i.e. it isn't matched by the previous --exclude) it will be included whether or not it matches the --include. That's what the error message was trying to say.
As for how to accomplish your goal...
Assuming you do want to exclude only paths of the form: /data/*/cache/[0-9]*.[a-z][a-z][a-z]?* just specify that:
rdiff-backup --exclude '/data/*/cache/[0-9]*.[a-z][a-z][a-z]?*' --exclude '*' /data /backup
This should work (I haven't tested it).
I am attempting to use rsync to copy files, but I want to not copy hidden files and folders, and there is one ordinary file I want excluded from the file transfer. I believe I am eliminating the hidden folders with the --exclude="./" and I believe I am excluding the hidden file with the --exclude file path option. If I eliminate the --exclude file path option, I don't get any errors, but that file is copied, which I do not want. If I eliminate the --excluude="./" the hidden files are copied, which I do not want either. What am I doing wrong?
mbp:~ username $ rsync —-exclude /Users/username/work/java/textsearch/settings/search_config.properties --exclude=".*/" -avz /Users/username/work/java/ root#remote.local:/usr/local/java/ -n
building file list ... rsync: link_stat "/Users/username/?\#200\#224-exclude" failed: No such file or directory (2)
done
sent 9560 bytes received 20 bytes 6386.67 bytes/sec
total size is 17461760 speedup is 1822.73
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]
1) What is /Users/username/?#200#224-exclude and why is rsync looking for it?
2) How do I get rsync to copy everything except the hidden folders/files and the specified file?
If this is an exact copy of the command line, the "--" in front of exclude is not using the correct characters. Delete this and replace with double minus. What happens is, that rsync doesn't recognize the option, instead searching the user directory for the file "—-exclude"
I am trying to copy files from another user on a server over to my user.
my command is:
cp /Directory/*
cp: target /Directory/file1.txt is not a directory
What is wrong?
I want to copy all files in the "Directory"
Simple answer: You haven't provided a destination, i.e. a target where to put files.
Long answer:
cp needs two or more arguments. All arguments except the last are treated as source, the last is treated as target.
When you write cp /Directory/*, then /Directory/* is expanded to a list of all files in the directory.
Therefore cp tries to copy all files in the directory, except the last one, into the last one. But that one is not a directory, therefore the command fails.
I found that I can use xcopy /s to copy all files that match a wildcard combination in a folder to another location. But this command re-creates the folder structure. I do not want the tree. I need just the files dumped into the destination folder. There are no duplicate files in the source folder.
You can use for command:
for /R %%x in (*.cpp) do copy "%%x" "c:\dest\"
If you want to run it directly from command prompt (not from a batch file) use %x instead of %%x.
For your purpose, instead of using xcopy you should use robocopy:
http://en.wikipedia.org/wiki/Robocopy
http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx
I use an rsync command to sync two directories remote >local
the command is (used in python script)
os.system('rsync --verbose --progress --stats --recursive\
--copy-links --times --include="*/" --include="*good_name*.good_ext*"\
--exclude-from "/myhome/mydir/src/rsync.exclude"\
%s %s'%(remotepath,localpath))
I want to exclude certain directories that has the same files that I also want to include.
I want to include recursively
any_dir_name/any_file_name.good
but I want to exclude any and all files that are in
bad_dir_name/
I used --exclude-from and here is my exclude from file
*
/*.bad_dir_name/
Unfortunately it doesn't work. I suspect it may have something to do with --include="*/" but if I remove it the command doesn't sync any files at all.
I got it. I used -vv to find according to which rule the directory was showing up in the sync list and since rsync supports regular expressions,
I changed my include statement from "*/" to
--include="*[^.bad_dir_name]/"
and all works fine now.