KitDevguides

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

  1. On the old userbot: .backup. The file arrives in Saved Messages.
  2. On the new place: clone KitDev, create the .env (you can copy it by hand) and start the userbot.
  3. From Saved Messages, reply to the backup file with .restore.
  4. 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:

  • backup exports all of KitDev's tables and your settings to a .json.gz file and sends it to Saved Messages. It does not include the data/ 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 (-y skips 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...), mongodump or pg_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_backup mark 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=false in the .env it 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

  • restore only accepts .tar.gz files with paths inside data/ and checks them before applying (no paths outside data/, no links, no oversized files).
  • The confirmation uses the assistant bot. If it isn't available, .restore tells 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, restore only accepts .json.gz files 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.