Hur man säkerhetskopierar PostgreSql DB i Laravel
-
installera laravel-paketet med composer.
composer require spatie/laravel-backup
-
infoga följande rad i din backup-kontroller.
use Spatie\DbDumper\Databases\PostgreSql;
-
skriv följande kod i din reservkontroll.
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.'); }