Update server.py
Browse files
server.py
CHANGED
|
@@ -319,6 +319,8 @@ def repeat_task():
|
|
| 319 |
# repeat_task()
|
| 320 |
# compress_folder()
|
| 321 |
|
|
|
|
|
|
|
| 322 |
import os
|
| 323 |
import subprocess
|
| 324 |
import pexpect
|
|
@@ -391,6 +393,24 @@ import requests
|
|
| 391 |
import subprocess
|
| 392 |
import logging
|
| 393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
# 配置日志
|
| 395 |
logging.basicConfig(level=logging.INFO)
|
| 396 |
|
|
@@ -442,8 +462,14 @@ def check_api1():
|
|
| 442 |
retry_count = 3 # 设置重试次数
|
| 443 |
for attempt in range(retry_count):
|
| 444 |
try:
|
| 445 |
-
|
| 446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
except subprocess.CalledProcessError as e:
|
| 448 |
logging.error(f"Rsync 失败,返回码: {e.returncode}, 尝试次数: {attempt + 1}")
|
| 449 |
if attempt == retry_count - 1:
|
|
|
|
| 319 |
# repeat_task()
|
| 320 |
# compress_folder()
|
| 321 |
|
| 322 |
+
|
| 323 |
+
|
| 324 |
import os
|
| 325 |
import subprocess
|
| 326 |
import pexpect
|
|
|
|
| 393 |
import subprocess
|
| 394 |
import logging
|
| 395 |
|
| 396 |
+
import paramiko
|
| 397 |
+
|
| 398 |
+
def check_ssh_connection(host, port, username, password):
|
| 399 |
+
try:
|
| 400 |
+
client = paramiko.SSHClient()
|
| 401 |
+
# 允许连接到不在 known_hosts 中的主机
|
| 402 |
+
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
| 403 |
+
# 尝试连接
|
| 404 |
+
client.connect(hostname=host, port=port, username=username, password=password)
|
| 405 |
+
client.close()
|
| 406 |
+
return True
|
| 407 |
+
except Exception as e:
|
| 408 |
+
print(f"SSH 连接失败: {e}")
|
| 409 |
+
return False
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
|
| 414 |
# 配置日志
|
| 415 |
logging.basicConfig(level=logging.INFO)
|
| 416 |
|
|
|
|
| 462 |
retry_count = 3 # 设置重试次数
|
| 463 |
for attempt in range(retry_count):
|
| 464 |
try:
|
| 465 |
+
if check_ssh_connection(ssh_url, ssh_port, 'root', 'qilan'):
|
| 466 |
+
print("SSH 连接成功")
|
| 467 |
+
subprocess.run(f"rsync -avz --timeout=600 -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{ssh_url}:{data_folder}/ {data_folder}/",shell=True, check=True)
|
| 468 |
+
break # 如果成功,跳出重试循环
|
| 469 |
+
else:
|
| 470 |
+
print("SSH 连接失败")
|
| 471 |
+
|
| 472 |
+
|
| 473 |
except subprocess.CalledProcessError as e:
|
| 474 |
logging.error(f"Rsync 失败,返回码: {e.returncode}, 尝试次数: {attempt + 1}")
|
| 475 |
if attempt == retry_count - 1:
|