Database ve File Backup Stratejileri: Veri Güvenliği Rehberi
z
zafer ak
Yazar
07 November 2025
2 dakika okuma
2 görüntülenme
Backup stratejileri, Laravel backup package, AWS S3 ve disaster recovery. Automated backup ve restore prosedürleri.
Backup Neden Önemli?
Veri kaybı, işletmeler için felaket olabilir. Hardware arızası, ransomware, insan hatası - backup'sız recovery imkansız.
3-2-1 Backup Kuralı
- 3: En az 3 kopya veri
- 2: 2 farklı medya türü
- 1: 1 kopya offsite (uzak lokasyon)
Laravel Backup Package
# Installation
composer require spatie/laravel-backup
# Config publish
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
// config/backup.php
'backup' => [
'name' => env('APP_NAME'),
'source' => [
'files' => [
'include' => [base_path()],
'exclude' => [
base_path('vendor'),
base_path('node_modules'),
],
],
'databases' => ['mysql'],
],
'destination' => [
'disks' => ['s3'],
],
]
Scheduled Backups
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->daily()->at('02:00');
$schedule->command('backup:clean')->daily()->at('03:00');
$schedule->command('backup:monitor')->daily()->at('04:00');
}
S3 Konfigürasyonu
# .env
AWS_ACCESS_KEY_ID=xxx
AWS_SECRET_ACCESS_KEY=xxx
AWS_DEFAULT_REGION=eu-central-1
AWS_BUCKET=my-backups
// config/filesystems.php
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
]
Manual Database Backup
# MySQL dump
mysqldump -u user -p database > backup.sql
# Restore
mysql -u user -p database < backup.sql
# Compressed
mysqldump -u user -p database | gzip > backup.sql.gz
# PostgreSQL
pg_dump -U user database > backup.sql
psql -U user database < backup.sql
Retention Policy
// config/backup.php
'cleanup' => [
'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,
'default_strategy' => [
'keep_all_backups_for_days' => 7,
'keep_daily_backups_for_days' => 16,
'keep_weekly_backups_for_weeks' => 8,
'keep_monthly_backups_for_months' => 4,
'keep_yearly_backups_for_years' => 2,
],
]
Monitoring ve Alerting
// Slack notification
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification::class => ['slack'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessfulNotification::class => ['slack'],
],
'slack' => [
'webhook_url' => env('BACKUP_SLACK_WEBHOOK_URL'),
],
]
Restore Prosedürü
# S3'ten indir
aws s3 cp s3://bucket/backup.zip .
# Extract
unzip backup.zip
# Database restore
mysql -u user -p database < db-dumps/mysql-database.sql
# Files restore
rsync -av storage/ /var/www/app/storage/
Test Your Backups!
Backup'ın değeri restore edilebildiğinde ortaya çıkar. Düzenli restore testleri yapın.
Sonuç
Automated backup, disaster recovery'nin temelidir. Laravel Backup package ve S3 kombinasyonu güvenilir çözüm sunar.