How to find and backup different COS users
How to backup & restore COS, including the COS users.
In this article we will show how to:
- Back-up COS subtree (LDAP).
- Find which users belong to which COS, and place them into different files, based on COS.
- Restore COS subtree.
- Assign users to specific COS
1. Backup COS.
This step assumes that you would like to migrate a server to another one, and this is a way to move just the COS to the other server.
- Download JXplorer from http://jxplorer.org/downloads/users.html
Create new entry as follows:
Host: "client" server IP Port 389 ; Protocol v3 Base DN: cn=zimbra
Level: User + Password User DN: cn=config Password is the output from: zmlocalconfig -s ldap_root_password
- From the left Tree View, expand cos.
- Select the COS that you want to export&move.
- From the File menu line above, click on LDIF > Export Subtree > Save on the local disk.
- Do that with all COS you want to move.
2. Create files for each non-default COS, and their respective user members.
This step assumes that you are going to move the users from this server to another, and you want to create file for each non-default COS, and to include their members in it.
A short script accomplishes that:
#!/bin/bash # The result is a file/s for each COS, and the users within this specific COS # Note: If there are no custom created COS, there will be no users listed in the default and default_external files. That # means all users are in the "default" COS. # Since the default and the default_external files will contain no users, their respective files are deleted at # the end. Zimbra only detect users that are not in the default COS. Thus, every non detected user is in the default COS. mkdir /tmp/cos_users IFS=$'\n' source ~/bin/zmshutil; zmsetvars for i in `zmprov gac` do id=$(zmprov gc "$i" zimbraId | grep zimbraId | cut -f2 -d":" | tr -d ' ') /opt/zimbra/common/bin/ldapsearch -xLLL -o ldif-wrap=no -h `zmhostname`:389 -D $zimbra_ldap_userdn -w $zimbra_ldap_password "(&(objectclass=zimbraAccount)(zimbraCosId="$id"))" mail > "/tmp/cos_users/$i" /bin/rm -rf /migration/cos_users/default* done
3. How to restore COS.
This step assumes you are restoring the backed up COS to the new server.
- Create new entry in the JXplorer as in point 1, but this time specify the "destination" server IP.
- Click on the "cos"
- LDIF > Import File > Select File > Import
Do that with all COS you want to import.
4. This step assumes that you moved the users from the old to the new server, and this script will assign the correct COS to the migrated users.
#!/bin/bash # The script first list the exported cos names, then iterate through all members within this cos and finally assigns the # user to the COS. for cos in /tmp/cos_users/* do while read user; do echo "zmprov sac $user" \"$(basename -- "$cos")\" >> /tmp/cos_users.prov done <"$cos" done zmprov < /tmp/cos_users.prov