[horde] Deleting all data for a user

Jacques Beaudoin jacques-beaudoin at cspi.qc.ca
Sun May 7 21:39:18 PDT 2006


Hi,

Just to follow-up, this is a script that I made to cleanup
my Horde Database.

Maybe someone will like to comment on this script.

#
#  This is my script to delete all records for a given
#  users in the horde tables
#
#  Exemple usage : /root/horde-delete.sh "john-down"
#

USER="$1"

cd /root

#
#  Count records before delete
#
HP_B=`mysql -s -u root  -e "SELECT count(*) from horde.horde_prefs WHERE pref_uid='$USER'"`
KE_B=`mysql -s -u root  -e "SELECT count(*) from horde.kronolith_events WHERE calendar_id='$USER'"`
MM_B=`mysql -s -u root  -e "SELECT count(*) from horde.mnemo_memos WHERE memo_owner='$USER'"`
TO_B=`mysql -s -u root  -e "SELECT count(*) from horde.turba_objects WHERE owner_id='$USER'"`
NT_B=`mysql -s -u root  -e "SELECT count(*) from horde.nag_tasks WHERE task_owner='$USER'"`
HD_B=`mysql -s -u root  -e "SELECT count(*) from horde.horde_datatree WHERE user_uid='$USER'"`
HDA_B=0
COUNT=0
mysql -s -u root  -e "SELECT datatree_id from horde.horde_datatree WHERE user_uid='$USER'" > /tmp/01
while read I
do
  COUNT=`mysql -s -u root  -e "SELECT count(*) from horde.horde_datatree_attributes WHERE
datatree_id='$I'"`
  HDA_B=`expr $HDA_B + $COUNT`
done</tmp/01

#
#  Delete records (Comments out these lines for testing)
#
mysql -s -u root  -e "DELETE from horde.horde_prefs WHERE pref_uid='$USER'"
mysql -s -u root  -e "DELETE from horde.kronolith_events WHERE calendar_id='$USER'"
mysql -s -u root  -e "DELETE from horde.mnemo_memos WHERE memo_owner='$USER'"
mysql -s -u root  -e "DELETE from horde.turba_objects WHERE owner_id='$USER'"
mysql -s -u root  -e "DELETE from horde.nag_tasks WHERE task_owner='$USER'"
mysql -s -u root  -e "DELETE from horde.horde_datatree WHERE user_uid='$USER'"
while read I
do
  mysql -s -u root  -e "DELETE from horde.horde_datatree_attributes WHERE datatree_id='$I'"
done</tmp/01

#
#  Count records after delete (Should always give zero)
#
HP_A=`mysql -s -u root  -e "SELECT count(*) from horde.horde_prefs WHERE pref_uid='$USER'"`
KE_A=`mysql -s -u root  -e "SELECT count(*) from horde.kronolith_events WHERE calendar_id='$USER'"`
MM_A=`mysql -s -u root  -e "SELECT count(*) from horde.mnemo_memos WHERE memo_owner='$USER'"`
TO_A=`mysql -s -u root  -e "SELECT count(*) from horde.turba_objects WHERE owner_id='$USER'"`
NT_A=`mysql -s -u root  -e "SELECT count(*) from horde.nag_tasks WHERE task_owner='$USER'"`
HD_A=`mysql -s -u root  -e "SELECT count(*) from horde.horde_datatree WHERE user_uid='$USER'"`
HDA_A=0
COUNT=0
mysql -s -u root  -e "SELECT datatree_id from horde.horde_datatree WHERE user_uid='$USER'" > /tmp/01
while read I
do
  COUNT=`mysql -s -u root  -e "SELECT count(*) from horde.horde_datatree_attributes WHERE
datatree_id='$I'"`
  HDA_A=`expr $HDA_A + $COUNT`
done</tmp/01

#
#  Display tables record counts after delete operation
#
echo "Before and after records count for user $USER'"
echo "==========================================================================="
echo "horde_prefs: $HP_B / $HP_A"
echo "kronolith_events: $KE_B / $KE_A"
echo "mnemo_memos: $MM_B / $MM_A"
echo "turba_objects: $TO_B / $TO_A"
echo "nag_tasks: $NT_B / $NT_A"
echo "horde_datatree: $HD_B / $HD_A"
echo "horde_datatree_attributes: $HDA_B / $HDA_A"

exit 0



Thanks


Jacques Beaudoin
Agent d'administration
Les services des technologies
de l'information et des communications
Commission scolaire de la Pointe de l'Île
Montréal, Québec, Canada

Courriel/Email: jacques-beaudoin at cspi.qc.ca
Cel: 514 918-3350






More information about the horde mailing list