Restore Procedure
Complete restore procedures for Chatty AI from backup.
Overview
This guide covers restoring Chatty AI from a backup created with the backup procedure.
What gets restored:
- PostgreSQL database (users, conversations, settings)
- Qdrant vector database (embeddings, RAG data)
- File uploads (user documents)
- Configuration files (.env, docker-compose.yaml, certificates)
Quick Restore Script
Download Restore Script
Save this script as restore-chatty.sh:
#!/bin/bash
#=================================================================
# Chatty AI Restore Script
# Restores Chatty AI from backup
#=================================================================
set -e # Exit on error
# Configuration
BACKUP_PATH="${1}"
COMPOSE_DIR="${COMPOSE_DIR:-/root/chatty-app-deploy/deploy}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if backup path provided
if [ -z "${BACKUP_PATH}" ]; then
echo -e "${RED}Error: Backup path not provided${NC}"
echo "Usage: $0 /path/to/backup"
echo "Example: $0 /root/chatty-backups/chatty-backup-20260409_140000"
exit 1
fi
# Check if backup exists
if [ ! -d "${BACKUP_PATH}" ]; then
echo -e "${RED}Error: Backup directory not found: ${BACKUP_PATH}${NC}"
exit 1
fi
echo -e "${GREEN}==================================================================${NC}"
echo -e "${GREEN}Chatty AI Restore Script${NC}"
echo -e "${GREEN}==================================================================${NC}"
echo ""
echo "Backup source: ${BACKUP_PATH}"
echo "Restore target: ${COMPOSE_DIR}"
echo ""
# Confirmation
echo -e "${YELLOW}⚠️ WARNING: This will replace all current data!${NC}"
echo -e "${YELLOW}Current data will be permanently deleted.${NC}"
echo ""
read -p "Are you sure you want to continue? (yes/no): " CONFIRM
if [ "${CONFIRM}" != "yes" ]; then
echo "Restore cancelled"
exit 0
fi
echo ""
echo -e "${YELLOW}Starting restore process...${NC}"
echo ""
# Navigate to compose directory
cd "${COMPOSE_DIR}"
# Stop services
echo -e "${YELLOW}[1/6] Stopping Chatty AI services...${NC}"
docker compose down
echo -e "${GREEN}✓ Services stopped${NC}"
echo -e "${YELLOW}[2/6] Restoring PostgreSQL database...${NC}"
# Start only database
docker compose up -d db
sleep 5
# Drop and recreate database
docker compose exec -T db psql -U chattyAdmin -d postgres -c "DROP DATABASE IF EXISTS chattydb;"
docker compose exec -T db psql -U chattyAdmin -d postgres -c "CREATE DATABASE chattydb OWNER chattyAdmin;"
# Restore database
gunzip -c "${BACKUP_PATH}"/postgres-*.sql.gz | docker compose exec -T db psql -U chattyAdmin -d chattydb
echo -e "${GREEN}✓ PostgreSQL database restored${NC}"
echo -e "${YELLOW}[3/6] Restoring Qdrant vector database...${NC}"
# Remove old Qdrant data
docker volume rm chatty-app_qdrant 2>/dev/null || true
# Restore Qdrant data
docker run --rm \
-v chatty-app_qdrant:/data \
-v "${BACKUP_PATH}":/backup \
ubuntu tar xzf /backup/qdrant-*.tar.gz -C /
echo -e "${GREEN}✓ Qdrant vector database restored${NC}"
echo -e "${YELLOW}[4/6] Restoring file uploads...${NC}"
# Restore uploads
docker run --rm \
-v chatty-app_chattyai:/data \
-v "${BACKUP_PATH}":/backup \
ubuntu tar xzf /backup/uploads-*.tar.gz -C /
echo -e "${GREEN}✓ File uploads restored${NC}"
echo -e "${YELLOW}[5/6] Restoring configuration files...${NC}"
# Restore .env if exists
if [ -f "${BACKUP_PATH}/config/.env" ]; then
cp "${BACKUP_PATH}/config/.env" .env
echo "✓ .env restored"
fi
# Restore docker-compose if exists
if [ -f "${BACKUP_PATH}/config/docker-compose.yaml" ]; then
cp "${BACKUP_PATH}/config/docker-compose.yaml" docker-compose.yaml
echo "✓ docker-compose.yaml restored"
fi
# Restore certificates if exist
if [ -d "${BACKUP_PATH}/config/certs" ]; then
cp -r "${BACKUP_PATH}/config/certs" ./
echo "✓ SSL certificates restored"
fi
echo -e "${GREEN}✓ Configuration files restored${NC}"
echo -e "${YELLOW}[6/6] Starting Chatty AI services...${NC}"
docker compose up -d
echo -e "${GREEN}✓ Services started${NC}"
echo ""
echo -e "${GREEN}==================================================================${NC}"
echo -e "${GREEN}Restore Complete!${NC}"
echo -e "${GREEN}==================================================================${NC}"
echo ""
echo -e "${YELLOW}Next steps:${NC}"
echo "1. Wait 2-3 minutes for all services to start"
echo "2. Verify services are running: docker compose ps"
echo "3. Check logs: docker compose logs"
echo "4. Test login to Chatty AI"
echo "5. Verify data integrity"
echo ""
Make Script Executable
chmod +x restore-chatty.sh
Run Restore
# Restore from backup
./restore-chatty.sh /root/chatty-backups/chatty-backup-20260409_140000
# With custom compose directory
COMPOSE_DIR=/path/to/deploy ./restore-chatty.sh /root/chatty-backups/chatty-backup-20260409_140000
Manual Restore Steps
If you prefer manual restore:
1. Stop Services
cd /root/chatty-app-deploy/deploy
docker compose down
2. Restore PostgreSQL Database
# Start only database
docker compose up -d db
sleep 5
# Drop existing database
docker compose exec db psql -U chattyAdmin -d postgres -c "DROP DATABASE IF EXISTS chattydb;"
# Create new database
docker compose exec db psql -U chattyAdmin -d postgres -c "CREATE DATABASE chattydb OWNER chattyAdmin;"
# Restore from backup
gunzip -c /root/chatty-backups/chatty-backup-20260409_140000/postgres-*.sql.gz | \
docker compose exec -T db psql -U chattyAdmin -d chattydb
# Verify restore
docker compose exec db psql -U chattyAdmin -d chattydb -c "\dt"
3. Restore Qdrant Vector Database
# Stop database service
docker compose down
# Remove old Qdrant volume
docker volume rm chatty-app_qdrant
# Restore Qdrant data
docker run --rm \
-v chatty-app_qdrant:/data \
-v /root/chatty-backups/chatty-backup-20260409_140000:/backup \
ubuntu tar xzf /backup/qdrant-*.tar.gz -C /
# Verify
docker volume inspect chatty-app_qdrant
4. Restore File Uploads
# Restore uploads
docker run --rm \
-v chatty-app_chattyai:/data \
-v /root/chatty-backups/chatty-backup-20260409_140000:/backup \
ubuntu tar xzf /backup/uploads-*.tar.gz -C /
# Verify
docker run --rm -v chatty-app_chattyai:/data ubuntu ls -la /data/uploads
5. Restore Configuration
# Restore .env
cp /root/chatty-backups/chatty-backup-20260409_140000/config/.env .env
# Restore docker-compose
cp /root/chatty-backups/chatty-backup-20260409_140000/config/docker-compose.yaml docker-compose.yaml
# Restore certificates
cp -r /root/chatty-backups/chatty-backup-20260409_140000/config/certs ./
# Verify
ls -la .env docker-compose.yaml certs/
6. Start Services
# Start all services
docker compose up -d
# Check status
docker compose ps
# View logs
docker compose logs -f
Disaster Recovery
Complete System Rebuild
If restoring to a new server:
#!/bin/bash
# disaster-recovery.sh
# 1. Install Docker
curl -fsSL https://get.docker.com | sh
# 2. Clone deployment repository
git clone https://<DEPLOY_TOKEN>@github.com/chattyai-org/chatty-app-deploy.git
cd chatty-app-deploy/deploy
# 3. Restore configuration
cp /path/to/backup/config/.env .env
cp /path/to/backup/config/docker-compose.yaml docker-compose.yaml
cp -r /path/to/backup/config/certs ./
# 4. Create volumes
docker volume create chatty-app_db_data
docker volume create chatty-app_qdrant
docker volume create chatty-app_chattyai
# 5. Run restore script
/path/to/restore-chatty.sh /path/to/backup
# 6. Verify
docker compose ps
docker compose logs
Selective Restore
Restore Only Database
#!/bin/bash
# restore-database-only.sh
BACKUP_PATH="/root/chatty-backups/chatty-backup-20260409_140000"
cd /root/chatty-app-deploy/deploy
# Stop chattyai service only
docker compose stop chattyai
# Restore database
gunzip -c "${BACKUP_PATH}"/postgres-*.sql.gz | \
docker compose exec -T db psql -U chattyAdmin -d chattydb
# Restart chattyai
docker compose start chattyai
echo "Database restored"
Restore Only Qdrant
#!/bin/bash
# restore-qdrant-only.sh
BACKUP_PATH="/root/chatty-backups/chatty-backup-20260409_140000"
cd /root/chatty-app-deploy/deploy
# Stop services using Qdrant
docker compose stop chattyai chattydatabases-ai-service qdrant
# Remove old data
docker volume rm chatty-app_qdrant
# Restore
docker run --rm \
-v chatty-app_qdrant:/data \
-v "${BACKUP_PATH}":/backup \
ubuntu tar xzf /backup/qdrant-*.tar.gz -C /
# Restart services
docker compose start qdrant chattydatabases-ai-service chattyai
echo "Qdrant restored"
Restore Only Configuration
#!/bin/bash
# restore-config-only.sh
BACKUP_PATH="/root/chatty-backups/chatty-backup-20260409_140000"
cd /root/chatty-app-deploy/deploy
# Backup current config
cp .env .env.backup
cp docker-compose.yaml docker-compose.yaml.backup
# Restore from backup
cp "${BACKUP_PATH}/config/.env" .env
cp "${BACKUP_PATH}/config/docker-compose.yaml" docker-compose.yaml
cp -r "${BACKUP_PATH}/config/certs" ./
# Restart services
docker compose down
docker compose up -d
echo "Configuration restored"
Verification After Restore
Verify Services
#!/bin/bash
# verify-restore.sh
echo "Checking services..."
docker compose ps
echo ""
echo "Checking database..."
docker compose exec db psql -U chattyAdmin -d chattydb -c "SELECT COUNT(*) FROM users;"
echo ""
echo "Checking Qdrant..."
curl -s http://localhost:6333/collections | jq
echo ""
echo "Checking Chatty AI..."
curl -s http://localhost:3000/health || curl -s https://$(grep CHATTYAI_DOMAIN .env | cut -d= -f2)/health
echo ""
echo "Verification complete"
Test Functionality
-
Login Test
# Access Chatty AI
https://chat.example.com
# Login with admin credentials
# Verify dashboard loads -
Database Test
# Check user count
docker compose exec db psql -U chattyAdmin -d chattydb -c "SELECT COUNT(*) FROM users;"
# Check conversations
docker compose exec db psql -U chattyAdmin -d chattydb -c "SELECT COUNT(*) FROM chats;" -
RAG Test
# Check Qdrant collections
curl http://localhost:6333/collections
# Verify embeddings exist -
File Upload Test
# Check uploads directory
docker run --rm -v chatty-app_chattyai:/data ubuntu ls -lh /data/uploads
Troubleshooting
Restore Fails - Database Connection
# Check database is running
docker compose ps db
# Check logs
docker compose logs db
# Restart database
docker compose restart db
sleep 10
Restore Fails - Permission Denied
# Run as root
sudo ./restore-chatty.sh /path/to/backup
# Or fix permissions
sudo chown -R $USER:$USER /root/chatty-app-deploy
Services Won't Start After Restore
# Check logs
docker compose logs
# Check .env file
cat .env
# Verify volumes
docker volume ls | grep chatty-app
# Recreate containers
docker compose down
docker compose up -d --force-recreate
Data Missing After Restore
# Verify backup contents
ls -la /path/to/backup/
# Check backup manifest
cat /path/to/backup/MANIFEST.txt
# Verify volumes
docker volume inspect chatty-app_db_data
docker volume inspect chatty-app_qdrant
docker volume inspect chatty-app_chattyai
Restore Checklist
- Backup location verified and accessible
- Backup integrity checked (all files present)
- Current data backed up (if needed)
- Services stopped successfully
- Database restored and verified
- Qdrant restored and verified
- File uploads restored and verified
- Configuration restored and verified
- Services started successfully
- Login test passed
- Data integrity verified
- Functionality tested
Related Documentation
- Backup Procedure - How to create backups
- Database Variables - Database configuration
- Service Management - Managing services from backup.