Files
dbbackup/cmd/cpu.go
Renz 0cf21cd893 feat: Complete MEDIUM priority security features with testing
- Implemented TUI auto-select for automated testing
- Fixed TUI automation: autoSelectMsg handling in Update()
- Auto-database selection in DatabaseSelector
- Created focused test suite (test_as_postgres.sh)
- Created retention policy test (test_retention.sh)
- All 10 security tests passing

Features validated:
 Backup retention policy (30 days, min backups)
 Rate limiting (exponential backoff)
 Privilege checks (root detection)
 Resource limit validation
 Path sanitization
 Checksum verification (SHA-256)
 Audit logging
 Secure permissions
 Configuration persistence
 TUI automation framework

Test results: 10/10 passed
Backup files created with .dump, .sha256, .info
Retention cleanup verified (old files removed)
2025-11-25 15:25:56 +00:00

76 lines
2.2 KiB
Go
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"context"
"fmt"
"github.com/spf13/cobra"
)
var cpuCmd = &cobra.Command{
Use: "cpu",
Short: "Show CPU information and optimization settings",
Long: `Display detailed CPU information and current parallelism configuration.`,
RunE: func(cmd *cobra.Command, args []string) error {
return runCPUInfo(cmd.Context())
},
}
func runCPUInfo(ctx context.Context) error {
log.Info("Detecting CPU information...")
// Optimize CPU settings if auto-detect is enabled
if cfg.AutoDetectCores {
if err := cfg.OptimizeForCPU(); err != nil {
log.Warn("CPU optimization failed", "error", err)
}
}
// Get CPU information
cpuInfo, err := cfg.GetCPUInfo()
if err != nil {
return fmt.Errorf("failed to detect CPU: %w", err)
}
fmt.Println("=== CPU Information ===")
fmt.Print(cpuInfo.FormatCPUInfo())
fmt.Println("\n=== Current Configuration ===")
fmt.Printf("Auto-detect cores: %t\n", cfg.AutoDetectCores)
fmt.Printf("CPU workload type: %s\n", cfg.CPUWorkloadType)
fmt.Printf("Parallel jobs (restore): %d\n", cfg.Jobs)
fmt.Printf("Dump jobs (backup): %d\n", cfg.DumpJobs)
fmt.Printf("Maximum cores limit: %d\n", cfg.MaxCores)
// Show optimization recommendations
fmt.Println("\n=== Optimization Recommendations ===")
if cpuInfo.PhysicalCores > 1 {
if cfg.CPUWorkloadType == "balanced" {
optimal, _ := cfg.CPUDetector.CalculateOptimalJobs("balanced", cfg.MaxCores)
fmt.Printf("Recommended jobs (balanced): %d\n", optimal)
}
if cfg.CPUWorkloadType == "io-intensive" {
optimal, _ := cfg.CPUDetector.CalculateOptimalJobs("io-intensive", cfg.MaxCores)
fmt.Printf("Recommended jobs (I/O intensive): %d\n", optimal)
}
if cfg.CPUWorkloadType == "cpu-intensive" {
optimal, _ := cfg.CPUDetector.CalculateOptimalJobs("cpu-intensive", cfg.MaxCores)
fmt.Printf("Recommended jobs (CPU intensive): %d\n", optimal)
}
}
// Show current vs optimal
if cfg.AutoDetectCores {
fmt.Println("\n✅ CPU optimization is enabled")
fmt.Println("Job counts are automatically optimized based on detected hardware")
} else {
fmt.Println("\n⚠ CPU optimization is disabled")
fmt.Println("Consider enabling --auto-detect-cores for better performance")
}
return nil
}
func init() {
rootCmd.AddCommand(cpuCmd)
}