Upload sync.py with huggingface_hub
Browse files
sync.py
CHANGED
|
@@ -96,14 +96,24 @@ def sync():
|
|
| 96 |
print('兩邊一致,不需要同步')
|
| 97 |
return
|
| 98 |
|
| 99 |
-
# 備份 Local
|
| 100 |
if LOCAL_DB.exists():
|
| 101 |
BACKUP_DIR.mkdir(exist_ok=True)
|
|
|
|
| 102 |
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 103 |
bk = BACKUP_DIR / f'pra_data_before_sync_{ts}.db'
|
| 104 |
shutil.copy2(str(LOCAL_DB), str(bk))
|
| 105 |
print(f'已備份 Local → {bk.name}')
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
# 直接用雲端 DB 覆蓋 Local
|
| 108 |
shutil.copy2(cloud_path, str(LOCAL_DB))
|
| 109 |
|
|
|
|
| 96 |
print('兩邊一致,不需要同步')
|
| 97 |
return
|
| 98 |
|
| 99 |
+
# 備份 Local(當天最多 5 個,總共最多 15 個)
|
| 100 |
if LOCAL_DB.exists():
|
| 101 |
BACKUP_DIR.mkdir(exist_ok=True)
|
| 102 |
+
today = datetime.now().strftime('%Y%m%d')
|
| 103 |
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 104 |
bk = BACKUP_DIR / f'pra_data_before_sync_{ts}.db'
|
| 105 |
shutil.copy2(str(LOCAL_DB), str(bk))
|
| 106 |
print(f'已備份 Local → {bk.name}')
|
| 107 |
|
| 108 |
+
# 當天最多 5 個
|
| 109 |
+
today_bks = sorted(BACKUP_DIR.glob(f'pra_data_before_sync_{today}_*.db'))
|
| 110 |
+
for old in today_bks[:-5]:
|
| 111 |
+
old.unlink()
|
| 112 |
+
# 總共最多 15 個
|
| 113 |
+
all_bks = sorted(BACKUP_DIR.glob('pra_data_before_sync_*.db'))
|
| 114 |
+
for old in all_bks[:-15]:
|
| 115 |
+
old.unlink()
|
| 116 |
+
|
| 117 |
# 直接用雲端 DB 覆蓋 Local
|
| 118 |
shutil.copy2(cloud_path, str(LOCAL_DB))
|
| 119 |
|