When pushing to the server from our local machines, we'd like to exclude (or not overwrite) directories used by awstats.
Is it possible to get rsync to replace everything on the server but ignore two symbolic links and a directory?
awstats-icon -> icon
awstatsicons -> icon
/icon
Our current rsync call looks like this where we're excluding .git from our local machines:
rsync -vzrP --delete --exclude '.git' ~/Sites/path/to/sitename/ user#server.com:/path/to/sitename/
Any pointers in the right direction would be much appreciated.
Would it work for you to also exclude the symbolic links and the directory?
rsync -vzrP --delete --exclude '.git' --exclude 'awstats-icon' --exclude 'awstatsicons' --exclude 'icon' ~/Sites/path/to/sitename/ user#server.com:/path/to/sitename/
This would prevent pushing the symbolic links and directory, while preserving (not deleting) the remote symbolic links or directories with the same names.
Related
I need to sync a local directory (destination) from the remote server directory (source) with the --delete option.
I've got this:
Local directory is /home/user/config and into it
removeit.txt
bar.csv
foo.h
config.conf
scripts <- Is a directory
logs <- Is adirectory
The remote directory is config and into it
bar.csv
foo.h
I want in the local directory after rsync
bar.csv
foo.h
config.conf
scripts <- Is a directory
logs <- Is adirectory
I've tested with multiple options but I can't get a entire rsync command with my needs.
rsync -avz --min-size=1 --delete -e "ssh" user#example.com:./config/ ./config --exclude ./config/scripts --exclude ./config/logs --exclude ./config/device.conf --dry-run
With a list of include files
rsync -avz --min-size=1 --include-from=list --exclude=* --delete-excluded -e "ssh" user#example.com:.config/ config/
But nothing works as I expected. The subfolders in the destination are deleted.
The man page for rsync has a section on "Include/Exclude Pattern Rules" which you should review. In particular, it looks like you are using ./ to refer to the directory relative of your shell's working directory which won't work the way you want.
Here is a relevant section of the documentation:
if the pattern starts with a / then it is anchored to a particular
spot in the hierarchy of files, otherwise it is matched against the
end of the pathname. This is similar to a leading ^ in regular
expressions. Thus /foo would match a name of "foo" at either the "root
of the transfer" (for a global rule) or in the merge-file's directory
(for a per-directory rule). An unqualified foo would match a name of
"foo" anywhere in the tree because the algorithm is applied
recursively from the top down; it behaves as if each path component
gets a turn at being the end of the filename. Even the unanchored
"sub/foo" would match at any point in the hierarchy where a "foo" was
found within a directory named "sub". See the section on ANCHORING
INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a
pattern that matches at the root of the transfer.
The pattern you are using might be causing rsync to look for a folder literally called . which contains a file or folder called scripts or whatever.
Try replacing the relative-ish ./config/ part with / in your exclude patterns. That will anchor the pattern in the "root of transfer" which is the directory you are synchronizing. In other words, try this:
rsync -avz --min-size=1 --delete -e "ssh" user#example.com:./config/ ./config --exclude /scripts --exclude /logs --exclude /device.conf --dry-run
I hope that works. If it's not too late to check, please let me know if this worked for you.
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/
Uhoh... issued this command:
rsync -avv --progress --delete "/media/Drive1_/" "/media/Drive2_/Backup/"
Previously, it had been working great and was:
rsync -avv --progress --delete "/media/Drive1_" "/media/Drive2_/Backup/"
But I added a trailing slash. Now, I'm seeing lots of output like this:
deleting /media/Drive1_/pics/pics/somepic.jpg
or
deleting /media/Drive1_/Drive2_backup/pics/somepic.jpg
I believe there should only be one /pic/ directory, but it lists two. Navigating to that path in samba shows the jpg serves up just fine.
I want the trailing slash to be there. Does this output though mean that Rsync deleted content from /media/Drive1_ ?
I believe you have pasted the "previous" command exactly the same as the "new" one but I will assume the previous one did not have the trailing slash.
When you put a trailing slash at the end of a source directory, rsync treats it as a "contents of this directory". So if you do "rsync pics/ otherdir" you put contents of pics into otherdir. If you do "rsync pics otherdir", you would put the directory pics into otherdir.
In the destination directory there is no difference whether you put trailing slash or not. If the directory doesn't exist, it will get created. Depending on the existance of trailing slash after source directory, it will either have contents of source in it or the source directory in it.
Example:
rsync -avv /media/drive/backup/ /media/drive2/backup
is the same as
rsync -avv /media/drive/backup /media/drive2
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/