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).

Oli
  • 293,335
  • 5
    You can generate a list of potential deletes from the -n (dry run) option. Would that work? – Jos Dec 07 '15 at 10:45
  • There are a couple of interesting ides here, http://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 07 '15 at 10:48
  • There is a timestamp of each file - you could also do : rsync -avptr – dschinn1001 Dec 07 '15 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 – the_velour_fog Dec 07 '15 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 07 '15 at 16:05
  • I'm writing a music player that syncs to five locations on 3 devices. Copying files between locations, or just updating time stamps when contents the same took some time to code. Now when deleting music files, it will be a bigger challenge to record the song names and apply the operation the next time another device/location is on-line. For Android phone I actually had to create a shadow database of modification times because Android doesn't keep one. This was to prevent resyncing files that didn't really change. Also oldest modification time is the real one when contents are the same. – WinEunuuchs2Unix Jan 02 '21 at 22:50
  • I find that the accepted answer doesn't work, but I find that @blueray's does. I'm using GNU rsync version 3.1.2 protocol version 31. Can anyone else report their rsync version, whether it's GNU or BSD, and which answer works for them? – webb Apr 23 '21 at 09:09

2 Answers2

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.

  • 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 ;-) – Terry Brown Jan 26 '20 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 '21 at 09: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. – Gabriel Staples Feb 27 '23 at 01: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/
  • The old answer already states to use --dry-run. – WinEunuuchs2Unix Jan 02 '21 at 22:57
  • 2
    @WinEunuuchs2Unix I am suggesting to use --info=DEL instead of greping the value. – Ahmad Ismail Jan 03 '21 at 04: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 '21 at 08: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 '21 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. – Gabriel Staples Feb 19 '23 at 08:54
  • Ok so that was with a dry-run logging to a file with --log-file. Once I made it NOT a dry-run, now it shows some lines that say deleting. I'd like to see that before I remove --dry-run, but none of my dry-runs show that. I'm using the latest version of rsync: 3.2.7 – Gabriel Staples Feb 19 '23 at 09:00