diff --git a/README.md b/README.md index f1dfeff..fd27141 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,11 @@ instances: backup_dir: /backups/primary retention_days: 14 schedule: "0 2 * * *" + # Optional: explicitly include or exclude specific databases + # include: + # - my_app_db + # exclude: + # - temp_db - name: secondary host: 192.168.1.20 @@ -109,6 +114,8 @@ instances: - `webhooks`: An array of webhook endpoints. Each can have its own `events` block to fire only on specific outcomes. - `logging.file`: The path where log files should be written. - `instances`: An array of MariaDB instances. Each requires its own name, connection details, backup directory, retention configuration (in days), and cron `schedule`. + - `include`: (Optional) If specified, ONLY the listed databases will be backed up. + - `exclude`: (Optional) If specified, the listed databases will be ignored. System databases are ALWAYS excluded automatically. > **Note:** Make sure the user specified in the configuration has `SELECT`, `LOCK TABLES`, `SHOW VIEW`, and `TRIGGER` permissions to properly perform `mysqldump` operations across all databases. diff --git a/backup/discover.go b/backup/discover.go index b4f4a54..794528f 100644 --- a/backup/discover.go +++ b/backup/discover.go @@ -39,6 +39,33 @@ func discoverDatabases(cfg config.InstanceConfig) ([]string, error) { if err := rows.Scan(&name); err != nil { return nil, err } + + if len(cfg.Include) > 0 { + included := false + for _, inc := range cfg.Include { + if name == inc { + included = true + break + } + } + if !included { + continue + } + } + + if len(cfg.Exclude) > 0 { + excluded := false + for _, exc := range cfg.Exclude { + if name == exc { + excluded = true + break + } + } + if excluded { + continue + } + } + databases = append(databases, name) } diff --git a/config/config.go b/config/config.go index a9ad581..064e5f3 100644 --- a/config/config.go +++ b/config/config.go @@ -59,14 +59,16 @@ type LoggingConfig struct { } type InstanceConfig struct { - Name string `yaml:"name"` - Host string `yaml:"host"` - Port int `yaml:"port"` - User string `yaml:"user"` - Password string `yaml:"password"` - BackupDir string `yaml:"backup_dir"` - RetentionDays int `yaml:"retention_days"` - Schedule string `yaml:"schedule"` + Name string `yaml:"name"` + Host string `yaml:"host"` + Port int `yaml:"port"` + User string `yaml:"user"` + Password string `yaml:"password"` + BackupDir string `yaml:"backup_dir"` + RetentionDays int `yaml:"retention_days"` + Schedule string `yaml:"schedule"` + Include []string `yaml:"include,omitempty"` + Exclude []string `yaml:"exclude,omitempty"` } func LoadConfig(path string) (*Config, error) {