10

I synchronise my music collection between:

  • My desktop's RAID10, where I rip CDs and download music to, and
  • The house media centre, which controls audio players around the house

I do this with a very simple, little rsync command:

rsync -av /media/ned/music/ tank:/media/steve/music/

Occasionally I'll delete something on my desktop, or rename it. When I sync again Tank keeps the old copy and this can result in duplicates.

I know there are --delete-{before/after} options but I am very apprehensive about automatic deletions. There is no third backup yet, so if I make a mistake (which I have before) and rsync nukes my "backup" on Tank, I've lost data.

Is there a way to generate a list of potential deletions after a transfer has finished? Ideally rsync would present me the list and give me a [y/N] prompt but I'm more than happy doing this in a separate command (I'll just write a syncmusic script).

7
  • 5
    You can generate a list of potential deletes from the -n (dry run) option. Would that work?
    – Jos
    Dec 7, 2015 at 10:45
  • There are a couple of interesting ides here, ubuntuforums.org/showthread.php?t=1692800, but nothing that does it natively within rsync. Rsync does always precede deleted files with the word 'deleting' which would be an easy grep.
    – Arronical
    Dec 7, 2015 at 10:48
  • There is a timestamp of each file - you could also do : rsync -avptr <source> <target> Dec 7, 2015 at 12:06
  • I like to use the diff -r or I personally like colordiff -r (-r for recursive) . I normally run it after rsync but you could do it before. If you run this - files and subfolders that are present in one folder/system but not in the other will be reported in the output as <file> not present Dec 7, 2015 at 12:47
  • @the_velour_fog That's a bit heavy for this. There are hundreds of thousands of files it'd have to diff. Even generating and transferring the full lists would take a while.
    – Oli
    Dec 7, 2015 at 16:05

2 Answers 2

9

Use the --dry-run option.

rsync -av --delete --dry-run /media/ned/music/ tank:/media/steve/music/ | grep deleting

This prints a list of things rsync would delete if you ran the command without the --dry-run option.

3
  • Found this works, but only with the trailing slashes on the source and destination paths. Weird because rsync still lists files considered without the slashes, have noticed that it's always best to include trailing slashes for rsync - probably in the docs. somewhere ;-) Jan 26, 2020 at 15:05
  • 1
    This answer doesn't work for me, but @blueray's does. Maybe a BSD vs GNU rsync issue? I'm using GNU rsync version 3.1.2 protocol version 31, and rsync -av --delete --dry-run does not output any information about which files will be deleted, whereas rsync -av --delete --dry-run --info=del does include it, and rsync -a --delete --dry-run only prints which files will be deleted, removing the need for the grep deleting in this answer.
    – webb
    Apr 23, 2021 at 9:01
  • This answer doesn't work for me. Here's my command: rsync -av --delete --dry-run --files-from /home/gabriel/.back_up_linux_pc.files_to_include.txt --exclude-from /home/gabriel/.back_up_linux_pc.files_to_exclude.txt / /media/gabriel/Linux_bak/Backups/rsync/Main_Dell_laptop. My rsync --version is rsync version 3.2.7 protocol version 31. Feb 27, 2023 at 1:33
3

What you are actually looking for is:

rsync --dry-run --delete-after -av --info=DEL  /media/ned/music/ tank:/media/steve/music/

If you want to check the progress as well then you can use:

rsync --dry-run --delete-after -av --info=DEL,PROGRESS2  /media/ned/music/ tank:/media/steve/music/
6
  • The old answer already states to use --dry-run. Jan 2, 2021 at 22:57
  • 2
    @WinEunuuchs2Unix I am suggesting to use --info=DEL instead of greping the value. Jan 3, 2021 at 4:20
  • 1
    thanks @blueray, this is exactly what I needed! without --info=DEL, my rsync -av --dry-run lists all the files to be copied, but doesn't say anything about which ones will be deleted, making it impossible to test --delete without --info=DEL. ps: i find that lowercase --info=del and progress2 also work.
    – webb
    Apr 23, 2021 at 8:58
  • 1
    I find that with rsync 3.2.3 I need --info=ALL0,DEL in order to silence other files, but still show the deleted files.
    – chmac
    Sep 17, 2021 at 13:52
  • I have 100000 files in my output. What keywords should I be searching for to see deleted files? I'm searching for deleting, deleted, and remov and am finding nothing. Feb 19, 2023 at 8:54

You must log in to answer this question.

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