This commit is contained in:
dami 2026-07-07 23:36:34 +08:00
parent 2f09e227d1
commit 91dfecf882
2 changed files with 17 additions and 7 deletions

View File

@ -116,9 +116,9 @@ def migrateSiteHotLogs(site_name, query_date):
time.sleep(0.5)
copy_start = time.time()
# import shutil
# shutil.copy(hot_db, hot_db_tmp)
shutil.copy(hot_db, hot_db_tmp)
# mw.fastCopy(hot_db, hot_db_tmp, 256 * 1024)
mw.sendfile(hot_db,hot_db_tmp)
# mw.sendfile(hot_db,hot_db_tmp)
print(f"[{site_name}] 备份完成,耗时 {time.time() - copy_start:.2f}s")
if not os.path.exists(hot_db_tmp):
return mw.returnMsg(False, f"{site_name} migrating fail, copy tmp file!")

View File

@ -327,15 +327,25 @@ def fastCopy(src, dst, buffer_size=256 * 1024): # 128MB 缓冲区
# linux高效复制
def sendfile(src, dst):
if isAppleSystem():
shutil.copyfile(src, dst)
return True
try:
shutil.copyfile(src, dst)
return True
except Exception as e:
return False
try:
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
filesize = os.fstat(fsrc.fileno()).st_size
os.sendfile(fdst.fileno(), fsrc.fileno(), 0, filesize)
sent = os.sendfile(fdst.fileno(), fsrc.fileno(), 0, filesize)
if sent != filesize:
shutil.copyfile(src, dst)
return True
except OSError as e:
return False
except (OSError, AttributeError) as e:
try:
shutil.copyfile(src, dst)
return True
except Exception as e2:
return False
def returnData(status, msg, data=None):
if data is None: