Sådan sikkerhedskopieres PostgreSql DB i Laravel
-
installer laravel-pakken ved hjælp af composer.
composer require spatie/laravel-backup
-
indsæt følgende linje i din backup-controller.
use Spatie\DbDumper\Databases\PostgreSql;
-
skriv følgende kode i din 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.'); }