备份与在Windows 7中使用laravel还原PostgreSQL数据库并设置localhost环境 [英] Backup & Restore PostgreSQL database and setup localhost environment with laravel in windows 7

查看:62
本文介绍了备份与在Windows 7中使用laravel还原PostgreSQL数据库并设置localhost环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)打开C:\ Program Files \ PostgreSQL \ 12 \ data \ pg_hba.conf

1) open C:\Program Files\PostgreSQL\12\data\pg_hba.conf

更改:托管所有:: 1:1128 md5

change: host all all ::1/128 md5

托管所有:::/128信任

host all all ::1/128 trust

2)打开pgAdmin&用用户名postgres创建一个本地主机服务器,密码将为空

2)open pgAdmin & create a localhost server with username postgres and password will empty

/*用于备份或还原现有数据库名称的转储*/

/* For taking a backup or restore a dump of existing database name */

打开cmd行,然后转到C:\ Program Files \ PostgreSQL \ 12 \ bin,然后按Enter键

open cmd line and go to C:\Program Files\PostgreSQL\12\bin and press enter

并根据需要在命令下方键入

and type below command as required

进行备份:pg_dump.exe -U postgres -d dbname -f D:\ Backup \

Take Backup : pg_dump.exe -U postgres -d dbname -f D:\Backup\

 or direct take backup using pgAdmin backup option and store in D:\Backup\<backup-file-name>  

hint: backup file should be tar or dump type

还原备份:pg_restore -U postgres -d dbname -1 D:\ Backup \

Restore Backup : pg_restore -U postgres -d dbname -1 D:\Backup\

3)在laravel代码文件夹中,打开.env文件并添加DB_SSLMODE = disable

3) In laravel code folder open .env file and add DB_SSLMODE=disable

4)在laravel代码文件夹中打开config/database.php,并打开"pgsql"数组

4) in laravel code folder open config/database.php and for 'pgsql' array

 replace

     'sslmode'=> 'require', 

 to    
    'sslmode' => env('DB_SSLMODE','require'),

推荐答案

如何在Laravel中备份PostgreSql数据库

  1. 使用composer安装laravel软件包.

  1. install laravel package using composer.

composer需要spatie/laravel-backup

将以下行插入备份控制器.

insert the following line to your backup controller.

使用Spatie \ DbDumper \ Databases \ PostgreSql;

在备份控制器中编写以下代码.

write the following code in your 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.');
}

这篇关于备份与在Windows 7中使用laravel还原PostgreSQL数据库并设置localhost环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆