68 lines
2.5 KiB
PHP
68 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Support\Str;
|
|
use App\Models\BackupPolicy;
|
|
|
|
class SystemBackupSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
// Defaults kommen jetzt aus config/backup.php
|
|
$enabled = false; // UI schaltet das später; Standard: aus
|
|
$cron = (string) config('backup.default_cron', '0 3 * * *');
|
|
$targetType = 'local';
|
|
$targetPath = (string) config('backup.local_path', '/var/backups/mailwolt');
|
|
$retentionCount = (int) config('backup.retention', 7);
|
|
|
|
// Falls du optional per ENV überschreiben willst (nicht nötig, aber möglich):
|
|
$cron = env('BACKUP_DEFAULT_CRON', $cron);
|
|
$targetPath = env('BACKUP_DIR', $targetPath);
|
|
$retentionCount = (int) env('BACKUP_RETENTION_COUNT', $retentionCount);
|
|
$targetType = Str::lower(env('BACKUP_TARGET_TYPE', $targetType)) === 's3' ? 's3' : 'local';
|
|
|
|
// optionale S3/MinIO-Parameter (nur wenn target_type = s3)
|
|
$s3Bucket = env('BACKUP_S3_BUCKET');
|
|
$s3Region = env('BACKUP_S3_REGION');
|
|
$s3Endpoint = env('BACKUP_S3_ENDPOINT');
|
|
$s3Key = env('BACKUP_S3_KEY');
|
|
$s3Secret = env('BACKUP_S3_SECRET');
|
|
|
|
$policy = BackupPolicy::query()->firstOrCreate(
|
|
['name' => 'Standard'],
|
|
['enabled' => false]
|
|
);
|
|
|
|
$payload = [
|
|
'enabled' => $enabled,
|
|
'schedule_cron' => $cron,
|
|
'target_type' => $targetType, // 'local' | 's3'
|
|
'target_path' => $targetPath, // bei local: Verzeichnis
|
|
'retention_count' => $retentionCount,
|
|
];
|
|
|
|
if ($targetType === 's3') {
|
|
$payload = array_merge($payload, [
|
|
's3_bucket' => $s3Bucket,
|
|
's3_region' => $s3Region,
|
|
's3_endpoint' => $s3Endpoint,
|
|
's3_key_enc' => $s3Key ? Crypt::encryptString($s3Key) : $policy->s3_key_enc,
|
|
's3_secret_enc' => $s3Secret ? Crypt::encryptString($s3Secret) : $policy->s3_secret_enc,
|
|
]);
|
|
} else {
|
|
$payload = array_merge($payload, [
|
|
's3_bucket' => null,
|
|
's3_region' => null,
|
|
's3_endpoint' => null,
|
|
's3_key_enc' => null,
|
|
's3_secret_enc' => null,
|
|
]);
|
|
}
|
|
|
|
$policy->fill($payload)->save();
|
|
}
|
|
}
|