Maintenance
Backup and Recovery
Flow Backup
bash
# Manual backup
cp ~/.node-red/flows.json ~/.node-red/flows.json.bak
# Automated backup script
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backup/node-red"
mkdir -p $BACKUP_DIR
cp -r ~/.node-red $BACKUP_DIR/node-red-$DATE
Database Backup
bash
# MySQL backup
mysqldump -u username -p database_name > node_red_backup.sql
# MongoDB backup
mongodump --host localhost --port 27017 --db node_red --out /backup/mongodb/
Updates and Patches
Node-RED Core Updates
bash
# Check current version
node-red --version
# Update to latest version
npm update -g node-red
# Update to specific version
npm install -g node-red@4.0.3
Node Package Updates
bash
# List installed packages
npm list -g --depth=0
# Update specific package
npm update -g node-red-contrib-package-name
# Update all packages
npm update -g
Maintenance Tasks
Log Rotation
bash
# Logrotate configuration
/var/log/node-red/*.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 node-red node-red
postrotate
systemctl reload node-red
endscript
}
Performance Optimization
bash
# Clear npm cache
npm cache clean --force
# Optimize Node.js heap
export NODE_OPTIONS="--optimize-for-size --max-old-space-size=2048"
# Clean temporary files
find /tmp -name "node-*" -type d -exec rm -rf {} +
Security Maintenance
Security Updates
bash
# Check for vulnerabilities
npm audit
# Fix vulnerabilities
npm audit fix
# Update security-related packages
npm update express helmet cors
Access Control Review
javascript
// Regular access control audit
{
"users": [
{
"username": "admin",
"permissions": ["*"],
"lastLogin": "2024-01-15T10:30:00Z",
"status": "active"
}
],
"apiKeys": [
{
"keyId": "key-123",
"permissions": ["read"],
"lastUsed": "2024-01-15T09:30:00Z",
"expiresAt": "2024-06-15T00:00:00Z"
}
]
}