6

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

  • 5
    You can generate a list of potential deletes from the -n (dry run) option. Would that work? – Jos Dec 7 '15 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 '15 at 10:48
  • There is a timestamp of each file - you could also do : rsync -avptr <source> <target> – dschinn1001 Dec 7 '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 7 '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 7 '15 at 16:05
7

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 yesterday

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.