Tuesday, July 21, 2015

Samba Migration to a New Server

#OLD SERVER
 mkdir /root/move


# Stop samba services
 service smb stop
 service nmb stop
 ckconfig smb off
 chkconfig nmb off

# RHEL/CentOS/Fedora: Default is 500 and upper limit is 65534 (/etc/libuser.conf).
# Debian/Ubuntu: Default is 1000 and upper limit is 29999 (/etc/adduser.conf).
 export UGIDLIMIT=500
 awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
 awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
 awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig

SERVER=IPADDRESS-HERE
 rsync -av /home/ $SERVER:/home/ --delete
 rsync -av /root/move $SERVER:/root/
 rsync -av /root/bin $SERVER:/root/ --delete
 rsync -av /etc/samba $SERVER:/etc/ --delete
 rsync -av /var/lib/samba $SERVER:/var/lib/ --delete

#NEW SERVER
 cd /root/move
 cat passwd.mig >> /etc/passwd
 cat group.mig >> /etc/group
 cat shadow.mig >> /etc/shadow

#IF smbpasswd convert to tdbsam

 pdbedit -i smbpasswd -e tdbsam

mv  /etc/samba/passdb.tdb /var/lib/samba/private
mv /etc/samba/secrets.tdb /var/lib/samba/private

#Start Samba services
 service smb start
 service nmb start
 chkconfig smb on
 chkconfig nmb on

Ref:

http://amar-linux.blogspot.com/2012/03/migrating-samba-server-and-users-in.html
http://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/

No comments:

Post a Comment