1

I am trying to write a backup solution, which will take snapshots of a folder using hardlinks and rsync, every hour it will run though its thing, and take the snapshot. I have most of it sorted already, it's just small details that I'm missing.

I'm already planning a system that will clear out old backups depending on how far apart they are, and how old they are in a sort of exponential backoff fashion. It will therefore not take up dramatically much disk space to keep hourly backups. (the age of each backup is divided by the backup one after it...)

I will however be running this on a machine that will regularly have no changes to backup (overnight, when people are on holiday, etc.) and as such, I'd like to take this into account. If only for the purposes of power saving.

Is there any way tell when the last modified time of the entire /home/ directory is?

Perferably without fully traversing the directory, as this would somewhat defeat the point.

Is there any better way to do this?

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
Thingomy
  • 33
  • 7

1 Answers1

1

Rsync can do this function with the -u or --update flags.

From the rsync man page:

-u, --update
              This  forces rsync to skip any files which exist on the destinaâ
              tion and have a modified time that  is  newer  than  the  source
              file.   (If an existing destination file has a modify time equal
              to the source fileâs, it will be updated if the sizes  are  
              different.)

              In  the current implementation of --update, a difference of file
              format between the sender and receiver is always  considered  to
              be important enough for an update, no matter what date is on the
              objects.  In other words, if the source has  a  directory  or  a
              symlink  where  the  destination  has a file, the transfer would
              occur regardless of the timestamps.  This might  change  in  the
              future  (feel free to comment on this on the mailing list if you
              have an opinion).

If you don't want to use rsync I can think of two other ways to get this info. But both ways would require you to drill down through the file system.

First the uglier way:

Use stat stat --format=%y <file> and parse the outputted time. You would have to do some pretty ugly things to get this working right.

Second the slicker way:

use find <path> -mtime -<number_of_days> to get a list of files that have been modified within the number_of_days ago window.


Re: Power saving

This would take some hacking, and wouldn't be 100% reliable - in the sense you might miss something that needs to be backed up. But you can do something like the following and just not run against home drives during certain windows:

if [ `date +%k` -lt 22] && [`date +%k` -gt 8] && [ `date +%u` -le 5 ]
then
     #Set some flags for run control.
fi 

The first date test, checks to see if it is before 10pm, the second after 8am and the last checks that the day of the week is less than or equal to 5 (date +%u outputs day of week from 1-7 with one being Monday, so 6 & 7 are Saturday and Sunday)

As far as holidays, the only thing I can really think of doing is to maintain a file with the day number of the year in it for each holiday then match against date +%j

Zypher
  • 36,995
  • 5
  • 52
  • 95
  • Well that certainly answers part of the problem. I already have the rsync thing wired up as you describe. The find idea though will do wonders for things thouhg. This still does not solve the drive powersaving issues. – Thingomy Feb 06 '10 at 22:16
  • I have confirmed that the mtime on a folder is set if a file within it is deleted. this means that even deletions are picked up by find, this is good. – Thingomy Feb 07 '10 at 14:14
  • Well, no awesome automated powersaving option, but I wasn't holding out much hope that one even existed. Cheers. – Thingomy Feb 09 '10 at 19:40