rsync: Can't turn off recursion
I would like to sync the folder ~/.maxima and all it's *.ini files to another folder, without copying/syncing its' folders/subdirectories. Unfortunatedly when I use rsync it not only updates the *.ini files, but also copies over ~/.maxima's subfolder: binary.
My preamble: Code:
#!/bin/bash So far I've tried: Code:
1) cp -apr --parents ~/.maxima/*.ini ${BKROOT} 1) The cp command works great for the first backup when the directory ${BKROOT} doesn't exist yet, but in case you delete a file you don't need any more in the source folder, using this the next backup won't delete that file from the target directory. 2) Gets rid of old files you don't want, but it ALWAYS copies over the undesirable subfolder "binary". 3) This is nice because it won't copy over anything other than a *.ini file (even folders/directories it doesn't copy), but when you delete an old *.ini file on the source, it won't delete that file on the target. 4) A strength here is that it doesn't copy over that specific directory, but it does still copy over other folders/directories and other files (e.g. text.log, a.txt etc.) Can rsync just sync "*.ini" files while excluding subdirectories/subfolders? Strange how in the rsync man pages there is no "maxdepth=" option. |
Attempt 2 probably wants --stats instead of -stat. If you type -stat with a single dash (and without the final s), rsync interprets this as -s -t -a, and the -a reverses the earlier --no-r.
Now if you try Code:
rsync -Savi -Eu --no-r --stats --delete ~/.maxima ${BKROOT}${HMA} |
Quote:
So I guess it requires a little more work, but perhaps it's a good start. |
results
Quote:
Quote:
Code:
REMOTE=media/a/LG/local; MYHOME=home/a |
ORIGINAL PROBLEM: I would like to sync the folder ~/.maxima and all it's *.ini files to another folder, without copying/syncing its' folders/subdirectories.
Recently I have learned two new rsync options: 1) --exclude/include; 2) --prune-empty-dirs. One can complete the above job with --exclude/include: Method01 Code:
rsync -Sai -Eu --stats --exclude binary --exclude *.txt /${MYHOME}/.maxima /${REMOTE}/${MYHOME} For this small situation method01 works. But what about a more versatile solution for a more complex directory structure containing more types of files? For this we need --prune-empty-dirs: Method02: Code:
$ rsync -Sai -Eu --stats --include *.ini --prune-empty-dirs -f "+ */" -f "- *" /${MYHOME}/.maxima /${REMOTE}/${MYHOME} 3155-3157) The combination of "+ */", "+ *.c", and "- *" would include all directories and C source files but nothing else (see also the --prune-empty-dirs option) 1801-1803) -F option is a shorthand for adding two --filter rules to your command. This worked quite well. The '+' in '-f "+ */"' means include and the '*/' means directories(recursive). In -f "- *", the "-" means exclude and the "*" means any files. But can't --prune itself include *.ini files also? Method03: Code:
$ rsync -Sai -Eu --stats --prune-empty-dirs -f "+ */" -f "+ *.ini" -f "- *" /${MYHOME}/.maxima /${REMOTE}/${MYHOME} But what if I had made some unwanted files on the destination(e.g. text.txt)? rsync's --prune-empty-dirs is also compatible with "--delete"! And remember, we don't need the "--no-r" option, thus no need to slavishly annex "--dirs" after "--delete": METHOD04: Code:
$ rsync -Sai -Eu --stats --delete --prune-empty-dirs -f "+ */" -f "+ *.ini" -f "- *" /${MYHOME}/.maxima /${REMOTE}/${MYHOME} |
All times are GMT -5. The time now is 11:01 PM. |