Cara Mencadangkan DB PostgreSql Di Laravel
-
instal paket laravel menggunakan komposer.
composer require spatie/laravel-backup
-
masukkan baris berikut ke pengontrol cadangan Anda.
use Spatie\DbDumper\Databases\PostgreSql;
-
tulis kode berikut di pengontrol cadangan Anda.
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.'); }