#!/bin/bash # Stop the samba process. pkill -SIGTERM ^samba$ while pgrep ^samba$ [ $? -eq 0 ] do echo "wait..." sleep 1 done # Create backup files. TMP_TARGET=/root/packages/backup-$(hostname)-$(date +'%Y-%m-%d-%H-%M-%S').tar # Samba # Configuration. cd / tar -cvf $TMP_TARGET etc/samba --xattrs # Private directory. cd /var/ tar -uvf $TMP_TARGET lib/samba/private --xattrs --warning=no-file-ignored # SysVol directory. cd ./lib/samba/ find ./sysvol -exec bash -c 'TMP=$(samba-tool ntacl get "{}" --as-sddl); echo "samba-tool ntacl set \"$TMP\" \"{}\""' \; > NTACL cd ../../ tar -uvf $TMP_TARGET lib/samba/sysvol lib/samba/NTACL lib/samba/bind-dns --xattrs rm NTACL # Bind # Configuration. cd / tar -uvf $TMP_TARGET etc/bind --xattrs # Lib directory cd /var/ tar -uvf $TMP_TARGET lib/bind --xattrs # Compress. gzip $TMP_TARGET # Finish. /usr/sbin/samba --interactive --no-process-group & echo "Backed up."