anchor.diff:      end,
       mnesia:subscribe(system),
       ?Log("~p started as ~p!~n", [?MODULE, NodeType]),
  +
  +    % backup any existing snapshots and start new snapshoting
  +    backup_snap(),
       if SnapInterval > 0 -> erlang:send_after(SnapInterval, self(), snapshot); true -> ok end,
       {_, SnapDir} = application:get_env(imem, imem_snapshot_dir),
       SnapshotDir = filename:absname(SnapDir),
  
positive.code:     end.
  
  write(Table, Row) when is_atom(Table), is_tuple(Row) ->
      % ?Log("mnesia:write ~p ~p~n", [Table,Row]),
      Result = case transaction(write,[Table, Row, write]) of
          {aborted,{no_exists,_}} ->
              % ?Log("cannot write ~p to ~p~n", [Row,Table]),
  
negative.code:     end,
      Tabs = [T || T <- mnesia:system_info(tables), re:run(atom_to_list(T), "(.*@.*)|schema") =:= nomatch],
      [(fun() ->
          case ets:lookup(?MODULE, T) of
              [] -> ok;
              [#user_properties { table = T, last_write = Wt, last_snap = St} = Up | _] ->
                  LastWriteTime = timestamp(Wt),
                  LastSnapTime = timestamp(St),
                  if 
                      LastSnapTime < LastWriteTime ->
                          %if T =:= ddTable -> io:format(user, "snap ~p timestamps ~p ~p~n", [T, {LastWriteTime, LastSnapTime}, {Wt, St}]); true -> ok end,
                          mnesia:transaction(fun() ->
                                          Rows = mnesia:select(T, [{'$1', [], ['$1']}], write),
                                          BackFile = filename:join([SnapDir, atom_to_list(T)++".bkp"]),
                                          NewBackFile = filename:join([SnapDir, atom_to_list(T)++".bkp.new"]),
                                          ok = file:write_file(NewBackFile, term_to_binary(Rows)),
                                          {ok, _} = file:copy(NewBackFile, BackFile),
                                          ?Log("snap ~p -> ~p~n", [T, BackFile]),
                                          ok = file:delete(NewBackFile)
                                         end),
                          true = ets:insert(?MODULE, Up#user_properties{last_snap = erlang:now()});
                      true -> 
                          %if T =:= ddTable -> io:format(user, "nosnap ~p timestamps ~p ~p~n", [T, {LastWriteTime, LastSnapTime}, {Wt, St}]); true -> ok end,
                          ok % no backup needed
                  end
          end
        end)()
      || T <- Tabs],
  