当前位置:网站首页>Thinkphp6 realizes database backup
Thinkphp6 realizes database backup
2022-07-29 07:23:00 【. sea month】
Before doing tp5 Database backup , There is expansion , Now? tp6 To realize database backup , I tried , Bring the extension directly to use , Find it feasible . Here's how to do it
Install the extension
composer require tp5er/tp5-databackup dev-masterstay config Create a new file write configuration under the directory

Copy the following code
$config=array(
'path' => './Data/',// Database backup path
'part' => 20971520,// Database backup volume size
'compress' => 0,// Whether compression is enabled for database backup files 0 Uncompressed 1 Compress
'level' => 9 // Database backup file compression level 1 Ordinary 4 commonly 9 The highest
);Next, write a method calling class in the controller , The configuration file is written in this method , In fact, you can not write , But to prevent some friends from importing configuration failure , You can write it directly here , Call this method to realize
public function backup()
{
$config=array(
'path' => './Data/',// Database backup path
'part' => 20971520,// Database backup volume size
'compress' => 0,// Whether compression is enabled for database backup files 0 Uncompressed 1 Compress
'level' => 9 // Database backup file compression level 1 Ordinary 4 commonly 9 The highest
);
$db= new \tp5er\Backup($config);
$tables=$db->dataList();// Get the information of all tables in the database
foreach($tables as $k=>$v){
$db->backup($v['name'],0);// Cycle all tables back up tables and data
}
$file=$db->getFile();// Get the file name of the backed up file
var_dump($file);
}The effect is as follows
边栏推荐
猜你喜欢

WPF 界面布局必知基础

H3C_ Using setting default static routing priority to realize the active and standby function of export dual lines

Use vscode to configure Mysql to realize connection, query, and other functions

MySQL----多表查询

Leetcode 879. profit plan

个人博客系统(附源码)

Vmware16 create virtual machine: cannot create a new virtual machine, do not have permission to perform this operation

Full process flow of CMOS chip manufacturing

Win11vmware turns on the virtual machine and restarts on the blue screen and the solution that cannot be started

Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)
随机推荐
Leetcode 209. subarray with the smallest length (2022.07.28)
Vmware16 create virtual machine: win11 cannot be installed
After three years of outsourcing, the salary of automatic testing after job hopping is twice that of the original. The secret is
一篇长文---深入理解synchronized
【OpenGL】着色器(Shader)的使用
JS break and continue and return keywords
MySQL 使用客户端以及SELECT 方式查看 BLOB 类型字段内容总结
Homebrew brew update doesn't respond for a long time (or stuck in updating homebrew...)
Can I specify memory parameters in SQL statements?
LevelFilter简介说明
QT基础第二天(2)qt基础部件:按钮类,布局类,输出类,输入类,容器等个别举例
tp6 使用 ProtoBuf
Other basic monitoring items of ZABBIX
MySQL uses the client and select methods to view the summary of blob type fields
Life cycle hooks in routing - activated and deactivated
Meta configuration item of route
Cvpr2021 | multi view stereo matching based on self supervised learning (cvpr2021)
QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
WPF 界面布局必知基础
WPF嵌套布局案例