Guest User

Untitled

a guest
Dec 16th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. """
  2. Fix broken entryids in a folder
  3.  
  4. BEFORE YOU RUN THIS SCRIPT: BACKUP YOUR KOPANO DATABASE WITH mysqldump OR SIMILAR
  5. NOW YOU HAVE BEEN WARNED. THIS SCRIPT COMES WITH NO WARRANTY WHAT SO EVER.
  6.  
  7. Step 1: BACKUP DATABASE! It is recommended you shutdown kopano-server while running
  8. this.
  9. Step 2: Change the USER, PASSWORD, HOST, and DB variables below
  10. Step 3: Find the store guid and hierarchy id of the folder
  11.  
  12. 13:25:23 bo@alpha ~ > python
  13. Python 2.7.13 (default, Jan 03 2017, 17:41:54) [GCC] on linux2
  14. Type "help", "copyright", "credits" or "license" for more information.
  15. >>> import kopano
  16. >>> store=kopano.Server().user("user1").store <--- change the username here
  17. >>> store.guid
  18. 'A52FDDDAB6044C44A86E1FE2C5162342' <--- this is your storeguid
  19.  
  20. Step 4: Find the hierarchyid of the folder where the messages with broken entryids are
  21.  
  22. >>> folder=kopano.Server().user("user1").inbox <--- use .folder("folder1/folder2") for a deep hierarchy
  23. >>> folder.hierarchyid
  24. 52L <--- this is the hierarchyid (just 52 without L)
  25.  
  26. Step 5: Run the script
  27.  
  28. $ python fix-entryids.py <storeguid> <hierarchyid>
  29.  
  30. The example above:
  31.  
  32. $ python fix-entryids.py A52FDDDAB6044C44A86E1FE2C5162342 52
  33.  
  34. Step 6: Restart kopano-server or run kopano-admin --clear-cache and the items should
  35. be accessible again
  36. """
  37.  
  38. import mysql.connector
  39. import sys
  40. import uuid
  41.  
  42. USER="root"
  43. PASSWORD=""
  44. HOST="127.0.0.1"
  45. DB="kopano"
  46.  
  47. storeguid = sys.argv[1]
  48. hierarchyid = int(sys.argv[2])
  49.  
  50. cnx = mysql.connector.connect(user=USER, password=PASSWORD,
  51. host=HOST,
  52. database=DB)
  53.  
  54. query = ("SELECT id FROM hierarchy WHERE parent=%d AND type=5" % hierarchyid)
  55.  
  56. cursor = cnx.cursor()
  57. cursor.execute(query)
  58.  
  59. result = []
  60. for (id,) in cursor:
  61. result.append(id)
  62.  
  63. for id in result:
  64. print "generating new entryid for: " + str(id)
  65. newentryid = '00000000' + storeguid + '0100000005000000' + uuid.uuid4().hex.upper() + '00000000'
  66. query = ("UPDATE indexedproperties SET val_binary = UNHEX('%s') WHERE tag = 4095 AND hierarchyid = %d" % (newentryid, id))
  67. print query
  68. cursor.execute(query)
  69.  
  70. cnx.commit()
  71. cnx.close()
Add Comment
Please, Sign In to add comment