deja-dup-team team mailing list archive
-
deja-dup-team team
-
Mailing list archive
-
Message #00544
[Merge] lp:~mterry/deja-dup/midnight-epoch into lp:deja-dup
Michael Terry has proposed merging lp:~mterry/deja-dup/midnight-epoch into lp:deja-dup.
Requested reviews:
Robert Bruce Park (robru)
Related bugs:
Bug #1154920 in Déjà Dup: "Backup schedule should be spread over the day"
https://bugs.launchpad.net/deja-dup/+bug/1154920
For more details, see:
https://code.launchpad.net/~mterry/deja-dup/midnight-epoch/+merge/153457
Spread the backup time love around. We were accidentally starting our "backup day" at midnight UTC, instead of midnight local time.
While fixing this, I added some randomization to spread the load around a little bit more and set the random range from 2-4AM.
I welcome suggestions on adding tests for this. I ended up just adding print statements to make everything was as expected. I miss having Python's mock module available to me at times like these.
If we're unsure of how to test, I guess manual print testing will have to suffice.
--
https://code.launchpad.net/~mterry/deja-dup/midnight-epoch/+merge/153457
Your team Déjà Dup Developers is subscribed to branch lp:deja-dup.
=== modified file 'common/CommonUtils.vala'
--- common/CommonUtils.vala 2013-01-27 21:07:48 +0000
+++ common/CommonUtils.vala 2013-03-14 20:45:33 +0000
@@ -19,6 +19,9 @@
using GLib;
+[CCode (cheader_filename = "unistd.h")]
+extern long gethostid();
+
namespace DejaDup {
public const string INCLUDE_LIST_KEY = "include-list";
@@ -95,12 +98,56 @@
}
}
+uint32 machine_id = 0;
+uint32 get_machine_id()
+{
+ if (machine_id > 0)
+ return machine_id;
+
+ // First try /etc/machine-id, then /var/lib/dbus/machine-id, then hostid
+
+ string machine_string;
+ try {
+ FileUtils.get_contents("/etc/machine-id", out machine_string);
+ }
+ catch (Error e) {}
+
+ if (machine_string == null) {
+ try {
+ FileUtils.get_contents("/var/lib/dbus/machine-id", out machine_string);
+ }
+ catch (Error e) {}
+ }
+
+ if (machine_string != null)
+ machine_id = (uint32)machine_string.to_ulong(null, 16);
+
+ if (machine_id == 0)
+ machine_id = (uint32)gethostid();
+
+ return machine_id;
+}
+
DateTime most_recent_scheduled_date(TimeSpan period)
{
// Compare days between epoch and current days. Mod by period to find
// scheduled dates.
var epoch = new DateTime.from_unix_local(0);
+
+ // Use early-morning local time for the epoch, not true midnight UNIX epoch:
+ // (A) In cases like cloud services or shared servers, it will help to avoid
+ // all users hitting the server at the same time. Hence the local time
+ // and randomization. (LP: #1154920)
+ // (B) Randomizing around 2-4 AM is probably a decent guess as for when to
+ // back up, if the user leaves the machine on and in the absence of more
+ // advanced scheduling support (LP: #479191)
+ // (C) We randomize using machine id as a seed to make our predictions
+ // consistent between calls to this function and runs of deja-dup.
+ var rand = new Rand.with_seed(get_machine_id());
+ var early_hour = (TimeSpan)(rand.double_range(2, 4) * TimeSpan.HOUR);
+ epoch = epoch.add(early_hour - epoch.get_utc_offset());
+
var cur_date = new DateTime.now_local();
var between = cur_date.difference(epoch);
Follow ups