Data and backups
DATA_DIR — the only persistent location
When a bot container restarts (redeploy, restart, token change), its file system is wiped — except for the folder pointed to by the DATA_DIR environment variable. Files written anywhere else (for example, inside the project itself) are gone on the next start. So keep all persistent data — SQLite databases, Excel exports, uploaded images — inside DATA_DIR only (sample code).
Examples
import sqlite3, os
db = sqlite3.connect(os.path.join(os.getenv("DATA_DIR", "./data"), "bot.sqlite3"))
const fs = require("fs")
const path = require("path")
const file = path.join(process.env.DATA_DIR || "./data", "users.json")
fs.writeFileSync(file, JSON.stringify(data))
Daily automatic backup
Every day at 03:00 (Tashkent time), the DATA_DIR folder of every active bot is archived in full, encrypted with AES-256-GCM and stored separately. Bots with no activity since their last backup are skipped, so no resources are wasted.
Retention
| Plan | Retention |
|---|---|
| Start, Freelancer | 7 days |
| Pro | 14 days |
| Business | 30 days |
Expired backups are deleted automatically. In the dashboard, Bot → Backups lists every available backup with its date and size.
Manual backup
You can take an extra backup at any time with the "Back up now" button — for example, before a big change.
Restoring from a backup
When you press Restore, the current state is first saved automatically as a "pre-restore backup" (so nothing is lost even if you clicked by mistake), then DATA_DIR is rolled back to the selected backup and the bot restarts briefly.
Downloading a backup
The "Download" button creates a signed link valid for 24 hours — use it to save the encrypted file to your computer. If the link has expired or been tampered with, the download will not work.
What if I use an external database?
If your bot connects to an external service such as PostgreSQL, MongoDB or Redis via DATABASE_URL, the check also treats that as "correct" — but keep in mind: Botxona only backs up DATA_DIR. Backing up the external database is entirely your responsibility.
Next step
Code rules that prevent data loss: 6 rules — rule 5. Why data survives when a bot sleeps and wakes up: Sleep and wake-up.