Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragnarok22/telegram-bot-api-docker/llms.txt
Use this file to discover all available pages before exploring further.
Migration Scenarios
You may need to move your bot between self-hosted servers in several situations:- Infrastructure changes: Migrating to new hardware or cloud providers
- Disaster recovery: Moving to a backup server after an outage
- Load balancing: Redistributing bots across multiple server instances
- Environment transitions: Moving from development to production
Understanding the Data Directory
Each bot stores its data in a subdirectory named after the bot’s user ID within the server’s working directory (default:/data).
The bot user ID is different from the bot token. You can find it by calling
getMe on your bot or extracting it from the first part of your bot token (before the colon).Migration Procedure
Call logOut on the old server
First, deregister your bot from the current server by calling logOut:This prevents the old server from receiving any new updates and prepares the bot for migration.
Optional: Clean up webhook and close connection
To minimize update loss during migration, perform these additional cleanup steps:
Calling deleteWebhook and close helps ensure a clean shutdown and reduces the risk of losing updates during the transition.
Stop the old server container
Ensure the old server is fully stopped before moving data:This prevents file corruption during the data transfer.
Transfer the bot subdirectory
Move the bot’s data directory from the old server to the new server.If servers are on the same host:If servers are on different hosts:Using Docker volumes:
Start the new server
Launch the Telegram Bot API server on the new host:The server will automatically detect the existing bot data in the transferred subdirectory.
Verification Steps
After completing the migration, verify everything is working correctly:Test file access
If your bot stores files, verify they are accessible:Send a file to your bot and ensure it’s stored correctly in the new location.
Preventing Update Loss
To minimize the risk of losing updates during migration:- Schedule during low-activity periods: Migrate when your bot has minimal traffic
- Use close method: Call
closebeforelogOutto gracefully shut down the connection - Quick transition: Minimize the time between logging out of the old server and starting the new one
- Monitor update IDs: Track the last received update ID before and after migration to detect any gaps
- Test in development: Practice the migration process with a test bot first
Telegram’s update delivery system is designed to be resilient. Brief disconnections during migration typically don’t result in lost updates, as Telegram will retry delivery to the new server once it’s online.
Rollback Procedure
If issues arise after migration, you can roll back to the old server:Common Issues
- Permission denied errors: Ensure the bot subdirectory has correct ownership (UID 1000 for the
botapiuser) - Bot data not found: Verify the subdirectory name matches the bot’s user ID exactly
- Updates not arriving: Confirm you called
logOuton the old server and the new server is properly started - File paths broken: If using local mode, ensure
TELEGRAM_LOCALis set consistently on the new server
Next Steps
- Review environment variables for server configuration
- Set up health checks for your new server
- Configure volume mounts to protect bot data