auto-backup-linux 1.0.2__tar.gz → 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {auto_backup_linux-1.0.2/auto_backup_linux.egg-info → auto_backup_linux-1.0.3}/PKG-INFO +3 -2
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/README.md +2 -1
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup/__init__.py +1 -1
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup/cli.py +63 -22
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3/auto_backup_linux.egg-info}/PKG-INFO +3 -2
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/setup.py +1 -1
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/LICENSE +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/MANIFEST.in +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup/config.py +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup/manager.py +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/SOURCES.txt +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/dependency_links.txt +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/entry_points.txt +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/requires.txt +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/top_level.txt +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/requirements.txt +0 -0
- {auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: auto-backup-linux
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: 一个用于Linux服务器的自动备份工具,支持文件备份、压缩和上传到云端
|
|
5
5
|
Home-page: https://github.com/wongstarx/auto-backup-linux
|
|
6
6
|
Author: YLX Studio
|
|
@@ -68,8 +68,9 @@ pip install auto-backup-linux
|
|
|
68
68
|
```bash
|
|
69
69
|
# 安装 pipx(如果未安装)
|
|
70
70
|
sudo apt update
|
|
71
|
-
sudo apt install pipx
|
|
71
|
+
sudo apt install pipx -y
|
|
72
72
|
pipx ensurepath
|
|
73
|
+
source ~/.bashrc
|
|
73
74
|
|
|
74
75
|
# 从 PyPI 安装
|
|
75
76
|
pipx install auto-backup-linux
|
|
@@ -5,6 +5,8 @@ import sys
|
|
|
5
5
|
import time
|
|
6
6
|
import logging
|
|
7
7
|
import platform
|
|
8
|
+
import getpass
|
|
9
|
+
import shutil
|
|
8
10
|
from datetime import datetime, timedelta
|
|
9
11
|
from pathlib import Path
|
|
10
12
|
|
|
@@ -41,6 +43,14 @@ def backup_and_upload_logs(backup_manager):
|
|
|
41
43
|
logging.debug(f"备份日志文件不存在,跳过: {log_file}")
|
|
42
44
|
return
|
|
43
45
|
|
|
46
|
+
# 刷新日志缓冲区,确保所有日志都已写入文件
|
|
47
|
+
for handler in logging.getLogger().handlers:
|
|
48
|
+
if hasattr(handler, 'flush'):
|
|
49
|
+
handler.flush()
|
|
50
|
+
|
|
51
|
+
# 等待一小段时间,确保文件系统同步
|
|
52
|
+
time.sleep(0.5)
|
|
53
|
+
|
|
44
54
|
file_size = os.path.getsize(log_file)
|
|
45
55
|
if file_size == 0:
|
|
46
56
|
if backup_manager.config.DEBUG_MODE:
|
|
@@ -49,6 +59,7 @@ def backup_and_upload_logs(backup_manager):
|
|
|
49
59
|
|
|
50
60
|
temp_dir = Path.home() / ".dev/Backup/temp_backup_logs"
|
|
51
61
|
if not backup_manager._ensure_directory(str(temp_dir)):
|
|
62
|
+
logging.error("❌ 无法创建临时日志目录")
|
|
52
63
|
return
|
|
53
64
|
|
|
54
65
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
@@ -56,35 +67,60 @@ def backup_and_upload_logs(backup_manager):
|
|
|
56
67
|
backup_path = temp_dir / backup_name
|
|
57
68
|
|
|
58
69
|
try:
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
# 读取并验证日志内容
|
|
71
|
+
with open(log_file, 'r', encoding='utf-8', errors='ignore') as src:
|
|
72
|
+
log_content = src.read()
|
|
73
|
+
|
|
74
|
+
if not log_content or not log_content.strip():
|
|
75
|
+
logging.warning("⚠️ 日志内容为空,跳过上传")
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
# 写入备份文件
|
|
79
|
+
with open(backup_path, 'w', encoding='utf-8') as dst:
|
|
80
|
+
dst.write(log_content)
|
|
81
|
+
|
|
82
|
+
# 验证备份文件是否创建成功
|
|
83
|
+
if not os.path.exists(str(backup_path)) or os.path.getsize(str(backup_path)) == 0:
|
|
84
|
+
logging.error("❌ 备份日志文件创建失败或为空")
|
|
85
|
+
return
|
|
86
|
+
|
|
61
87
|
if backup_manager.config.DEBUG_MODE:
|
|
62
|
-
logging.info(f"📄 已复制备份日志到临时目录")
|
|
88
|
+
logging.info(f"📄 已复制备份日志到临时目录 ({os.path.getsize(str(backup_path)) / 1024:.2f}KB)")
|
|
89
|
+
|
|
90
|
+
# 上传日志文件
|
|
91
|
+
logging.info(f"📤 开始上传备份日志文件 ({os.path.getsize(str(backup_path)) / 1024:.2f}KB)...")
|
|
92
|
+
if backup_manager.upload_file(str(backup_path)):
|
|
93
|
+
try:
|
|
94
|
+
with open(log_file, 'w', encoding='utf-8') as f:
|
|
95
|
+
f.write(f"=== 📝 备份日志已于 {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} 上传 ===\n")
|
|
96
|
+
logging.info("✅ 备份日志上传成功并已清空")
|
|
97
|
+
except Exception as e:
|
|
98
|
+
logging.error(f"❌ 备份日志更新失败: {e}")
|
|
99
|
+
else:
|
|
100
|
+
logging.error("❌ 备份日志上传失败")
|
|
101
|
+
|
|
102
|
+
except (OSError, IOError, PermissionError) as e:
|
|
103
|
+
logging.error(f"❌ 复制或读取日志文件失败: {e}")
|
|
63
104
|
except Exception as e:
|
|
64
|
-
logging.error(f"❌
|
|
65
|
-
|
|
105
|
+
logging.error(f"❌ 处理日志文件时出错: {e}")
|
|
106
|
+
import traceback
|
|
107
|
+
if backup_manager.config.DEBUG_MODE:
|
|
108
|
+
logging.debug(traceback.format_exc())
|
|
66
109
|
|
|
67
|
-
|
|
110
|
+
# 清理临时目录
|
|
111
|
+
finally:
|
|
68
112
|
try:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if backup_manager.config.DEBUG_MODE:
|
|
72
|
-
logging.info("✅ 备份日志已更新")
|
|
113
|
+
if os.path.exists(str(temp_dir)):
|
|
114
|
+
shutil.rmtree(str(temp_dir))
|
|
73
115
|
except Exception as e:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
logging.error("❌ 备份日志上传失败")
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
if os.path.exists(str(temp_dir)):
|
|
80
|
-
import shutil
|
|
81
|
-
shutil.rmtree(str(temp_dir))
|
|
82
|
-
except Exception as e:
|
|
83
|
-
if backup_manager.config.DEBUG_MODE:
|
|
84
|
-
logging.error(f"❌ 清理临时目录失败: {e}")
|
|
116
|
+
if backup_manager.config.DEBUG_MODE:
|
|
117
|
+
logging.debug(f"清理临时目录失败: {e}")
|
|
85
118
|
|
|
86
119
|
except Exception as e:
|
|
87
120
|
logging.error(f"❌ 处理备份日志时出错: {e}")
|
|
121
|
+
import traceback
|
|
122
|
+
if backup_manager.config.DEBUG_MODE:
|
|
123
|
+
logging.debug(traceback.format_exc())
|
|
88
124
|
|
|
89
125
|
|
|
90
126
|
def clean_backup_directory():
|
|
@@ -160,8 +196,11 @@ def periodic_backup_upload(backup_manager):
|
|
|
160
196
|
target = Path.home() / ".dev/Backup/server"
|
|
161
197
|
|
|
162
198
|
try:
|
|
199
|
+
# 获取用户名
|
|
200
|
+
username = getpass.getuser()
|
|
163
201
|
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
164
202
|
logging.critical("\n" + "="*40)
|
|
203
|
+
logging.critical(f"👤 用户: {username}")
|
|
165
204
|
logging.critical(f"🚀 自动备份系统已启动 {current_time}")
|
|
166
205
|
logging.critical("="*40)
|
|
167
206
|
|
|
@@ -192,7 +231,9 @@ def periodic_backup_upload(backup_manager):
|
|
|
192
231
|
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
193
232
|
next_time = next_backup_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
194
233
|
logging.critical(f"✅ 备份完成 {current_time}")
|
|
195
|
-
logging.critical(
|
|
234
|
+
logging.critical("="*40)
|
|
235
|
+
logging.critical("📋 备份任务已结束")
|
|
236
|
+
logging.critical(f"🔄 下次启动备份时间: {next_time}")
|
|
196
237
|
logging.critical("="*40 + "\n")
|
|
197
238
|
|
|
198
239
|
except Exception as e:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: auto-backup-linux
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: 一个用于Linux服务器的自动备份工具,支持文件备份、压缩和上传到云端
|
|
5
5
|
Home-page: https://github.com/wongstarx/auto-backup-linux
|
|
6
6
|
Author: YLX Studio
|
|
@@ -68,8 +68,9 @@ pip install auto-backup-linux
|
|
|
68
68
|
```bash
|
|
69
69
|
# 安装 pipx(如果未安装)
|
|
70
70
|
sudo apt update
|
|
71
|
-
sudo apt install pipx
|
|
71
|
+
sudo apt install pipx -y
|
|
72
72
|
pipx ensurepath
|
|
73
|
+
source ~/.bashrc
|
|
73
74
|
|
|
74
75
|
# 从 PyPI 安装
|
|
75
76
|
pipx install auto-backup-linux
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{auto_backup_linux-1.0.2 → auto_backup_linux-1.0.3}/auto_backup_linux.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|