Files
douba_shop/app/services/system/SystemDatabackupServices.php
Karlcarlo c9a98f342c chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材
添加系统版本配置文件(.version)和常量定义文件(.constant)
更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件
添加验证码配置文件(captcha.php)和.gitignore规则
2026-03-06 20:14:23 +08:00

125 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\system;
use app\services\BaseServices;
use crmeb\services\MysqlBackupService;
use think\facade\Db;
use think\facade\Env;
/**
* 数据库备份
* Class SystemDatabackupServices
* @package app\services\system
*/
class SystemDatabackupServices extends BaseServices
{
/**
*
* @var MysqlBackupService
*/
protected $dbBackup;
/**
* 构造方法
* SystemDatabackupServices constructor.
*/
public function __construct()
{
$this->dbBackup = app()->make(MysqlBackupService::class, [[
//数据库备份卷大小
'compress' => 1,
//数据库备份文件是否启用压缩 0不压缩 1 压缩
'level' => 5,
]]);
}
/**
* 获取数据库列表
* @return array
* @throws \think\db\exception\BindParamException
*/
public function getDataList()
{
$list = $this->dbBackup->dataList();
$count = count($list);
return compact('list', 'count');
}
/**
* 获取表详情
* @param string $tablename
* @return array
*/
public function getRead(string $tablename)
{
$database = Env::get("database.database");
$list = Db::query("select * from information_schema.columns where table_name = '" . $tablename . "' and table_schema = '" . $database . "'");
$count = count($list);
foreach ($list as $key => $f) {
$list[$key]['EXTRA'] = ($f['EXTRA'] == 'auto_increment' ? '是' : ' ');
}
return compact('list', 'count');
}
/**
* @return MysqlBackupService
*/
public function getDbBackup()
{
return $this->dbBackup;
}
/**
* 备份表
* @param string $tables
* @return string
* @throws \think\db\exception\BindParamException
*/
public function backup(string $tables)
{
$tables = explode(',', $tables);
$data = '';
ini_set ("memory_limit","-1");
foreach ($tables as $t) {
$res = $this->dbBackup->backup($t, 0);
if ($res == false && $res != 0) {
$data .= $t . '|';
}
}
return $data;
}
/**
* 获取备份列表
* @return array
*/
public function getBackup()
{
$files = $this->dbBackup->fileList();
$data = [];
foreach ($files as $key => $t) {
$data[$key]['filename'] = $t['filename'];
$data[$key]['part'] = $t['part'];
$data[$key]['size'] = $t['size'] . 'B';
$data[$key]['compress'] = $t['compress'];
$data[$key]['backtime'] = $key;
$data[$key]['time'] = $t['time'];
}
krsort($data);//根据时间降序
return ['count' => count($data), 'list' => array_values($data)];
}
}