FTP备份优化

pull/445/head
midoks 2 years ago
parent 38b4042c5a
commit c9f074b319
  1. 1
      README.md
  2. 52
      plugins/backup_ftp/index.py

@ -113,6 +113,7 @@ OP防火墙 - 重载即可
* 站点批量删除修复。 * 站点批量删除修复。
* OP防火墙-修复`自动强制验证`关闭不生效。 * OP防火墙-修复`自动强制验证`关闭不生效。
* 新增OneDrive备份插件。 * 新增OneDrive备份插件。
* FTP备份优化。
### JSDelivr安装地址 ### JSDelivr安装地址

@ -14,6 +14,7 @@ if sys.platform != "darwin":
sys.path.append(os.getcwd() + "/class/core") sys.path.append(os.getcwd() + "/class/core")
import mw import mw
import db
_ver = sys.version_info _ver = sys.version_info
is_py2 = (_ver[0] == 2) is_py2 = (_ver[0] == 2)
@ -185,6 +186,35 @@ def backupAllFunc(stype):
"path": "path", "path": "path",
} }
backups = []
sql = db.Sql()
# print("stype:", stype)
# 提前获取-清理多余备份
if stype == 'site':
pid = sql.table('sites').where('name=?', (name,)).getField('id')
backups = sql.table('backup').where(
'type=? and pid=?', ('0', pid)).field('id,filename').select()
if stype == 'database':
db_path = mw.getServerDir() + '/mysql'
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
'name=?', (name,)).getField('id')
backups = sql.table('backup').where(
'type=? and pid=?', ('1', pid)).field('id,filename').select()
if stype == 'path':
backup_path = backup_dir + '/path'
_name = 'path_{}'.format(os.path.basename(name))
backups = findPathName(backup_path, _name)
# 其他类型关系性数据库(mysql类的)
if stype.find('database_') > -1:
plugin_name = stype.replace('database_', '')
db_path = mw.getServerDir() + '/' + plugin_name
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
'name=?', (name,)).getField('id')
backups = sql.table('backup').where(
'type=? and pid=?', ('1', pid)).field('id,filename').select()
args = stype + " " + name + " " + num args = stype + " " + name + " " + num
cmd = 'python3 ' + mw.getRunDir() + '/scripts/backup.py ' + args cmd = 'python3 ' + mw.getRunDir() + '/scripts/backup.py ' + args
if stype.find('database_') > -1: if stype.find('database_') > -1:
@ -213,17 +243,29 @@ def backupAllFunc(stype):
filename = mw.execShell(find_new_file)[0].strip() filename = mw.execShell(find_new_file)[0].strip()
if filename == "": if filename == "":
mw.echoInfo("not find upload file!") mw.echoInfo("not find upload file!")
return False return ''
print("|-准备上传文件 {}".format(filename)) print("|-准备上传文件 {}".format(filename))
ftp = FtpPSClient() ftp = FtpPSClient()
ftp.uploadFile(filename, stype) ftp.uploadFile(filename, stype)
return ''
# print(backups)
backups = sorted(backups, key=lambda x: x['filename'], reverse=False)
mw.echoStart('开始删除远程备份')
num = int(num)
sep = len(backups) - num
if sep > -1:
for backup in backups:
fn = os.path.basename(backup['filename'])
object_name = ftp.buildDirName(stype, fn)
ftp.deleteFile(object_name)
mw.echoInfo("---已清理远程过期备份文件:" + object_name)
sep -= 1
if sep < 0:
break
mw.echoEnd('结束删除远程备份')
def backupSite(): return ''
# 备份站点
pass
def in_array(name, arr=[]): def in_array(name, arr=[]):

Loading…
Cancel
Save