How to Backup/Clear/Restore a SpamAssassin Bayes Database

Sometimes you might have to work with the Spamassin Bayes Token database. This is the database that is used by the SpamAssassin Self Learning (Bayesian) Classifier to store the ham and spam tokens. This tutorial will show you how to make a backup of that database. E.g. when you want to move it to a new server. It will show you how to clear the database in case that it learned wrong tokens and how to restore the Bayes database from a backup. All these tasks can be performed with the sa-learn command.

I’ve tested the steps below on an ISPConfig 3 server with Debian Linux which uses SpamAssassin and Amavisd for spam scanning. If you are using an Ubuntu system, prepend the command ‘sudo’ to all commands.

Backup SpamAssassin Bayes Database

The command to back up the Bayes database is:

sa-learn --backup > /tmp/bayes.db

The command will store the backup in the file /tmp/bayes.db. This command needs to be run under the username that created and uses the database. On systems that use Amavis (e.g. an ISPConfig 3 server), this user is named ‘amavis’. I will use the su command here:

su amavis -c 'sa-learn --backup > /tmp/bayes.db'

This command executes the sa-learn backup command as user amavis and stores the backup file in the /tmp folder of your server.

Restore SpamAssassin Bayes database

The command to restore the content of the SpamAssassin Bayes database is:

sa-learn --restore /tmp/bayes.db

In my case, I had to run this command as amavis user, so the command that I run us:

su amavis -c 'sa-learn --restore /tmp/bayes.db'

Clear SpamAssassin Bayes Database

The Command to clear the Bayes database is:

sa-learn --clear

This command needs to be run as the user which created the database. In my case, this user is ‘amavis’. the command to run sa-learn –clear as amavis user on Debian is:

su amavis -c 'sa-learn --clear'

That’s all. Spamassassin/Amavis will start to learn new tokens now.

The post How to Backup/Clear/Restore a SpamAssassin Bayes Database appeared first on FAQforge.

Ubuntu Server Admin

Recent Posts

How to avoid package End of Life through backporting

In July 2025, git received CVE-2025-48384, a high vulnerability allowing arbitrary code execution when cloning…

3 days ago

Showcasing open design in action: Loughborough University design students explore open source projects

Last year, we collaborated with two design student teams from Loughborough University in the UK.…

7 days ago

Canonical Ubuntu and Ubuntu Pro now available on AWS European Sovereign Cloud

January 15, 2026 – Canonical, the publisher of Ubuntu and provider of open source security,…

1 week ago

How to install GitLab on Ubuntu 24.04

How to install GitLab on Ubuntu 24.04 will be explained in this blog post with…

1 week ago

How to Set Up OpenVPN Access Server on Ubuntu 24.04 (VM) & Connect Using OpenVPN Connect

Do you know what was always there but has increased multiple times in the last…

2 weeks ago

How to build DORA-ready infrastructure with verifiable provenance and reliable support

The Digital Operational Resilience Act (DORA) came into force across the EU on January 17,…

2 weeks ago