KitDev / Guides / Backup and migration
Backup and migration
To move to another VPS or to Termux without losing your data, use these two commands.
| Command | What it does |
|---|---|
backup |
Creates a file with your data and sends it to Saved Messages |
restore [-y] |
Replying to that file, restores it and restarts the userbot. It first asks for confirmation with buttons; with -y it skips it |
What it includes
Everything in the data/ folder: settings and language, database (bot users, warnings, gban list, people with sudo), installed addons and media (photos, GIFs and videos of the menu, welcome and PM Permit).
It does not include the .env: that is where your session is, and it's better not to send it over Telegram. It doesn't include data/cache/ either (the deployment message's animation), which regenerates by itself.
If you use MongoDB or PostgreSQL instead of SQLite, your data is not in data/: .backup and .restore work with a different file (see With MongoDB or PostgreSQL) and the automatic backups are not used.
Moving step by step
- On the old userbot:
.backup. The file arrives in Saved Messages. - On the new place: clone KitDev, create the
.env(you can copy it by hand) and start the userbot. - From Saved Messages, reply to the backup file with
.restore. - The assistant warns you with buttons that your whole
data/folder will be replaced (database, settings, bot token and addons). Tap Yes, restore and KitDev restarts and applies the backup. You now have everything as it was.
Don't run the old and the new userbot at the same time with the same SESSION_STRING: Telegram closes the session. Stop the old one before using the new one.
With MongoDB or PostgreSQL
If you use MongoDB or PostgreSQL, backup and restore also work, but with the database instead of the data/ folder:
backupexports all of KitDev's tables and your settings to a.json.gzfile and sends it to Saved Messages. It does not include thedata/folder (addons and media, which stay local) or the.env. It carries your settings, including the assistant bot's token: don't share it.restore [-y], replying to that file, replaces those tables and your settings in the database and restarts the userbot. First it asks for confirmation with buttons (-yskips it) and sends you a copy of what was there to Saved Messages; if it can't save it, nothing is restored.- Tables that the file does not carry are not touched. The file can be up to 256 MB uncompressed.
- With PostgreSQL the restore is all or nothing: if it fails, nothing changes. MongoDB doesn't have that guarantee: if it fails halfway, restore the previous copy.
- It also works for switching engines: a backup made with PostgreSQL restores into MongoDB and the other way round (tested with a simulated MongoDB).
- The automatic backups are not needed: the remote database keeps your data even if the server restarts. You can also use your provider's backups (Atlas, Supabase, Neon...),
mongodumporpg_dump.
Automatic backups
Besides .backup, KitDev can send a copy of data/ to the logs group by itself every time your data changes. They come turned on.
- When it is sent: every 5 minutes KitDev checks whether anything changed (by the size and date of the files, without reading them). If something changed and the minimum time you choose has passed, it sends a copy. Another one is sent when it shuts down, even if that time hasn't passed.
- How many are kept: the last 5. Older ones are deleted from the group.
- The panel:
/start→ ⚙️ Settings → 💾 Backups. There you turn them on or off, choose how often (30 min, 1 h, 6 h or 24 h; 1 h by default), see when the last one was and can tap 📤 Send now. - How to recognize them: your account sends them with the
#kitdev_backupmark in the text. To restore one by hand, reply to the file with.restore, just like with a.backup.
Restoring by themselves on startup
If on startup there is no data (a new or wiped disk, like on every Heroku restart) and you have LOG_CHAT_ID in the .env, KitDev looks in that group for the latest valid automatic backup and restores it before loading anything. If there is none, it starts from scratch.
- With
AUTO_RESTORE=falsein the.envit never does it. - It doesn't act if there is already data, or if a restore is pending.
- If you turn off the backups in the panel, the ones already in the group stay there and could be restored. If you don't want that, also set
AUTO_RESTORE=false. - What changed after the last backup is lost: at most, the minimum time you chose.
Security
restoreonly accepts.tar.gzfiles with paths insidedata/and checks them before applying (no paths outsidedata/, no links, no oversized files).- The confirmation uses the assistant bot. If it isn't available,
.restoretells you and you can use.restore -y. If you cancel, or don't answer in 5 minutes, nothing is restored and the downloaded file is deleted. - Your previous data is not deleted: it stays in
data.old-<date>(the last two are kept). - The backup is applied on restart, not while the userbot is running, so the database isn't touched while it's open.
- With a remote database,
restoreonly accepts.json.gzfiles with KitDev's format and checks the tables, columns and values before touching the database; nothing in the file is run as SQL. - The automatic backups carry your settings (including the bot's token) and your contacts' data. The logs group has to be only yours and your assistant bot's: don't add anyone else.