So sichern Sie die PostgreSql-DB in Laravel
-
Laravel-Paket mit Composer installieren.
composer require spatie/laravel-backup
-
Fügen Sie die folgende Zeile in Ihren Backup-Controller ein.
use Spatie\DbDumper\Databases\PostgreSql;
-
Schreiben Sie den folgenden Code in Ihren Backup-Controller.
date_default_timezone_set('EST'); try { $this->info('The backup has been started'); $backup_name = 'backup-' . date('c') . '.sql'; $backup_path = 'app/backups/' . $backup_name; PostgreSql::create() ->setDbName(env('DB_DATABASE')) ->setUserName(env('DB_USERNAME')) ->setPassword(env('DB_PASSWORD')) ->dumpToFile($backup_path); $this->info('The backup has been proceed successfully.'); } catch (ProcessFailedException $exception) { logger()->error('Backup exception', compact('exception')); $this->error('The backup process has been failed.'); }