I had a hard drive nearing capacity (mostly /home). I installed a new larger drive, copied /home over to it and went on with my life.

This was on 5/17/2013. I know it was on 5/17/2013 because I forgot the archive flag when I copied everything, so every file on the server that has not been updated since then is dated 5/17/2013.

I still have the original /home directory (/oldhome) with the correct last-modified dates.

I need a starting point to write a script that would replace each file in /home that is dated 5/17/2013 with the corresponding original file from /oldhome (with the proper date intact). I would only want to replace files dated 5/17/2013, as some files that were present on that date have subsequently been updated and I, of course, want to keep the updated versions of those files.

File count in /oldhome is ~63K

Thoughts on where to begin?


OK. Based on Theophrastus's comment below (thank you), I can start with:

...from inside /home: find -type f -newermt 2013-5-17 ! -newermt 2013-5-18 -print0 | xargs -I % -0 rsync -avzI --dry-run /oldhome% /home%

...which I think might be almost there. The output from find has a leading period which breaks the path in the rsync command (we get /oldhome./directory/filename /home./directory/filename.ext when everything is concatenated. Can I restate find statement somehow to leave off the leading period? The purpose is to identify files in /home with the 5/17/2013 date and replace them with a copy from /oldhome - there are no files in /oldhome dated later than 5/17/2013.

  • Regarding "leave off the leading period": Try change /oldhome% /home% to /oldhome/% /home/% and you should get /oldhome/./directory/filename – hschou Dec 22 '16 at 22:38
  • @Theophrastus: the find command will run just fine without a starting directory, it will just print the contents of the directory from whence it is run. I don't want to find files in /oldhome with a date of 5/17/2013... there aren't any. There are 63K files in /home with that date, though, and I want to replace them all with their properly dated counterparts in /oldhome. – csisia Dec 22 '16 at 23:19
  • @hschou: yes, that actually works... somehow. I'll try it out on a backup data set and see what I didn't think of. – csisia Dec 22 '16 at 23:21

Your Answer

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

Browse other questions tagged or ask your own question.