mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 12:07:28 +08:00
docs: 优化部署、迁移文档、docker增加redis支持
1、优化部署、迁移 2、自动备份命令增加手动备份功能 3、docker部署集成redis
This commit is contained in:
@@ -7,17 +7,20 @@ use Google\Cloud\Storage\StorageClient;
|
||||
|
||||
class BackupDatabase extends Command
|
||||
{
|
||||
protected $signature = 'backup:upload-cloud';
|
||||
protected $signature = 'backup:database {upload?}';
|
||||
protected $description = '备份数据库并上传到 Google Cloud Storage';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
// 判断是否存在必要配置
|
||||
$requiredConfigs = ['database.connections.mysql', 'cloud_storage.google_cloud.key_file', 'cloud_storage.google_cloud.storage_bucket'];
|
||||
foreach ($requiredConfigs as $config) {
|
||||
if (config($config) === null) {
|
||||
$this->error("❌:缺少必要配置项: $config , 取消备份");
|
||||
return;
|
||||
$isUpload = $this->argument('upload');
|
||||
// 如果是上传到云端则判断是否存在必要配置
|
||||
if($isUpload){
|
||||
$requiredConfigs = ['database.connections.mysql', 'cloud_storage.google_cloud.key_file', 'cloud_storage.google_cloud.storage_bucket'];
|
||||
foreach ($requiredConfigs as $config) {
|
||||
if (blank(config($config))) {
|
||||
$this->error("❌:缺少必要配置项: $config , 取消备份");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,27 +42,31 @@ class BackupDatabase extends Command
|
||||
->dumpToFile($databaseBackupPath);
|
||||
$this->info("2️⃣:Sqlite备份完成");
|
||||
}
|
||||
$this->info("3️⃣:开始将备份上传到Google Cloud");
|
||||
// Google Cloud Storage 配置
|
||||
$storage = new StorageClient([
|
||||
'keyFilePath' => config('cloud_storage.google_cloud.key_file'),
|
||||
]);
|
||||
$bucket = $storage->bucket(config('cloud_storage.google_cloud.storage_bucket'));
|
||||
$objectName = 'backup/' . now()->format('Y-m-d_H-i-s') . '_database_backup.sql';
|
||||
// 上传文件
|
||||
$bucket->upload(fopen($databaseBackupPath, 'r'), [
|
||||
'name' => $objectName,
|
||||
]);
|
||||
|
||||
// 输出文件链接
|
||||
|
||||
\Log::channel('backup')->info("🎉:数据库备份已上传到 Google Cloud Storage: $objectName");
|
||||
$this->info("🎉:数据库备份已上传到 Google Cloud Storage: $objectName");
|
||||
if (!$isUpload){
|
||||
$this->info("🎉:数据库成功备份到:$databaseBackupPath");
|
||||
}else{
|
||||
// 传到云盘
|
||||
$this->info("3️⃣:开始将备份上传到Google Cloud");
|
||||
// Google Cloud Storage 配置
|
||||
$storage = new StorageClient([
|
||||
'keyFilePath' => config('cloud_storage.google_cloud.key_file'),
|
||||
]);
|
||||
$bucket = $storage->bucket(config('cloud_storage.google_cloud.storage_bucket'));
|
||||
$objectName = 'backup/' . now()->format('Y-m-d_H-i-s') . '_database_backup.sql';
|
||||
// 上传文件
|
||||
$bucket->upload(fopen($databaseBackupPath, 'r'), [
|
||||
'name' => $objectName,
|
||||
]);
|
||||
|
||||
// 输出文件链接
|
||||
\Log::channel('backup')->info("🎉:数据库备份已上传到 Google Cloud Storage: $objectName");
|
||||
$this->info("🎉:数据库备份已上传到 Google Cloud Storage: $objectName");
|
||||
\File::delete($databaseBackupPath);
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
\Log::channel('backup')->error("😔:数据库备份失败" . $e->getMessage());
|
||||
$this->error("😔:数据库备份失败" . $e->getMessage());
|
||||
\Log::channel('backup')->error("😔:数据库备份失败 \n" . $e);
|
||||
$this->error("😔:数据库备份失败\n" . $e);
|
||||
\File::delete($databaseBackupPath);
|
||||
}
|
||||
// 开始删除本地备份
|
||||
\File::delete($databaseBackupPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,20 +52,21 @@ class XboardInstall extends Command
|
||||
if (\File::exists(base_path() . '/.env') && $this->getEnvValue('INSTALLED')) {
|
||||
$securePath = admin_setting('secure_path', admin_setting('frontend_admin_path', hash('crc32b', config('app.key'))));
|
||||
$this->info("访问 http(s)://你的站点/{$securePath} 进入管理面板,你可以在用户中心修改你的密码。");
|
||||
abort(500, '如需重新安装请清空目录下 .env 文件的内容(Docker安装方式不可以删除此文件)');
|
||||
$this->warn("如需重新安装请清空目录下 .env 文件的内容(Docker安装方式不可以删除此文件)");
|
||||
$this->warn("快捷清空.env命令: \"rm .env && touch .env\"");
|
||||
\Artisan::call('config:cache');
|
||||
return ;
|
||||
}
|
||||
|
||||
// 选择是否使用Sqlite
|
||||
$isSqlite = $this->ask('是否启用Sqlite代替Mysql(默认不启动 y/n)','n');
|
||||
if( $isSqlite == 'y' ) {
|
||||
if( $this->ask('是否启用Sqlite(无需额外安装)代替Mysql(默认不启用 y/n)','n') == 'y' ) {
|
||||
$sqliteFile = '.docker/.data/database.sqlite';
|
||||
if (!file_exists(base_path($sqliteFile))) {
|
||||
// 创建空文件
|
||||
if (touch(base_path($sqliteFile))) {
|
||||
echo "sqlite创建成功: $sqliteFile";
|
||||
} else {
|
||||
echo "sqlite创建成功";
|
||||
echo "sqlite创建失败";
|
||||
}
|
||||
}
|
||||
$envConfig = [
|
||||
@@ -75,15 +76,7 @@ class XboardInstall extends Command
|
||||
'DB_HOST' => '',
|
||||
'DB_USERNAME' => '',
|
||||
'DB_PASSWORD' => '',
|
||||
'REDIS_HOST' => $this->ask('请输入redis地址(默认: 127.0.0.1)', '127.0.0.1'),
|
||||
'REDIS_PORT'=> $this->ask('请输入redis端口(默认: 6379)', '6379'),
|
||||
'REDIS_PASSWORD' => $this->ask('请输入redis密码(默认: null)', null),
|
||||
'INSTALLED' => 'true'
|
||||
];
|
||||
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
||||
abort(500, '复制环境文件失败,请检查目录权限');
|
||||
}
|
||||
$this->saveToEnv($envConfig);
|
||||
}else{
|
||||
$envConfig = [
|
||||
'APP_KEY' => 'base64:' . base64_encode(Encrypter::generateKey('AES-256-CBC')),
|
||||
@@ -93,17 +86,27 @@ class XboardInstall extends Command
|
||||
'DB_DATABASE' => $this->ask('请输入数据库名', 'xboard'),
|
||||
'DB_USERNAME' => $this->ask('请输入数据库用户名'),
|
||||
'DB_PASSWORD' => $this->ask('请输入数据库密码'),
|
||||
'REDIS_HOST' => $this->ask('请输入redis地址(默认: 127.0.0.1)', '127.0.0.1'),
|
||||
'REDIS_PORT'=> $this->ask('请输入redis端口(默认: 6379)', '6379'),
|
||||
'REDIS_PASSWORD' => $this->ask('请输入redis密码(默认: null)', null),
|
||||
'INSTALLED' => 'true'
|
||||
];
|
||||
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
||||
abort(500, '复制环境文件失败,请检查目录权限');
|
||||
}
|
||||
$this->saveToEnv($envConfig);
|
||||
|
||||
}
|
||||
|
||||
$envConfig['INSTALLED'] = 'true';
|
||||
// 判断是否为Docker环境
|
||||
if (env('docker', false) == 'true' && $this->ask('是否启用Docker内置的Redis(默认启用 y/n)','y') === 'y'){
|
||||
$envConfig['REDIS_HOST'] = '/run/redis-socket';
|
||||
$envConfig['REDIS_PORT'] = 0;
|
||||
$envConfig['REDIS_PASSWORD'] = null;
|
||||
}else{
|
||||
$envConfig['REDIS_HOST'] = $this->ask('请输入redis地址(默认: 127.0.0.1)', '127.0.0.1');
|
||||
$envConfig['REDIS_PORT'] = $this->ask('请输入redis端口(默认: 6379)', '6379');
|
||||
$envConfig['REDIS_PASSWORD'] = $this->ask('请输入redis密码(默认: null)', null);
|
||||
}
|
||||
|
||||
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
||||
abort(500, '复制环境文件失败,请检查目录权限');
|
||||
}
|
||||
$this->saveToEnv($envConfig);
|
||||
|
||||
\Artisan::call('config:clear');
|
||||
\Artisan::call('config:cache');
|
||||
\Artisan::call('cache:clear');
|
||||
@@ -132,7 +135,7 @@ class XboardInstall extends Command
|
||||
$defaultSecurePath = hash('crc32b', config('app.key'));
|
||||
$this->info("访问 http(s)://你的站点/{$defaultSecurePath} 进入管理面板,你可以在用户中心修改你的密码。");
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
$this->error($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user