Active Topics

 


Reply
Thread Tools
ilpianista's Avatar
Posts: 22 | Thanked: 13 times | Joined on Sep 2010
#1
Hi all,
I don't know if this has already been discussed somewhere else, but I didn't know how to remove very old messages without remove the whole conversation. Then I wrote this little script. Hope this helps someone else too.

Code:
#!/bin/sh

if [ $# -eq 0 ]; then
  echo "usage: $(basename $0) <db file> \"YYYY-MM-DD HH:MM\""
  exit 1
fi

db=$1
sqlite=sqlite3

# timestamp
date=$(date +%s --date="$2")

echo "${sqlite} ${db} \"DELETE FROM Events WHERE storage_time<'$date';\""
${sqlite} ${db} "DELETE FROM Events WHERE storage_time<'$date';"

echo "${sqlite} ${db} \"SELECT event_id FROM GroupCache;\""
ids=$(${sqlite} ${db} "SELECT event_id FROM GroupCache;")

for id in $ids; do
  echo "${sqlite} ${db} \"SELECT remote_uid FROM Events WHERE id='$id';\""
  number=$(${sqlite} ${db} "SELECT remote_uid FROM Events WHERE id='$id';")

  echo "${sqlite} ${db} \"SELECT COUNT(id) FROM Events WHERE remote_uid='$number';\""
  total_events=$(${sqlite} ${db} "SELECT COUNT(id) FROM Events WHERE remote_uid='$number';")

  echo "${sqlite} ${db} \"UPDATE GroupCache SET total_events='$total_events' WHERE event_id='$id';\""
  ${sqlite} ${db} "UPDATE GroupCache SET total_events='$total_events' WHERE event_id='$id';"

  echo "${sqlite} ${db} \"UPDATE GroupCache SET read_events='$total_events' WHERE event_id='$id';\""
  ${sqlite} ${db} "UPDATE GroupCache SET read_events='$total_events' WHERE event_id='$id';"
done

exit 0
That's all. Now you can play removing old messages only from a specific number or everything you want
Note, it's the first time I play with the rtcom database.

PS. I used it and everything still works fine, but I suggest you to DO A BACKUP before!
 

The Following 4 Users Say Thank You to ilpianista For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 21:00.