8

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?

8

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.

| improve this answer | |
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.