Tuesday, January 4, 2011

When rsyncs go wrong

Ok, so a few days ago I wanted to sync some photos between by laptop and my desktop. My desktop has my entire photo collection and I have a subset of that on my laptop. I frequently sync directories between the two using rsync. The desktop doubles as a backup, the files are on a RAID1 array for redundancy -- of course that isn't enough to be safe, and yes, I found out.

The directory structure is very simple, I've set it up as

yyyy/mm/dd-short-description-of-shoot

with yyyy the year, mm the month and dd the day of the month.

After having done some editing in the current month on my laptop, I wanted to sync it to my desktop.

I have a small script that uses rsync to synchronize the current working directory from my laptop to my desktop. I had deleted some bad photo's and obviously wanted them removed from the desktop as well. So I gave the script the --delete flag, which it handed over to rsync.

I ran the script and was greeted by screenfulls of lines saying deleted xxx or yyy. Hmm, I didn't delete that much pictures. I glance at the files that are being deleted, hmm, wait a minute, those aren't the right ... AAAAAH!

^C^C^C^C^C^C^C^C^C^C^C^C^C

FUUUUUCK! I'm bashing CTRL-C for my life here! Finally it kills itself and gives me a shell prompt. I look at the current working directory:

2010/

That should of course have been

2010/12/

And as I said, I don't have a full mirror of all the photos on my laptop (not enough hard disk space there), so it started pruning all the older ones from my desktop. Ouch.

I've shut down the desktop asap and haven't booted it since. I'm probably going to try my luck with extundelete after the exams. Fingers crossed.

TL;DR Be careful with the --delete flag in rsync. It will fuck you up sooner or later!

Update

1 comment:

  1. If it helps, I tried extundelete yesterday, just after remounting the volume as read only, and extundelete managed to recover almost all my files.

    I say almost because it didn't find all the files by itself, so I had to explicitly tell it to recover files that I KNEW were deleted but didn't show up - and those were recovered ok. But I couldn't remember all the file names...

    ReplyDelete