277 lines
6.4 KiB
Text
277 lines
6.4 KiB
Text
|
|
"""
|
||
|
|
Example Backup Configuration in KCL
|
||
|
|
|
||
|
|
This demonstrates how to define backup configurations using the KCL schema
|
||
|
|
for integration with the prov-ecosystem provisioning system.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import backup
|
||
|
|
|
||
|
|
# Simple local backup example
|
||
|
|
simple_local_backup = backup.BackupConfig {
|
||
|
|
version = "1.0"
|
||
|
|
name = "local-backup"
|
||
|
|
description = "Simple daily local backup"
|
||
|
|
backend = "tar"
|
||
|
|
|
||
|
|
repository = {
|
||
|
|
type = "local"
|
||
|
|
path = "/mnt/backups/local"
|
||
|
|
}
|
||
|
|
|
||
|
|
targets = [
|
||
|
|
{
|
||
|
|
name = "home"
|
||
|
|
paths = ["/home/user/documents", "/home/user/projects"]
|
||
|
|
excludes = ["node_modules/*", ".git/*", "*.tmp"]
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
retention = {
|
||
|
|
keep_daily = 7
|
||
|
|
}
|
||
|
|
|
||
|
|
schedule = {
|
||
|
|
enabled = true
|
||
|
|
cron = "0 3 * * *"
|
||
|
|
init_system = "cron"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Cloud backup with encryption
|
||
|
|
cloud_encrypted_backup = backup.BackupConfig {
|
||
|
|
version = "1.0"
|
||
|
|
name = "cloud-backup"
|
||
|
|
description = "Encrypted backup to cloud storage"
|
||
|
|
backend = "restic"
|
||
|
|
|
||
|
|
repository = {
|
||
|
|
type = "s3"
|
||
|
|
path = "s3://company-backups/prod"
|
||
|
|
password_file = "/etc/backup/restic.pwd"
|
||
|
|
env_vars = {
|
||
|
|
"AWS_ACCESS_KEY_ID" = env("AWS_KEY_ID")
|
||
|
|
"AWS_SECRET_ACCESS_KEY" = env("AWS_SECRET_KEY")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
targets = [
|
||
|
|
{
|
||
|
|
name = "app-data"
|
||
|
|
paths = ["/var/lib/myapp", "/etc/myapp"]
|
||
|
|
excludes = ["*.tmp", "*.log", "cache/*"]
|
||
|
|
tags = ["production"]
|
||
|
|
pre_hooks = ["systemctl stop myapp"]
|
||
|
|
post_hooks = ["systemctl start myapp"]
|
||
|
|
}
|
||
|
|
{
|
||
|
|
name = "database"
|
||
|
|
paths = ["/var/lib/postgresql"]
|
||
|
|
excludes = ["pg_wal/*"]
|
||
|
|
tags = ["production", "critical"]
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
retention = {
|
||
|
|
keep_daily = 7
|
||
|
|
keep_weekly = 4
|
||
|
|
keep_monthly = 12
|
||
|
|
keep_yearly = 5
|
||
|
|
}
|
||
|
|
|
||
|
|
schedule = {
|
||
|
|
enabled = true
|
||
|
|
cron = "0 */6 * * *" # Every 6 hours
|
||
|
|
init_system = "systemd"
|
||
|
|
on_failure = "notify"
|
||
|
|
}
|
||
|
|
|
||
|
|
hooks = {
|
||
|
|
on_error = [
|
||
|
|
"mail -s 'Backup failed' ops@company.com"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
notifications = {
|
||
|
|
enabled = true
|
||
|
|
on_failure = true
|
||
|
|
command = "curl -X POST https://slack.com/webhook"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Multi-target rsync backup
|
||
|
|
rsync_backup = backup.BackupConfig {
|
||
|
|
version = "1.0"
|
||
|
|
name = "rsync-backup"
|
||
|
|
description = "Fast incremental sync backup"
|
||
|
|
backend = "rsync"
|
||
|
|
|
||
|
|
repository = {
|
||
|
|
type = "sftp"
|
||
|
|
path = "sftp://backup.internal/backups"
|
||
|
|
env_vars = {
|
||
|
|
"RSYNC_RSH" = "ssh -i /etc/backup/id_rsa"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
targets = [
|
||
|
|
{
|
||
|
|
name = "web-content"
|
||
|
|
paths = ["/var/www/html", "/var/www/uploads"]
|
||
|
|
excludes = ["*.temp", "cache/*", ".git"]
|
||
|
|
tags = ["web"]
|
||
|
|
}
|
||
|
|
{
|
||
|
|
name = "configs"
|
||
|
|
paths = ["/etc", "/opt/app"]
|
||
|
|
excludes = ["/etc/ssl/private"]
|
||
|
|
tags = ["system"]
|
||
|
|
}
|
||
|
|
{
|
||
|
|
name = "home"
|
||
|
|
paths = ["/home"]
|
||
|
|
excludes = ["/home/*/Downloads/*", ".cache/*"]
|
||
|
|
tags = ["users"]
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
retention = {
|
||
|
|
keep_daily = 7
|
||
|
|
keep_weekly = 4
|
||
|
|
}
|
||
|
|
|
||
|
|
schedule = {
|
||
|
|
enabled = true
|
||
|
|
cron = "30 1 * * *"
|
||
|
|
init_system = "systemd"
|
||
|
|
on_failure = "notify"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# BorgBackup with comprehensive retention
|
||
|
|
borg_backup = backup.BackupConfig {
|
||
|
|
version = "1.0"
|
||
|
|
name = "borg-backup"
|
||
|
|
description = "Comprehensive backup with space-efficient deduplication"
|
||
|
|
backend = "borg"
|
||
|
|
|
||
|
|
repository = {
|
||
|
|
type = "local"
|
||
|
|
path = "/mnt/backups/borg-repo"
|
||
|
|
password_file = "/etc/backup/borg.pwd"
|
||
|
|
}
|
||
|
|
|
||
|
|
targets = [
|
||
|
|
{
|
||
|
|
name = "system-critical"
|
||
|
|
paths = ["/etc", "/root", "/var/www"]
|
||
|
|
excludes = [
|
||
|
|
"/etc/ssl/private",
|
||
|
|
"/root/.ssh/keys",
|
||
|
|
"**/.*",
|
||
|
|
"*.tmp"
|
||
|
|
]
|
||
|
|
tags = ["critical", "system"]
|
||
|
|
pre_hooks = ["echo 'Starting critical backup'"]
|
||
|
|
}
|
||
|
|
{
|
||
|
|
name = "user-data"
|
||
|
|
paths = ["/home"]
|
||
|
|
excludes = [
|
||
|
|
"*/.cache/*",
|
||
|
|
"*/Downloads/*",
|
||
|
|
"*/.local/share/Trash/*",
|
||
|
|
"*.tmp"
|
||
|
|
]
|
||
|
|
tags = ["user"]
|
||
|
|
}
|
||
|
|
{
|
||
|
|
name = "application"
|
||
|
|
paths = ["/opt/app", "/var/lib/app"]
|
||
|
|
excludes = ["*.log", "temp/*"]
|
||
|
|
tags = ["app"]
|
||
|
|
pre_hooks = ["systemctl stop app || true"]
|
||
|
|
post_hooks = ["systemctl start app || true"]
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
retention = {
|
||
|
|
keep_last = 20
|
||
|
|
keep_hourly = 24
|
||
|
|
keep_daily = 7
|
||
|
|
keep_weekly = 4
|
||
|
|
keep_monthly = 12
|
||
|
|
keep_yearly = 5
|
||
|
|
keep_tags = ["important", "release"]
|
||
|
|
}
|
||
|
|
|
||
|
|
schedule = {
|
||
|
|
enabled = true
|
||
|
|
cron = "0 */4 * * *" # Every 4 hours
|
||
|
|
init_system = "auto" # Auto-detect best system
|
||
|
|
on_failure = "notify"
|
||
|
|
}
|
||
|
|
|
||
|
|
hooks = {
|
||
|
|
pre_backup = [
|
||
|
|
"echo 'Backup started' | systemd-cat -t borg-backup -p info"
|
||
|
|
]
|
||
|
|
post_backup = [
|
||
|
|
"borg compact || true"
|
||
|
|
]
|
||
|
|
on_error = [
|
||
|
|
"systemd-cat -t borg-backup -p err <<< 'Backup failed'"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
notifications = {
|
||
|
|
enabled = true
|
||
|
|
on_success = false
|
||
|
|
on_failure = true
|
||
|
|
command = "mail -s 'Borg Backup Failure' admin@company.com"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Development machine backup (simple)
|
||
|
|
dev_backup = backup.BackupConfig {
|
||
|
|
version = "1.0"
|
||
|
|
name = "dev-machine"
|
||
|
|
description = "Development machine local backup"
|
||
|
|
backend = "cpio"
|
||
|
|
|
||
|
|
repository = {
|
||
|
|
type = "local"
|
||
|
|
path = "/home/developer/backups"
|
||
|
|
}
|
||
|
|
|
||
|
|
targets = [
|
||
|
|
{
|
||
|
|
name = "projects"
|
||
|
|
paths = ["/home/developer/projects"]
|
||
|
|
excludes = [
|
||
|
|
"*/node_modules",
|
||
|
|
"*/.git",
|
||
|
|
"*/.venv",
|
||
|
|
"*/target",
|
||
|
|
"*.o",
|
||
|
|
"*.pyc"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
{
|
||
|
|
name = "documents"
|
||
|
|
paths = ["/home/developer/Documents"]
|
||
|
|
excludes = ["*.temp", ".~*"]
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
retention = {
|
||
|
|
keep_daily = 30
|
||
|
|
}
|
||
|
|
|
||
|
|
schedule = {
|
||
|
|
enabled = true
|
||
|
|
cron = "0 22 * * *" # 10 PM daily
|
||
|
|
init_system = "cron"
|
||
|
|
}
|
||
|
|
}
|