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?
Rsync can do this function with the
-u or --update
flags.From the rsync man page:
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:
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