Q&A: Can I increase the samba debug level on the fly?

Question:

Can I increase the samba debug level, without restarting the samba service?

Answer:

You can use the following script to increase the samba debug level on the fly, without restarting the samba service.

#!/bin/bash
set -euo pipefail

# Temp-Verzeichnis erstellen
TMP_DIR="$(mktemp -d)"
cd "$TMP_DIR" || exit 1
echo "Working in temporary directory: $TMP_DIR"

# Ursprünglichen Debug-Level aus smb.conf ermitteln
OLD_LEVEL=$(grep -m1 '^[[:space:]]*debug level' /etc/samba/smb.conf | awk -F= '{print $2}' | xargs)
[ -z "$OLD_LEVEL" ] && OLD_LEVEL=0

echo "Collecting initial Samba logs..."
cp -r /var/log/samba samba.0

echo "Increasing debug level to 10..."
smbcontrol all debug 10
sleep 1

echo
read -p "Please reproduce the problem now. Hit return when finished."
echo
sleep 3

echo "Restoring debug level ($OLD_LEVEL)..."
smbcontrol all debug "$OLD_LEVEL"

echo "Collecting new Samba logs..."
cp -r /var/log/samba samba.1

echo "Comparing logs..."
diff -Nuar samba.0 samba.1 > diff01 || true

rm -rf samba.0 samba.1

echo "Ok, the debug information has been saved to '$TMP_DIR/diff01'."

You do not always need the debug 10 level.
Level 5 shows a lot and might be enough.

:warning: Attention
You have to check your free disk space, and take care there is not too much load and open samba files (smbstatus) on the server.

1 Like