title: Proper CDR collecting process for asterisk CDR databases
body: <p>First of all sorry for this complex long problem explanation.</p>
  
  <p>Currently I'm maintaining several <code>asterisk</code> servers which process calls. currently I'm collecting <code>CDR</code>s to centralized database hourly. </p>
  
  <p>The main problem here is to track <code>copied</code> records and <code>new</code> records. In my setup each <code>asterisk</code> <code>CDR</code> table have <code>id</code> column as the <em>primary key</em>. So in centralized table I'm coping this <code>id</code> and also maintain a column to keep <code>server_name</code>. By using both <code>id</code> and <code>server_name</code> I can identify the last collected <code>id</code> number of each <code>asterisk</code> server and then collected all new <code>CDR</code>s which higher than that <code>id</code> number.</p>
  
  <p>This process is not perfect since its not good to rely on that id will always increase. And also I need to convert this setup to <code>REST API</code> and stop using <code>id</code> for this.</p>
  
  <p>Use <code>datetime</code> range to pick call records also not a good idea because I'm collecting <code>CDR</code>s hourly and what if there was ongoing call with <code>duration</code> more than 1 hour. <code>Asterisk</code> <code>CDR</code> insert records at the end of the call and <code>datetime</code> field is not always in ascending order.</p>
  
  <p>I could use a <em>flag</em> called <code>copied</code> with using above <code>datetime</code> range and solve the missing record problem but it is not suit with <code>REST APT</code> since it is <em>stateless</em> and can't keep <em>flags</em>.</p>
  
  <p>Now I'm ran out of ideas... and wondering is there better solution for this...</p>
  
  <p>Hope some expert can help me...</p>