refactor: 图片迁移python脚本
Some checks failed
Gitea Actions Official-website / deploy-dev (push) Failing after 3s
Some checks failed
Gitea Actions Official-website / deploy-dev (push) Failing after 3s
This commit is contained in:
24
scripts/config.json
Normal file
24
scripts/config.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"source": {
|
||||||
|
"type": "local",
|
||||||
|
"base_dir": "public/storage",
|
||||||
|
"ssh": {
|
||||||
|
"host": "source-server.example.com",
|
||||||
|
"port": 22,
|
||||||
|
"username": "username",
|
||||||
|
"password": "your_password_here",
|
||||||
|
"key_file": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"target": {
|
||||||
|
"type": "ssh",
|
||||||
|
"base_dir": "/www/wwwroot/orico-official-website/public/storage",
|
||||||
|
"ssh": {
|
||||||
|
"host": "47.91.149.172",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"password": "Orico666tx5d",
|
||||||
|
"key_file": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -316,9 +316,9 @@ class ImageMigrator:
|
|||||||
print(
|
print(
|
||||||
f"DEBUG ensure_target_directory: 目录实际上已存在: {current_path}"
|
f"DEBUG ensure_target_directory: 目录实际上已存在: {current_path}"
|
||||||
)
|
)
|
||||||
except:
|
except Exception as listdir_e:
|
||||||
# 目录确实不存在且创建失败
|
# 目录确实不存在且创建失败
|
||||||
print(f"错误: 无法创建目录 {current_path}: {mkdir_e}")
|
print(f"错误: 无法创建目录 {current_path}: {listdir_e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 最终确认目录是否创建成功
|
# 最终确认目录是否创建成功
|
||||||
@@ -365,7 +365,7 @@ class ImageMigrator:
|
|||||||
return True, os.path.getsize(source_path)
|
return True, os.path.getsize(source_path)
|
||||||
else:
|
else:
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(f"DEBUG: 文件不存在!")
|
print("DEBUG: 文件不存在!")
|
||||||
return False, 0
|
return False, 0
|
||||||
else:
|
else:
|
||||||
# SSH远程文件
|
# SSH远程文件
|
||||||
@@ -388,7 +388,7 @@ class ImageMigrator:
|
|||||||
if self.source_config.is_local():
|
if self.source_config.is_local():
|
||||||
# 从本地文件复制
|
# 从本地文件复制
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(f"DEBUG read_source_file: 开始复制文件")
|
print("DEBUG read_source_file: 开始复制文件")
|
||||||
print(f"DEBUG read_source_file: 源路径: {source_path}")
|
print(f"DEBUG read_source_file: 源路径: {source_path}")
|
||||||
print(f"DEBUG read_source_file: 临时路径: {temp_path}")
|
print(f"DEBUG read_source_file: 临时路径: {temp_path}")
|
||||||
print(
|
print(
|
||||||
@@ -401,7 +401,7 @@ class ImageMigrator:
|
|||||||
shutil.copy2(source_path, temp_path)
|
shutil.copy2(source_path, temp_path)
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(f"DEBUG read_source_file: 复制完成")
|
print("DEBUG read_source_file: 复制完成")
|
||||||
print(
|
print(
|
||||||
f"DEBUG read_source_file: 临时文件是否存在: {os.path.exists(temp_path)}"
|
f"DEBUG read_source_file: 临时文件是否存在: {os.path.exists(temp_path)}"
|
||||||
)
|
)
|
||||||
@@ -417,6 +417,8 @@ class ImageMigrator:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
with open("fails.txt", "a", encoding="utf-8") as file:
|
||||||
|
file.write(f"{source_path}\n")
|
||||||
print(f"读取源文件失败 {source_path}: {e}")
|
print(f"读取源文件失败 {source_path}: {e}")
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
@@ -519,7 +521,7 @@ class ImageMigrator:
|
|||||||
self.target_sftp.put(temp_path, target_path)
|
self.target_sftp.put(temp_path, target_path)
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(f"DEBUG: 上传完成")
|
print("DEBUG: 上传完成")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
|
|||||||
2
scripts/images.txt
Normal file
2
scripts/images.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
images/banner/20251217/c16f15d090170b9cecaf6b88e02384f3_thumb.png
|
||||||
|
images/banner/20251217/c16f15d090170b9cecaf6b88e02384f3.png
|
||||||
Reference in New Issue
Block a user