View | Details | Raw Unified | Return to bug 32685
Collapse All | Expand All

(-)a/branches/ucs-3.2/ucs-3.2-1/management/univention-directory-replication/replication.py (-18 / +18 lines)
 Lines 808-842   def flatmode_reconnect(): Link Here 
808
def _delete_dn_recursive(l, dn):
808
def _delete_dn_recursive(l, dn):
809
	try:
809
	try:
810
		l.delete_s(dn)
810
		l.delete_s(dn)
811
	except ldap.NOT_ALLOWED_ON_NONLEAF, msg:
811
	except ldap.NOT_ALLOWED_ON_NONLEAF:
812
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'Failed to delete non leaf object: dn=[%s];' % dn)
812
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'Failed to delete non leaf object: dn=[%s];' % dn)
813
		dns=[]
813
		dns = [dn_ for dn_, _attr in l.search_s(dn, ldap.SCOPE_SUBTREE, '(objectClass=*)', attrlist=['dn'])]
814
		for dn,attr in l.search_s(dn, ldap.SCOPE_SUBTREE, '(objectClass=*)'):
815
			dns.append(dn)
816
		dns.reverse()
814
		dns.reverse()
817
		for dn in dns:
815
		for dn in dns:
818
			l.delete_s(dn)
816
			l.delete_s(dn)
819
	except ldap.NO_SUCH_OBJECT, msg:
817
	except ldap.NO_SUCH_OBJECT:
820
		pass
818
		pass
821
819
822
def _backup_dn_recursive(l, dn):
820
def _backup_dn_recursive(l, dn):
821
	try:
822
		result = l.search_s(dn, ldap.SCOPE_SUBTREE, '(objectClass=*)', attrlist=['*', '+'])
823
	except ldap.NO_SUCH_OBJECT:
824
		return
825
823
	backup_directory = '/var/univention-backup/replication'
826
	backup_directory = '/var/univention-backup/replication'
824
	if not os.path.exists(backup_directory):
827
	if not os.path.exists(backup_directory):
825
		os.makedirs(backup_directory)
828
		os.makedirs(backup_directory)
826
		os.chmod(backup_directory, 0700)
829
		os.chmod(backup_directory, 0700)
827
	
830
828
	backup_file = os.path.join(backup_directory, str(time.time()))
831
	backup_file = os.path.join(backup_directory, str(time.time()))
829
	fd = open(backup_file, 'w+')
830
	fd.close()
831
	os.chmod(backup_file, 0600)
832
	univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'replication: dump %s to %s' % (dn, backup_file))
832
	univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'replication: dump %s to %s' % (dn, backup_file))
833
	
833
	os.chmod(backup_file, 0600)
834
	fd = open(backup_file, 'w+')
834
	with open(backup_file, 'w+') as fd:
835
	ldif_writer = ldifparser.LDIFWriter(fd)
835
		ldif_writer = ldifparser.LDIFWriter(fd)
836
	for dn,entry in l.search_s(dn, ldap.SCOPE_SUBTREE, '(objectClass=*)', attrlist=['*', '+']):
836
		for dn, entry in result:
837
		ldif_writer.unparse(dn,entry)
837
			ldif_writer.unparse(dn,entry)
838
	fd.close()
838
839
		
840
def _get_current_modrdn_link():
839
def _get_current_modrdn_link():
841
	return os.path.join(STATE_DIR, 'current_modrdn')
840
	return os.path.join(STATE_DIR, 'current_modrdn')
842
841
 Lines 1024-1030   def handler(dn, new, listener_old, operation): Link Here 
1024
					univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'replication: the current modrdn points to a different entryUUID: %s' % os.readlink(current_modrdn_link))
1023
					univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'replication: the current modrdn points to a different entryUUID: %s' % os.readlink(current_modrdn_link))
1025
1024
1026
					old_dn = _read_dn_from_file(current_modrdn_link)
1025
					old_dn = _read_dn_from_file(current_modrdn_link)
1027
1028
					if old_dn:
1026
					if old_dn:
1029
						univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'replication: the DN %s from the current_modrdn_link has to be backuped and removed' % (old_dn))
1027
						univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'replication: the DN %s from the current_modrdn_link has to be backuped and removed' % (old_dn))
1030
						try:
1028
						try:
 Lines 1033-1041   def handler(dn, new, listener_old, operation): Link Here 
1033
							# The backup will fail in LDIF mode
1031
							# The backup will fail in LDIF mode
1034
							pass
1032
							pass
1035
						_delete_dn_recursive(l, old_dn)
1033
						_delete_dn_recursive(l, old_dn)
1034
						if dn == old_dn:
1035
							old = None
1036
					else:
1036
					else:
1037
						univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'replication: no old dn has been found')
1037
						univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'replication: no old dn has been found')
1038
					
1038
1039
					if not old:
1039
					if not old:
1040
						_add_object_from_new(l, dn, new)
1040
						_add_object_from_new(l, dn, new)
1041
					elif old:
1041
					elif old:

Return to bug 32685