#!/bin/sh

#
# cron script to snapshot samba database.
#
# 2025, Vladimir Smirnov <kkatarn@sleepgate.ru>
# 2025, Skoltech
#

# The following two vars are better be hardcoded...
DATASET="zero/var/lib/samba-ad"
NTPSRV="10.17.11.100"

SNAP="${DATASET}@$(date +%Y-%m-%d)"
ME="$(basename $0)"

_rv=0

echo "${ME}: stopping samba services..."
systemctl stop nmbd
systemctl stop smbd
systemctl stop winbind

echo "${ME}: syncing time with ${NTPSRV}..."
ntpdate ${NTPSRV} || _rv=1

echo "${ME}: making snapshot \"${SNAP}\"..."
zfs snapshot ${SNAP} || _rv=1

echo "${ME}: starting samba services..."
systemctl start winbind || _rv=1
systemctl start smbd || _rv=1
systemctl start nmbd

exit ${_rv}
