I have two computers connected to the same home network. I would like to synchronize certain folders between the two. In the past I already used unison for this purpose and I think this could be a good solution. This time I would like to automatize the process, in order not to rely on my memory...
I'm thinking about using cron and the command line version of unison to set up a daily backup. Now, for the synchronization to happen both computers must be on at the same time, which is not always the case.
To solve this problem I thought that a good idea would be to create a small script on one of the two computers (let's call it PC1). The script should do the following operations:
- Check if the other computer (PC2) is on.
- If PC2 is off then do nothing.
- If PC2 is on then check when the last synchronization happened
- If the two PCs synchronized last time less that 24 hours ago (for example) then do nothing.
- If the last synchronization happened more that 24 hours before that execute unison
At that point I can run the script every 10 minutes on PC1. While PC2 is off nothing happens. As soon as PC2 is on, then unison is executed once. If both PC1 and PC2 remains on for a while no sync will take place, unless more than 24 hours pass. I think this should work, at least in theory.
The question is that I don't know how to implement points from 3 to 5. How can I check when last sync happened? Is there another solution to my problem? Please, take into account that I would like not to use cloud storage (huge files to synchronize, speed, etc).
Thanks!