[Samba] Syncing Sysvol

Rowland penny rpenny at samba.org
Tue Jul 16 12:11:29 UTC 2019


Hi, in this thread: 
https://lists.samba.org/archive/samba/2019-July/224365.html

Joachim Lindenberg reminded me that he was using smbclient to sync Sysvol.

He posted (in the link above) a link to his original post:

https://lists.samba.org/archive/samba/2019-July/224346.html

Here he posted a copy of his script. I personally would never have 
thought about using smbclient, but it just goes to show how inventive 
Samba users are.

I have tested the script (and altered it slightly), it seems to work, so 
here is my version:

#------- script start ---------------------
#!/bin/bash
# prerequisite: apt-get install smbclient

# you need to be root or use sudo to run this script.
if [ "$EUID" -ne 0 ]; then
     echo "Please run as root, or use sudo. Exiting now..."
     exit 1
fi

sysvol="$(samba -b | grep "STATEDIR" | awk '{print $NF}')/sysvol"
[[ -d $sysvol ]] || exit

pdc=$(host -t SRV _ldap._tcp.pdc._msdcs."$(hostname -d)" | awk '{print 
$NF}' | awk -F '.' '{print $1}')
thisdc=$(hostname -s)
if [ "$thisdc" = "$pdc" ]; then
     echo "This is the DC holding the PDC Emulator role"
     echo "Cannot continue...Exiting."
     exit
fi

if [ ! -d /tmp/samba ]; then
     mkdir /tmp/samba
     if [ "$?" != 0 ]; then
         exit
     fi
fi

if [ ! -f /tmp/samba/olddir ]; then
     echo '0' > /tmp/samba/olddir
fi

smbclient --machine-pass -e --max-protocol SMB3 \\\\"$pdc"\\sysvol -c 
"prompt; recurse; dir *" >/tmp/samba/newdir

cmp /tmp/samba/newdir /tmp/samba/olddir > /dev/null 2>&1
if [ $? -ne 0 ]; then
     mkdir /tmp/samba/sysvol
     cd /tmp/samba/sysvol || exit
     smbclient --machine-pass -e --max-protocol SMB3 \\\\"$pdc"\\sysvol 
-c "prompt; recurse; mget *"
     mv "$sysvol" "$sysvol.old"
     mv /tmp/samba/sysvol "$sysvol.old/.."
     samba-tool ntacl sysvolreset
     rm -r "$sysvol.old"
     rm -f /tmp/samba/olddir
     mv /tmp/samba/newdir /tmp/samba/olddir
fi

exit 0
#----------- script end ----------------

My version is a bit simpler and doesn't use ldb-tools.

Rowland





More information about the samba mailing list