Delete over rsync using ssh is not working - rsync

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/

Related

Rsync with delete option but excluding subfolders

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.

Rsync wont delete files from an external drive

Can someone please tell me why the following command does not delete the extra files on backup2Drive.
Backup1Folder is a folder and backup2Drive is a drive.
rsync -avh --exclude '._*' --delete /Volumes/ext/Backup1Folder/ /Volumes/backup2Drive
you are either missing --delete-excluded or you are skipping the delete step because of previous i/o errors

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

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 filtering

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.

Resources