Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Jan 9, 2022
1 parent 1c9bc6d commit 30a359a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README_zh.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

# Smart Backup

- 一个集 *全盘备份* / *增量备份* / *差异备份* 为一体的插件 _(实际上增量备份只有实现, 没有使用)_
- 一个集 *全盘备份* / *增量备份* / *差异备份* 为一体的插件
- 支持**定时备份**
- 暂未实现清理备份功能
2 changes: 1 addition & 1 deletion mcdreforged.plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "smart_backup",
"version": "1.1.1",
"version": "1.2.0",
"name": "SmartBackup",
"description": {
"en_us": "A Minecraft Backup Plugin",
Expand Down
31 changes: 19 additions & 12 deletions smart_backup/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def _timed_make_backup():
source = GL.SERVER_INS.get_plugin_command_source()
cmt = 'SMB timed backup: ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
broadcast_message('Making backup "{}"'.format(cmt))
try:
make_backup(source, cmt)
finally:
if backup_timer is None:
_flush_backup_timer()
make_backup(source, cmt)

@GL.on_load_call
def on_load(server: MCDR.PluginServerInterface):
Expand All @@ -67,18 +63,29 @@ def make_backup(source: MCDR.CommandSource, comment: str, mode: BackupMode = Non
tuple(map(server.execute, GL.Config.befor_backup))
def c():
nonlocal mode
prev: Backup = None
prev: Backup = Backup.get_last(GL.Config.backup_path)
if mode is None:
mode = BackupMode.FULL
if 'differential_count' not in GL.Config.cache or GL.Config.cache['differential_count'] >= GL.Config.differential_backup_limit:
GL.Config.cache['differential_count'] = 0
if 'incremental_count' not in GL.Config.cache or \
GL.Config.cache['incremental_count'] >= GL.Config.incremental_backup_limit:
GL.Config.cache['incremental_count'] = 0
if 'differential_count' not in GL.Config.cache or \
GL.Config.cache['differential_count'] >= GL.Config.differential_backup_limit:
GL.Config.cache['differential_count'] = 0
else:
if prev is None:
GL.Config.cache['differential_count'] = 0
else:
GL.Config.cache['differential_count'] += 1
mode = BackupMode.DIFFERENTIAL
else:
prev = Backup.get_last(GL.Config.backup_path)
if prev is None:
GL.Config.cache['differential_count'] = 0
GL.Config.cache['incremental_count'] = 0
else:
GL.Config.cache['differential_count'] += 1
mode = BackupMode.DIFFERENTIAL
GL.Config.cache['incremental_count'] += 1
mode = BackupMode.INCREMENTAL
if mode == BackupMode.FULL:
prev = None
backup = Backup.create(mode, comment,
source.get_server().get_mcdr_config()['working_directory'], GL.Config.backup_needs, GL.Config.backup_ignores, prev=prev)
send_message(source, 'Saving backup "{}"'.format(comment), log=True)
Expand Down
11 changes: 6 additions & 5 deletions smart_backup/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
HelpMessage = '''
{0} help 显示帮助信息
{0} status 显示插件状态
{0} list [<limit>] 列出[所有/<limit>条]备份
{0} list [<limit> = 10] 列出<limit>条备份
{0} query <id> 查询备份详细信息
{0} make [<comment>] 创建新备份(差异/全盘)
{0} makefull [<comment>] 创建全盘备份
{0} rm <id> [force] 删除指定备份(及其子备份) #TODO
{0} restore <id> [force] 回档至指定备份
{0} make [<comment> = 'None'] 创建新备份(差异/全盘)
{0} makefull [<comment> = 'None'] 创建全盘备份
{0} rm <id> [<force> = false] 删除指定备份(及其子备份) #TODO
{0} restore <id> [<force> = false] 回档至指定备份
{0} confirm 确认操作
{0} abort 取消操作
{0} reload 重新加载配置文件
Expand Down Expand Up @@ -75,6 +75,7 @@ def command_status(source: MCDR.CommandSource):
join_rtext('最近一次备份:', lc)
)

@new_thread
def command_list_backup(source: MCDR.CommandSource, limit: int):
bks = Backup.list(GL.Config.backup_path, limit)
lines = [MCDR.RTextList(b.z_index * '|',
Expand Down
3 changes: 2 additions & 1 deletion smart_backup/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
BIG_BLOCK_AFTER = ':::: {0} v{1} ============'

class SMBConfig(MCDR.Serializable):
differential_backup_limit: int = 10
incremental_backup_limit: int = 12
differential_backup_limit: int = 6
full_backup_limit: int = 10
backup_interval: int = 60 * 60 * 1 # 1 hours
restore_timeout: int = 30
Expand Down

0 comments on commit 30a359a

Please sign in to comment.