Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import psycopg2
- import os
- from pwd import getpwnam
- from grp import getgrnam
- vmailuid = getpwnam('vmail')[2]
- vmailgid = getgrnam('vmail')[2]
- os.setuid( vmailuid )
- connection = psycopg2.connect('dbname=virtual_mail user=foo password=bar host=myhost')
- cursor = connection.cursor()
- #sql = 'SELECT id, legacy_username, username from virtual_users where legacy_username = \'dpkellyl\'; '
- sql = 'SELECT id, legacy_username, username from virtual_users;'
- cursor.execute( sql )
- # mailboxes that still reside in /home
- still_in_home = set([
- 'anedgp',
- 'caservices_dial',
- 'child1',
- 'child11',
- 'child12',
- 'child2',
- 'dpk',
- 'dpkelly',
- 'dpkelly_block',
- 'dwbc_cath',
- 'informix',
- 'infovoice',
- 'katez016',
- 'malbec',
- 'mrtg',
- 'natashah',
- 'parent1',
- 'parent2',
- 'pedram',
- 'q_lekelly',
- 'q_mtkelly',
- 'q_natashah',
- 'q_samanthah',
- 'remove',
- 'roamer',
- 'samanthah',
- 'shiraz',
- 'test',
- 'thebakers',
- 'tp_advtax',
- 'tp_lynair',
- 'usage_20080118',
- 'usage_20080119',
- 'usage_20080202',
- 'usage_20080221',
- 'usage_20080319',
- 'usage_20080326',
- 'vo_faxtest',
- 'waymouthtower',
- ])
- rows = cursor.fetchall()
- for row in rows:
- if( row[1] != None ):
- base_location = None
- legacy_username = str(row[0])
- if legacy_username in still_in_home:
- base_location = '/home/'
- else:
- base_location = '/mail/'
- maildir = '/var/mail/virtual_mail/voice.net.au/'
- if not os.path.exists(maildir):
- os.makedirs( maildir )
- if row[0] != None:
- print "Sync User "+str(row[1])
- fullpath = maildir+str(row[0])
- cmd = "/usr/bin/rsync -avzr -e ssh root@vns02.voice.net.au:"+base_location + str(row[1])+'/ '+ fullpath
- #print cmd
- output = os.system(cmd)
- #cmd = "ln -s " + fullpath + " " + maildir + row[1]
- #print cmd
- #output = os.system(cmd)
- #os.chown( fullpath,vmailuid,vmailgid )
- cursor.close()
- connection.close()
- # Convert everything to dovecot
- cmd = '/usr/local/bin/courier-dovecot-migrate.pl --convert --overwrite --to-dovecot --recursive /var/mail/virtual_mail/'
- print cmd + "\n"
- #os.system(cmd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement