feat: add include and exclude filtering options for database discovery
Build and Push / build (godump, amd64, linux) (push) Successful in 18s
Build and Push / build (godump, amd64, linux) (push) Successful in 18s
This commit is contained in:
@@ -90,6 +90,11 @@ instances:
|
|||||||
backup_dir: /backups/primary
|
backup_dir: /backups/primary
|
||||||
retention_days: 14
|
retention_days: 14
|
||||||
schedule: "0 2 * * *"
|
schedule: "0 2 * * *"
|
||||||
|
# Optional: explicitly include or exclude specific databases
|
||||||
|
# include:
|
||||||
|
# - my_app_db
|
||||||
|
# exclude:
|
||||||
|
# - temp_db
|
||||||
|
|
||||||
- name: secondary
|
- name: secondary
|
||||||
host: 192.168.1.20
|
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.
|
- `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.
|
- `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`.
|
- `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.
|
> **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.
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,33 @@ func discoverDatabases(cfg config.InstanceConfig) ([]string, error) {
|
|||||||
if err := rows.Scan(&name); err != nil {
|
if err := rows.Scan(&name); err != nil {
|
||||||
return nil, err
|
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)
|
databases = append(databases, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-8
@@ -59,14 +59,16 @@ type LoggingConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type InstanceConfig struct {
|
type InstanceConfig struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
BackupDir string `yaml:"backup_dir"`
|
BackupDir string `yaml:"backup_dir"`
|
||||||
RetentionDays int `yaml:"retention_days"`
|
RetentionDays int `yaml:"retention_days"`
|
||||||
Schedule string `yaml:"schedule"`
|
Schedule string `yaml:"schedule"`
|
||||||
|
Include []string `yaml:"include,omitempty"`
|
||||||
|
Exclude []string `yaml:"exclude,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig(path string) (*Config, error) {
|
func LoadConfig(path string) (*Config, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user