2020-07-10 解决public冲突。

This commit is contained in:
midoks
2020-07-10 15:57:25 +08:00
parent 89e3940771
commit 6c65e45d00
47 changed files with 2324 additions and 2318 deletions
+26 -26
View File
@@ -17,7 +17,7 @@ reload(sys)
sys.setdefaultencoding('utf-8')
import public
import mw
import db
import time
@@ -36,14 +36,14 @@ class backupTools:
"----------------------------------------------------------------------------")
return
backup_path = public.getRootDir() + '/backup/site'
backup_path = mw.getRootDir() + '/backup/site'
if not os.path.exists(backup_path):
public.execShell("mkdir -p " + backup_path)
mw.execShell("mkdir -p " + backup_path)
filename = backup_path + "/web_" + name + "_" + \
time.strftime('%Y%m%d_%H%M%S', time.localtime()) + '.tar.gz'
public.execShell("cd " + os.path.dirname(path) + " && tar zcvf '" +
filename + "' '" + os.path.basename(path) + "' > /dev/null")
mw.execShell("cd " + os.path.dirname(path) + " && tar zcvf '" +
filename + "' '" + os.path.basename(path) + "' > /dev/null")
endDate = time.strftime('%Y/%m/%d %X', time.localtime())
@@ -60,7 +60,7 @@ class backupTools:
sql.table('backup').add('type,name,pid,filename,addtime,size', ('0', os.path.basename(
filename), pid, filename, endDate, os.path.getsize(filename)))
log = u"网站[" + name + u"]备份成功,用时[" + str(round(outTime, 2)) + u"]秒"
public.writeLog(u'计划任务', log)
mw.writeLog(u'计划任务', log)
print(u"★[" + endDate + "] " + log)
print(u"|---保留最新的[" + count + u"]份备份")
print(u"|---文件名:" + filename)
@@ -72,7 +72,7 @@ class backupTools:
num = len(backups) - int(count)
if num > 0:
for backup in backups:
public.execShell("rm -f " + backup['filename'])
mw.execShell("rm -f " + backup['filename'])
sql.table('backup').where('id=?', (backup['id'],)).delete()
num -= 1
print(u"|---已清理过期备份文件:" + backup['filename'])
@@ -80,9 +80,9 @@ class backupTools:
break
def backupDatabase(self, name, count):
db_path = public.getServerDir() + '/mysql'
db_path = mw.getServerDir() + '/mysql'
db_name = 'mysql'
name = public.M('databases').dbPos(db_path, 'mysql').where(
name = mw.M('databases').dbPos(db_path, 'mysql').where(
'name=?', (name,)).getField('name')
startTime = time.time()
if not name:
@@ -93,26 +93,26 @@ class backupTools:
u"----------------------------------------------------------------------------")
return
backup_path = public.getRootDir() + '/backup/database'
backup_path = mw.getRootDir() + '/backup/database'
if not os.path.exists(backup_path):
public.execShell("mkdir -p " + backup_path)
mw.execShell("mkdir -p " + backup_path)
filename = backup_path + "/db_" + name + "_" + \
time.strftime('%Y%m%d_%H%M%S', time.localtime()) + ".sql.gz"
import re
mysql_root = public.M('config').dbPos(db_path, db_name).where(
mysql_root = mw.M('config').dbPos(db_path, db_name).where(
"id=?", (1,)).getField('mysql_root')
mycnf = public.readFile(db_path + '/etc/my.cnf')
mycnf = mw.readFile(db_path + '/etc/my.cnf')
rep = "\[mysqldump\]\nuser=root"
sea = "[mysqldump]\n"
subStr = sea + "user=root\npassword=" + mysql_root + "\n"
mycnf = mycnf.replace(sea, subStr)
if len(mycnf) > 100:
public.writeFile(db_path + '/etc/my.cnf', mycnf)
mw.writeFile(db_path + '/etc/my.cnf', mycnf)
public.execShell(
mw.execShell(
db_path + "/bin/mysqldump --opt --default-character-set=utf8 " + name + " | gzip > " + filename)
if not os.path.exists(filename):
@@ -123,47 +123,47 @@ class backupTools:
u"----------------------------------------------------------------------------")
return
mycnf = public.readFile(db_path + '/etc/my.cnf')
mycnf = mw.readFile(db_path + '/etc/my.cnf')
mycnf = mycnf.replace(subStr, sea)
if len(mycnf) > 100:
public.writeFile(db_path + '/etc/my.cnf', mycnf)
mw.writeFile(db_path + '/etc/my.cnf', mycnf)
endDate = time.strftime('%Y/%m/%d %X', time.localtime())
outTime = time.time() - startTime
pid = public.M('databases').dbPos(db_path, db_name).where(
pid = mw.M('databases').dbPos(db_path, db_name).where(
'name=?', (name,)).getField('id')
public.M('backup').add('type,name,pid,filename,addtime,size', (1, os.path.basename(
mw.M('backup').add('type,name,pid,filename,addtime,size', (1, os.path.basename(
filename), pid, filename, endDate, os.path.getsize(filename)))
log = u"数据库[" + name + u"]备份成功,用时[" + str(round(outTime, 2)) + u"]秒"
public.writeLog(u'计划任务', log)
mw.writeLog(u'计划任务', log)
print("★[" + endDate + "] " + log)
print(u"|---保留最新的[" + count + u"]份备份")
print(u"|---文件名:" + filename)
# 清理多余备份
backups = public.M('backup').where(
backups = mw.M('backup').where(
'type=? and pid=?', ('1', pid)).field('id,filename').select()
num = len(backups) - int(count)
if num > 0:
for backup in backups:
public.execShell("rm -f " + backup['filename'])
public.M('backup').where('id=?', (backup['id'],)).delete()
mw.execShell("rm -f " + backup['filename'])
mw.M('backup').where('id=?', (backup['id'],)).delete()
num -= 1
print(u"|---已清理过期备份文件:" + backup['filename'])
if num < 1:
break
def backupSiteAll(self, save):
sites = public.M('sites').field('name').select()
sites = mw.M('sites').field('name').select()
for site in sites:
self.backupSite(site['name'], save)
def backupDatabaseAll(self, save):
db_path = public.getServerDir() + '/mysql'
db_path = mw.getServerDir() + '/mysql'
db_name = 'mysql'
databases = public.M('databases').dbPos(
databases = mw.M('databases').dbPos(
db_path, db_name).field('name').select()
for database in databases:
self.backupDatabase(database['name'], save)