Repository navigation
Database Backup
Since v4.0.11 YAF.NET can back up its database itself: on demand, or every night. The backups are zip files in a folder of the application, and you can download them from the admin area. Each backup contains the database and the files of the forum: the uploaded files (attachments, album images) and the images (avatars, category, forum and medal images, logos).
The page is under Admin > Database > Backup. Only the host admin can see it, because a backup contains the whole database (all boards, users and password hashes).
The menu entry and the page are only shown when a backup is possible on your server. If you don't see them, open Admin > Host Settings > Server Info: the field Database Backup shows why the backup is not available.
| Option | Description |
|---|---|
| Nightly backup | Turns the automatic backup on or off. The backup runs once per night, between 01:00 and 06:00 (server time, which is UTC in a Docker container). |
| Backups to keep | The number of backups to keep. After each backup the oldest ones are deleted. 0 keeps all backups. The default is 7. |
| Backup now | Creates a backup right away. Only one backup can run at a time. |
Below the settings you find the list of the existing backups, with their size and date. You can download or delete each one.
The backups are named yaf-backup-yyyyMMdd-HHmmss.zip (UTC time). Each zip contains:
yaf-backup-20261113-020000.bak the database (.bak, .sql or .db, see below)
wwwroot/uploads/... the uploaded files
wwwroot/images/... the images
With StaticFilesRoot the folders are in that sub folder (e.g. wwwroot/Forums/uploads), with MultiBoardFolders the folders of each board are included (e.g. wwwroot/1/uploads, wwwroot/2/uploads). A file that can't be read during the backup (e.g. an upload that is just written) is skipped and logged. The other files of wwwroot (scripts, styles, themes, languages) are part of the installation and not backed up, neither is the search index, which the forum rebuilds.
The database file in the zip:
| Database | File in the zip | How it is made |
|---|---|---|
| SQL Server | .bak |
BACKUP DATABASE ... WITH COPY_ONLY (a full backup that doesn't affect your other backups or the log chain) |
| MySQL / MariaDB | .sql |
A SQL dump made over the connection of the forum (no mysqldump needed) |
| PostgreSQL | .sql |
A SQL dump made with pg_dump
|
| SQLite | .db |
A copy of the database made with VACUUM INTO
|
The backup is configured in the BoardConfiguration section of the appsettings.json (see BoardConfiguration Settings):
| Setting | Default | Description |
|---|---|---|
BackupFolder |
App_Data/Backups |
The folder of the backups, as the application sees it. A relative path is relative to the application folder. The application needs write access. The folder must not be in wwwroot, so the backups can't be downloaded without logging in. |
SqlServerBackupFolder |
empty | SQL Server only: the same folder as SQL Server sees it. Without it, the backup is not available for SQL Server. |
PgDumpPath |
pg_dump |
PostgreSQL only: the pg_dump program, a full path or a name in the PATH. |
The settings are read at startup, so restart the application after changing them.
Works everywhere, nothing to set up. The backup is written by the application itself.
Works everywhere, nothing to set up. The dump is made over the connection of the forum, so it also works with a database on another server or a hosted database.
The backup needs the program pg_dump (package postgresql-client) on the application server. Its version must be the same or newer than the version of the PostgreSQL server: an older pg_dump refuses to dump a newer server.
-
Docker: the YAF.NET PostgreSQL image already contains the newest
pg_dumpfrom the PostgreSQL apt repository. -
Linux: install the client tools, e.g.
apt install postgresql-client. If your distribution only has an older version, use the PostgreSQL apt repository. -
Windows: install the PostgreSQL command line tools and set
PgDumpPath, e.g.C:\Program Files\PostgreSQL\17\bin\pg_dump.exe.
pg_dump uses the host, port, user, password and SSL mode of the connection string of the forum.
SQL Server writes the .bak file itself, on its own disk, not through the application. So the backup only works when SQL Server and the application share a folder:
-
SqlServerBackupFolderis the folder as SQL Server sees it. -
BackupFolderis the same folder as the application sees it.
The database user needs the permission BACKUP DATABASE (e.g. the role db_backupoperator or db_owner).
If the database user is a sysadmin, YAF.NET checks that SQL Server sees the folder of the application, and only shows the page if it does. Otherwise this can't be checked: the page is shown with a note, and the first backup checks it. If the backup file doesn't show up in the folder of the application, the page is hidden again and Host Settings shows the reason.
Set both settings to the same folder:
"BoardConfiguration": {
"BackupFolder": "C:\\YafBackups",
"SqlServerBackupFolder": "C:\\YafBackups"
}You can also keep the default BackupFolder and set SqlServerBackupFolder to the full path of the App_Data\Backups folder of the application.
The SQL Server service account needs write access to the folder, e.g. for the default instance:
icacls C:\YafBackups /grant "NT Service\MSSQLSERVER":(OI)(CI)M
For SQL Server Express the account is NT Service\MSSQL$SQLEXPRESS.
The SQL Server compose file (see Docker) shares the named volume yaf-backups between both containers:
services:
yafnet:
environment:
- BoardConfiguration__SqlServerBackupFolder=/var/opt/mssql/backup
volumes:
- yaf-backups:/app/App_Data/Backups
sql-server-db:
volumes:
- yaf-backups:/var/opt/mssql/backup
sql-server-backup-init:
# gives the SQL Server user (10001) write access to the volume
...
volumes:
yaf-backups:SQL Server runs as user mssql (10001) and creates the .bak file only readable by that user and its group. The application container runs as root, so it can zip and delete the file. If you run the application as a different user, it must be able to read the files of SQL Server.
- Hosted SQL Server / SQL Server on another server: the backup is only possible if the hoster gives you a folder (network share) that SQL Server and the application can both reach. This is usually not the case; use the backup of your hoster.
- Azure SQL Database / Azure SQL Managed Instance can't back up to a disk, so the backup is not available.
- SQL Server in Docker Desktop with a Windows folder (bind mount): SQL Server can't write the backup into a folder of the Windows host (operating system error 31). Use a named volume as in the compose file.
The restore is not part of YAF.NET: stop the forum and restore the backup with the tools of your database. Unzip the backup first.
Files: copy the folder wwwroot of the zip into the application folder, so wwwroot/uploads and wwwroot/images are replaced. With Docker, e.g. docker cp ./wwwroot/. yafnet:/app/wwwroot/ (the name of the container may differ, see docker ps).
SQLite: replace the database file (e.g. /data/yafnet.db in the Docker volume) with the .db file of the backup.
SQL Server:
RESTORE DATABASE [yaf] FROM DISK = N'/var/opt/mssql/backup/yaf-backup-20261113-020000.bak' WITH REPLACEMySQL / MariaDB:
mariadb -u root -p yaf < yaf-backup-20261113-020000.sql
PostgreSQL (into an empty database):
psql -U postgres -d yaf -f yaf-backup-20261113-020000.sql
- The backups are stored on the same server as the forum. Download them regularly, or copy the backup folder (or Docker volume) somewhere else: a backup on the same disk doesn't help when the disk or server is lost.
- The backup folder needs enough free space for the backups you keep, plus the unzipped file of the running backup. Every backup contains all uploads and images again, so with many attachments set Backups to keep accordingly.
- A backup of a large database can take a while; it can run up to
SqlCommandTimeoutseconds.
YetAnotherForum.NET (YAF) the Open Source Discussion Forum for ASP.NET - https://YetAnotherForum.NET - Support me on Ko-fi
Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved
Getting started
- About YAF.NET
- Features
- Docker
- Installation (IIS)
- Hosting on Linux with nginx
- Integration (ASP.NET Core)
- Upgrade to v4
Configuration
Administration
Help
Development
Legacy (v3 and older)