An init.d script to back up and restore Samba .tdb files.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


An init.d script to automate the back up and restore of Samba .tdb files.

The idea was just to implement a fairly minor following of a best-practice recommendation. Inspired by

Written for a Debian 8.7 (Jessie) environment, running a fairly simply-configured standalone-server instance of Samba (4.2.14-Debian at time of writing).

Once installed the script will execute with system startup (run-levels 2, 3, 4, and 5) and on shutdown (run-levels 0, 1, and 6). On startup the script validates Samba's .tdb files, and if necessary will recover corrupted .tdb files from the most recent backup available. On shutdown, the current .tdb files are backed up and backup files older than two two weeks (configurable) are deleted.

Essentially it's just a nice, automated way of using the tdbbackup utility.

To install it: (assuming your Debian[whatever] and Samba are up and running)

  • copy the samba-tdb script file to /etc/init.d/
  • remember to set execute permissions: -- $ sudo chmod +x samba-tdb
  • inform init.d of the new script so it runs on startup and shutdown: -- $ sudo update-rc.d samba-tdb defaults
  • done.


  • call it with a valid option (if invalid it will tell you): -- $ sudo /etc/init.d/samba-tdb OPTION
  • valid options are: -- start OR validate --- The script will call "tdbbackup -v" to check your current .tdb files. If necessary a backup will be restored (if the file's corrupted, and if a backup is available). -- stop OR backup --- The script calls a plain "tdbbackup" to back up the current .tdb files with the default .bak suffix. It then copies the new .bak files and adds a ".YYYYMMDDHHMM" suffix so a history can be kept. Finally it checks for backups older than 14 days (configurable) and deletes them.

Bugs, Known Issues, and Limitations:

  • The script does not deal with outright missing .tdb files. If a file used to be and now no longer is, this script will not pick that up for you. Hopefully this convenience will be added in future (maybe through a comparison of existing .bak files with the current .tdb files or something...).


... hopefully this is useful ;)