Audience: Lab Operator Prerequisites: Backup & Recovery Time: ~20 minutes
Overview¶
Keeping MADSci up to date ensures you have the latest features, bug fixes, and security patches. This guide covers upgrade procedures, database migrations, and routine maintenance tasks.
Checking for Updates¶
Current Version¶
# Check installed MADSci version
madsci version
# Check all installed package versions
pip list | grep madsciAvailable Updates¶
Check the MADSci releases page for new versions and changelogs.
Upgrade Procedure¶
Step 1: Read the Changelog¶
Before upgrading, review the changelog for:
Breaking changes that require configuration updates
Database migrations that need to be run
Deprecation notices for features being removed
New dependencies that may need to be installed
Step 2: Create Backups¶
Always back up before upgrading:
# Back up all databases
madsci-postgres-backup create \
--db-url postgresql://postgres:postgres@localhost:5432/resources \
--backup-dir ./backups/pre-upgrade
for db in events experiments data workcell locations; do
madsci-mongodb-backup create \
--mongo-url mongodb://localhost:27017 \
--database $db \
--backup-dir ./backups/pre-upgrade/mongodb
doneStep 3: Stop Services¶
# Stop all services
docker compose downStep 4: Update Code¶
# If using git (development install)
git pull origin main
pdm install -G:all
# If using pip (released packages)
pip install --upgrade madsci_common madsci_client madsci_node_module \
madsci_squid madsci_event_manager madsci_experiment_manager \
madsci_resource_manager madsci_data_manager madsci_workcell_manager \
madsci_location_manager madsci_experiment_applicationStep 5: Rebuild Docker Images¶
# Rebuild all images
docker compose build
# Or rebuild specific services
docker compose build workcell_manager event_managerStep 6: Run Database Migrations¶
# PostgreSQL migrations (Resource Manager)
python -m madsci.resource_manager.migration_tool \
--db-url postgresql://postgres:postgres@localhost:5432/resources
# MongoDB migrations (per manager, if needed)
# Check release notes for specific migration commandsStep 7: Start Services¶
# Start all services
docker compose up -d
# Verify health
madsci status
# Check for migration warnings
madsci logs --level WARNING --tail 50Step 8: Verify¶
# Run diagnostics
madsci doctor
# Test a simple workflow
# (Use your lab's standard smoke test)Database Migrations¶
PostgreSQL Migrations¶
The Resource Manager uses Alembic for schema migrations:
# Check current migration status
python -m madsci.resource_manager.migration_tool --status \
--db-url postgresql://postgres:postgres@localhost:5432/resources
# Run pending migrations
python -m madsci.resource_manager.migration_tool \
--db-url postgresql://postgres:postgres@localhost:5432/resourcesThe migration tool automatically:
Creates a backup before migrating
Restores the backup if migration fails
Reports success/failure
MongoDB Migrations¶
MongoDB managers handle index creation and schema validation on startup. Specific migrations are documented in release notes.
Definition File Migration¶
If upgrading from a version that uses definition files (pre-v0.7.0):
# Scan for files needing migration
madsci migrate scan
# Preview migration
madsci migrate convert --dry-run
# Apply migration
madsci migrate convert --apply
# Verify
madsci migrate status
# After confirming everything works, clean up
madsci migrate finalizeRoutine Maintenance¶
Log Rotation¶
MADSci event logs grow over time. Configure retention:
# Environment variable for Event Manager
EVENT_RETENTION_DAYS=90
EVENT_ARCHIVE_ENABLED=true
EVENT_ARCHIVE_DIR=/data/event_archivesDatabase Maintenance¶
MongoDB¶
# Check database sizes
docker compose exec mongodb mongosh --eval "
db.adminCommand('listDatabases').databases.forEach(function(d) {
print(d.name + ': ' + (d.sizeOnDisk / 1024 / 1024).toFixed(2) + ' MB');
});
"
# Compact a collection (reclaim disk space)
docker compose exec mongodb mongosh events --eval "
db.runCommand({compact: 'events'})
"PostgreSQL¶
# Check database size
docker compose exec postgres psql -U postgres -c "
SELECT pg_database.datname,
pg_size_pretty(pg_database_size(pg_database.datname))
FROM pg_database
ORDER BY pg_database_size(pg_database.datname) DESC;
"
# Run vacuum (reclaim space, update statistics)
docker compose exec postgres psql -U postgres -d resources -c "VACUUM ANALYZE;"Docker Cleanup¶
# Remove unused images
docker image prune
# Remove unused volumes (careful - don't remove data volumes!)
docker volume prune --filter "label!=keep"
# Remove build cache
docker builder prune
# Full cleanup (stopped containers, unused images, unused networks)
docker system pruneDisk Space Monitoring¶
# Check overall disk usage
df -h
# Check Docker disk usage
docker system df
# Find large log files
find /var/lib/docker/containers -name "*.log" -size +100M
# Truncate a large container log (if needed)
truncate -s 0 /var/lib/docker/containers/<container_id>/<container_id>-json.logRollback Procedure¶
If an upgrade causes issues:
Step 1: Stop Services¶
docker compose downStep 2: Restore Code¶
# If using git
git checkout <previous_version_tag>
pdm install -G:all
# If using pip
pip install madsci_common==<previous_version> ...Step 3: Restore Database (if migrations were run)¶
# Restore PostgreSQL
madsci-postgres-backup restore \
--db-url postgresql://postgres:postgres@localhost:5432/resources \
--backup-path ./backups/pre-upgrade/resources_backup.sql
# Restore MongoDB
for db in events experiments data workcell locations; do
madsci-mongodb-backup restore \
--mongo-url mongodb://localhost:27017 \
--database $db \
--backup-path ./backups/pre-upgrade/mongodb/${db}_backup.bson
doneStep 4: Rebuild and Restart¶
docker compose build
docker compose up -d
madsci statusMaintenance Schedule¶
| Task | Frequency | Command |
|---|---|---|
| Health check | Continuous | madsci status --watch |
| Log review | Daily | madsci logs --level WARNING --since 24h |
| Database backup | Every 6 hours | Automated via cron |
| Backup validation | Weekly | Restore to test environment |
| Disk space check | Weekly | df -h && docker system df |
| Docker cleanup | Monthly | docker system prune |
| MADSci update | As released | Follow upgrade procedure |
| Full recovery test | Quarterly | Restore from backup to clean environment |
What’s Next?¶
Daily Operations - Day-to-day lab management
Monitoring - Set up proactive monitoring
Troubleshooting - When things go wrong