Come eseguire il backup di PostgreSql DB in Laravel
-
installa il pacchetto laravel usando il compositore.
composer require spatie/laravel-backup
-
inserisci la seguente riga nel tuo controller di backup.
use Spatie\DbDumper\Databases\PostgreSql;
-
scrivi il seguente codice nel tuo controller di backup.
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.'); }