I’ve been playing with the idea of running a standalone Samba server to replace an old NAS device that I’d like to repurpose. So I looked for some Samba best-practice ideas and one of them mentioned the periodic backing up and checking the small database files Samba uses for storing config and running info. I figured I’d automate the task with a script, and here we are.
And there the script is, over on my GitHub. The readme there pretty much explains what it does (I hope). The system I set this up for is a Debian 8.7 (Jessie) system so directories (and such) mentioned are applicable to that.
Putting this together was a fun exercise in learning about Linux init.d, and learning some cool bash scripting & general command use overall. Plus Samba & its .tdb files of course.
Very broadly, the Linux system’s service manager, systemd as of Debian Jessie, calls init.d scripts(/services) when the system’s run-level changes. That is, when the machine boots, powers off, restarts, goes to sleep, and that kind of thing. So one can set up init.d scripts to run when a machine shuts down or boots & whatnot. Setting up your own essentially involves writing your shell script (with some specific descriptive info on top – see the Credits section of the script readme for links) and copying it to /etc/init.d/ (there’s also a sample file at /etc/init.d/skeleton).
I should mention that init.d scripts, as far as I know, are not actually the proper way with systemd. They’re supported as compatibility throwbacks to ease the transition from sysinit. I may update the script to do things the systemd way, at some stage…
Beyond that, compiling this script was great bash scripting practice. My favourite find is the one-line for-loop for copying files and renaming the copies, that the script uses to build a backup history. I can see myself using that in more places.
That’s about it. If you have a Samba server, and it runs on Debian (some Debian derivative would probably work too), well maybe you’ll like this. 😉