diff --git a/examples/main.c b/examples/main.c
index 03ae3dec854b1f415442351e8cc3c006e6ce2891..4eefe2a6b79767c00f6a8ea6c912159e2b219eaf 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -1275,8 +1275,17 @@ int main(int argc, char *argv[]) {
 
     /* Also if using nsteps to exit, will not have saved any restarts on exit,
      * make sure we do that (useful in testing only). */
-    if (force_stop || (e.restart_onexit && e.step - 1 == nsteps))
-      engine_dump_restarts(&e, 0, 1);
+    if (force_stop || (e.restart_onexit && e.step - 1 == nsteps)) {
+
+      /* Check whether we dumped snapshots/stats/groups and hence do not
+         need to drift (as we might drift to the past) */
+      int drifted_all = 0;
+      drifted_all |= (e.step_props & engine_step_prop_snapshot);
+      drifted_all |= (e.step_props & engine_step_prop_statistics);
+      drifted_all |= (e.step_props & engine_step_prop_stf);
+
+      engine_dump_restarts(&e, drifted_all, /*force=*/1);
+    }
 
     /* Dump the task data using the given frequency. */
     if (dump_tasks && (dump_tasks == 1 || j % dump_tasks == 1)) {
diff --git a/src/engine.c b/src/engine.c
index 700c287011cd350851fa8379255234d385cb9d73..32190ecdbf9636f5dea06d3175dd0375d2adf7af 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -2352,7 +2352,8 @@ void engine_step(struct engine *e) {
   /********************************************************/
 
   /* Create a restart file if needed. */
-  engine_dump_restarts(e, 0, e->restart_onexit && engine_is_done(e));
+  engine_dump_restarts(e, /*drifted_all=*/0,
+                       e->restart_onexit && engine_is_done(e));
 
   engine_check_for_dumps(e);