13

I use rsync to create backups on an external hard drive. I usually run a dry-run first just to sanity check. Specifically, I will use

rsync -auvn path/to/source path/to/dest

However this prints all directories recursed into, regardless of whether or not it or any of its files need to be copied. Since I am backing up a large structure of files, this prints our hundreds of directories, and usually there are only a couple files that need to be copied. Thus this output is not ideal and requires me to dig through hundreds of lines of needless output to actually do my sanity check.

I would love to be able to tell it to print only the actual operations to be performed. My current workaround is to | grep '\.', but obviously this isn't a perfect filter.

Is there any way to get rsync's dry-run mode to not print out directories?

5 Answers 5

1

My solution is this:

rsync -auovin SOURCE_DIR/ DEST_DIR/ |sed '/^.d/d'

The trick is that the i argument will print all lines with extra information at the front. For files, that extra information will begin with .f.. and for directories, that extra information will begin with .d... The sed command will say, for every line in the output beginning with .d, remove it from the output.

13

I often use rsync to synchronise directory structures and like to do a dry run before running the actual command. I too get annoyed by the printing of the directory names so I use grep to filter them out.

One difference between my usage and yours is that I use the --delete option to remove files from the destination directory. Accordingly, I don’t want the grep to filter out lines such as

deleting folderA/
deleting folderA/folderB/

Also, I like to keeps the blank line (^$) for readability so the full pipeline is:

rsync -auvn --delete source_folder destination_folder | grep -E '^deleting|[^/]$|^$'

It’d be great if rsync had a flag for not printing out directory names (it has an option for almost everything else) but in the mean time, this is the best hack I’ve come up with.

5

I had a very similar problem, I was doing a dry-run and it was unnecessarily printing unmodified directories. I found --omit-dir-times (in short -O) which solved this.

3
  • 2
    I had great hopes for this solution, but alas, it made no difference to me using rsync 3.2.3 . Directories are still getting listed even though all has been copied. Commented Jul 18, 2021 at 0:45
  • 1
    What if you try --omit-dir-times --no-perms --no-owner --no-group ? Maybe you need to disable something more. Commented Jul 19, 2021 at 11:41
  • I needed perms, owner, and group. This was a long time ago and I seem to not have the problem anymore. Now using rsync 3.2.7. Commented May 25, 2023 at 4:03
0

I've had this issue as well, and in search for a cleaner solution I landed here.
While Anthony's answer works, here is another alternative that works for me when I know the Parent directory remains the same.

For ex to get the stats for a backup of directory named "foo":

rsync -avP --dry-run --stats --delete foo dest/dir/  | sed '/^foo\/.*\/$/d;'

sed here deletes every line that starts with foo and ends with a / while keeping all the info I need including:

  1. New files that gets transferred/updated
  2. Files that gets deleted
  3. Output of the stats flag
0

Same problem here. My generic workaround is to filter out lines ending with / (directories) as long as the first word contains a / i.e. not "deleting". This would only fail if the top level directory specified on the command line has a space in its name e.g. "My parent dir/source_subdir" as awk would see word one as "My".

rsync -avP --dry-run --stats --delete foo dest/dir/ | awk '!($1~/\// && /\/$/)'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .