Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #!/usr/bin/python
  2. import psycopg2
  3. import os
  4. from pwd import getpwnam
  5. from grp import getgrnam
  6.  
  7. vmailuid = getpwnam('vmail')[2]
  8. vmailgid = getgrnam('vmail')[2]
  9. os.setuid( vmailuid )
  10.  
  11. connection = psycopg2.connect('dbname=virtual_mail user=foo password=bar host=myhost')
  12. cursor = connection.cursor()
  13.  
  14. #sql = 'SELECT id, legacy_username, username from virtual_users where legacy_username = \'dpkellyl\'; '
  15. sql = 'SELECT id, legacy_username, username from virtual_users;'
  16. cursor.execute( sql )
  17.  
  18. # mailboxes that still reside in /home
  19. still_in_home = set([
  20. 'anedgp',
  21. 'caservices_dial',
  22. 'child1',
  23. 'child11',
  24. 'child12',
  25. 'child2',
  26. 'dpk',
  27. 'dpkelly',
  28. 'dpkelly_block',
  29. 'dwbc_cath',
  30. 'informix',
  31. 'infovoice',
  32. 'katez016',
  33. 'malbec',
  34. 'mrtg',
  35. 'natashah',
  36. 'parent1',
  37. 'parent2',
  38. 'pedram',
  39. 'q_lekelly',
  40. 'q_mtkelly',
  41. 'q_natashah',
  42. 'q_samanthah',
  43. 'remove',
  44. 'roamer',
  45. 'samanthah',
  46. 'shiraz',
  47. 'test',
  48. 'thebakers',
  49. 'tp_advtax',
  50. 'tp_lynair',
  51. 'usage_20080118',
  52. 'usage_20080119',
  53. 'usage_20080202',
  54. 'usage_20080221',
  55. 'usage_20080319',
  56. 'usage_20080326',
  57. 'vo_faxtest',
  58. 'waymouthtower',
  59. ])
  60.  
  61. rows = cursor.fetchall()
  62.  
  63. for row in rows:
  64.  
  65. if( row[1] != None ):
  66.  
  67. base_location = None
  68. legacy_username = str(row[0])
  69.  
  70. if legacy_username in still_in_home:
  71. base_location = '/home/'
  72. else:
  73. base_location = '/mail/'
  74. maildir = '/var/mail/virtual_mail/voice.net.au/'
  75.  
  76. if not os.path.exists(maildir):
  77. os.makedirs( maildir )
  78.  
  79. if row[0] != None:
  80. print "Sync User "+str(row[1])
  81. fullpath = maildir+str(row[0])
  82. cmd = "/usr/bin/rsync -avzr -e ssh root@vns02.voice.net.au:"+base_location + str(row[1])+'/ '+ fullpath
  83. #print cmd
  84. output = os.system(cmd)
  85.  
  86. #cmd = "ln -s " + fullpath + " " + maildir + row[1]
  87. #print cmd
  88. #output = os.system(cmd)
  89.  
  90. #os.chown( fullpath,vmailuid,vmailgid )
  91.  
  92. cursor.close()
  93. connection.close()
  94.  
  95. # Convert everything to dovecot
  96. cmd = '/usr/local/bin/courier-dovecot-migrate.pl --convert --overwrite --to-dovecot --recursive /var/mail/virtual_mail/'
  97. print cmd + "\n"
  98. #os.system(cmd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement