Marzban to PasarGuard
This guide is for Marzban versions beta-3
and below.
This guide will help you migrate your data, settings, and user accounts from Marzban to PasarGuard without losing anything.
Prerequisites
⚠️ Important: Always have a complete backup of your data before starting the migration process.
- Make sure you have root access to your server.
- Have a backup of your current Marzban installation.
- Check that Docker and Docker Compose are installed.
Migration Steps
1. Stop Marzban Services
First, stop all running Marzban containers:
Stop Service Commands
cd /opt/marzban
docker compose down
2. Rename Main Directory
Change the main Marzban directory name to PasarGuard:
Directory Rename Command
sudo mv /opt/marzban /opt/pasarguard
3. Rename Data Directory
Change the data directory name as well:
Data Directory Rename Command
sudo mv /var/lib/marzban /var/lib/pasarguard
4. Rename MySQL Directory (if using)
If you're using MySQL and have a dedicated directory for Marzban database:
MySQL Directory Rename Command
sudo mv /var/lib/mysql/marzban /var/lib/mysql/pasarguard
5. Update Environment Variables
Go to the new PasarGuard directory and update the environment file:
cd /opt/pasarguard
Update all paths referenced in the .env
file with a simple command:
sudo sed -i 's|/var/lib/marzban|/var/lib/pasarguard|g' .env
If you're using an older version (0.8.4 or below), you also need to change the SQL driver:
SQLite Driver Update
❌ Old
SQLALCHEMY_DATABASE_URL = "sqlite:///db.sqlite3"
✅ New
SQLALCHEMY_DATABASE_URL = "sqlite+aiosqlite:///db.sqlite3"
MySQL Driver Update
❌ Old
SQLALCHEMY_DATABASE_URL = "mysql+pymysql://root:DB_PASSWORD@127.0.0.1/pasarguard"
✅ New
SQLALCHEMY_DATABASE_URL = "mysql+asyncmy://root:DB_PASSWORD@127.0.0.1/pasarguard"
6. Update Docker Compose File
Update the docker-compose.yml
file to reflect the new paths. You need to manually edit this file:
sudo nano docker-compose.yml
Docker Compose Changes
Here's a comparison showing the necessary changes:
❌ Before (Marzban)
services:
marzban:
image: gozargah/marzban:latest
restart: always
env_file: .env
network_mode: host
volumes:
- /var/lib/marzban:/var/lib/marzban
depends_on:
- mysql
mysql:
image: mysql:lts
restart: always
env_file: .env
network_mode: host
command: --bind-address=127.0.0.1 --mysqlx-bind-address=127.0.0.1 --disable-log-bin
environment:
MYSQL_DATABASE: marzban
volumes:
- /var/lib/mysql/marzban:/var/lib/mysql
✅ After (PasarGuard)
services:
pasarguard:
image: pasarguard/panel:latest
restart: always
env_file: .env
network_mode: host
volumes:
- /var/lib/pasarguard:/var/lib/pasarguard
depends_on:
- mysql
mysql:
image: mysql:lts
restart: always
env_file: .env
network_mode: host
command: --bind-address=127.0.0.1 --mysqlx-bind-address=127.0.0.1 --disable-log-bin
environment:
MYSQL_DATABASE: marzban
volumes:
- /var/lib/mysql/pasarguard:/var/lib/mysql
Key Changes Summary:
Section | Before | After |
---|---|---|
Service Name | marzban | pasarguard |
Docker Image | gozargah/marzban:latest | pasarguard/panel:latest |
App Volume | /var/lib/marzban:/var/lib/marzban | /var/lib/pasarguard:/var/lib/pasarguard |
MySQL Volume | /var/lib/mysql/marzban:/var/lib/mysql | /var/lib/mysql/pasarguard:/var/lib/mysql |
7. Update File Permissions
Make sure you have the necessary permissions for the new directories:
Permission Update Commands
sudo chown -R $USER:$USER /opt/pasarguard
sudo chmod -R 755 /opt/pasarguard
8. Install PasarGuard Management Script
Install the PasarGuard management script for easier management:
Script Installation Command
sudo bash -c "$(curl -sL https://github.com/PasarGuard/scripts/raw/main/pasarguard.sh)" @ install-script
This script provides useful commands for managing your PasarGuard installation.
9. Start PasarGuard
Now start PasarGuard with the new configuration:
Startup Command
pasarguard up
10. Verify Migration
Check that all services are running properly:
Verification Commands
pasarguard status
Open your panel URL to make sure everything is working correctly.
Troubleshooting
Common Issues
💡 Tip: Most issues can be resolved by checking file permissions and path configurations.
1. Permission Denied Make sure you're running commands with appropriate permissions (sudo when needed).
2. Database Connection Issues If you're using MySQL, check that database paths and login information are properly updated.
3. Port Conflicts Make sure no other services are using the same ports.
4. Missing Environment Variables
Double-check that all environment variables in the .env
file are properly updated.
Rollback
⚠️ Emergency Rollback: If you encounter serious issues and need to revert to the previous version
# Stop PasarGuard
cd /opt/pasarguard
docker compose down
# Restore original directories
sudo mv /opt/pasarguard /opt/marzban
sudo mv /var/lib/pasarguard /var/lib/marzban
sudo mv /var/lib/mysql/pasarguard /var/lib/mysql/marzban # if using
# Restore original docker-compose.yml and .env files from backup
# Then start Marzban
marzban up
Post-Migration
After successful migration:
- 📊 Update Monitoring: If you have monitoring tools, connect them to the new paths.
- 💾 Update Backups: Make sure your backup scripts are updated to backup from the new directories.
- 🧪 Test All Features: Thoroughly test all panel features to ensure everything is working correctly.
Support
🔗 Links
- Discussion Group: Telegram
- Issues: If you encounter any problems during migration, create an issue.
📝 Note: This guide assumes a standard Marzban installation. Custom configurations may require additional steps.