diff --git a/class/core/crontab_api.py b/class/core/crontab_api.py
index a531720ae..9bcecab53 100755
--- a/class/core/crontab_api.py
+++ b/class/core/crontab_api.py
@@ -129,7 +129,6 @@ class crontab_api:
addData = public.M('crontab').where('id=?', (sid,)).save('name,type,where1,where_hour,where_minute,save,backup_to,sbody,urladdress', (get[
'name'], field_type, get['where1'], get['hour'], get['minute'], get['save'], get['backup_to'], get['sbody'], get['urladdress']))
-
self.removeForCrond(cronInfo['echo'])
self.syncToCrond(cronInfo)
public.writeLog('计划任务', '修改计划任务[' + cronInfo['name'] + ']成功')
@@ -244,6 +243,26 @@ class crontab_api:
return public.returnJson(True, '任务日志已清空!')
except:
return public.returnJson(False, '任务日志清空失败!')
+
+ # 取数据列表
+ def getDataListApi(self):
+ stype = request.form.get('type', '').encode('utf-8')
+ data = {}
+ data['data'] = public.M(stype).field('name,ps').select()
+ data['orderOpt'] = []
+ # try:
+ # tmp = public.readFile('data/libList.conf')
+ # libs = json.loads(tmp)
+ # import imp
+ # for lib in libs:
+ # imp.find_module(lib['module'])
+ # tmp = {}
+ # tmp['name'] = lib['name']
+ # tmp['value'] = lib['opt']
+ # data['orderOpt'].append(tmp)
+ # except Exception as e:
+ # print e
+ return public.getJson(data)
##### ----- start ----- ###
# 转换大写星期
@@ -336,26 +355,25 @@ class crontab_api:
log = '.log'
wheres = {
- 'path': head + "python " + public.getServerDir() + "/panel/script/backup.py path " + param['sname'] + " " + str(param['save']),
- 'site': head + "python " + public.getServerDir() + "/panel/script/backup.py site " + param['sname'] + " " + str(param['save']),
- 'database': head + "python " + public.getServerDir() + "/panel/script/backup.py database " + param['sname'] + " " + str(param['save']),
- 'logs': head + "python " + public.getServerDir() + "/panel/script/logsBackup " + param['sname'] + log + " " + str(param['save']),
- 'rememory': head + "/bin/bash " + public.getServerDir() + '/panel/script/rememory.sh'
+ 'path': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py path " + param['sname'] + " " + str(param['save']),
+ 'site': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py site " + param['sname'] + " " + str(param['save']),
+ 'database': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py database " + param['sname'] + " " + str(param['save']),
+ 'logs': head + "python " + public.getServerDir() + "/mdserver-web/scripts/logs_backup " + param['sname'] + log + " " + str(param['save']),
+ 'rememory': head + "/bin/bash " + public.getServerDir() + '/mdserver-web/scripts/rememory.sh'
}
if param['backup_to'] != 'localhost':
- cfile = public.getServerDir() + "/panel/plugin/" + param[
+ cfile = public.getServerDir() + "/mdserver-web/plugin/" + param[
'backup_to'] + "/" + param['backup_to'] + "_main.py"
if not os.path.exists(cfile):
- cfile = public.getServerDir() + "/panel/script/backup_" + \
+ cfile = public.getServerDir() + "/mdserver-web/script/backup_" + \
param['backup_to'] + ".py"
wheres = {
'path': head + "python " + cfile + " path " + param['sname'] + " " + str(param['save']),
'site': head + "python " + cfile + " site " + param['sname'] + " " + str(param['save']),
'database': head + "python " + cfile + " database " + param['sname'] + " " + str(param['save']),
- 'logs': head + "python " + public.getServerDir() + "/panel/script/logsBackup " + param['sname'] + log + " " + str(param['save']),
- 'rememory': head + "/bin/bash " + public.getServerDir() + '/panel/script/rememory.sh'
+ 'logs': head + "python " + public.getServerDir() + "/mdserver-web/scripts/logs_backup " + param['sname'] + log + " " + str(param['save']),
+ 'rememory': head + "/bin/bash " + public.getServerDir() + '/mdserver-web/scripts/rememory.sh'
}
-
try:
shell = wheres[stype]
except:
diff --git a/data/libList.conf b/data/libList.conf
new file mode 100755
index 000000000..2835bc914
--- /dev/null
+++ b/data/libList.conf
@@ -0,0 +1,57 @@
+[{
+ "name":"七牛云存储",
+ "type":"计划任务",
+ "ps":"将网站或数据库打包备份到七牛对象存储空间,七牛提供10GB免费存储空间, 点击申请",
+ "status":false,
+ "opt":"qiniu",
+ "module":"qiniu",
+ "script":"qiniu",
+ "help":"http://www.bt.cn/bbs/thread-839-1-1.html",
+ "key":"access_key|请输入AccessKey|七牛秘钥中的AK",
+ "secret":"secret_key|请输入SecretKey|七牛秘钥中的SK",
+ "bucket":"存储空间|请输入对象存储空间名称|七牛对象存储中您创建的空间名称",
+ "domain":"外链域名|请输入绑定域名或测试域名|绑定的七牛外链域名,若没有则填测试域名",
+ "check":["/usr/lib/python2.6/site-packages/qiniu/auth.py","/usr/lib/python2.7/site-packages/qiniu/auth.py"]
+},{
+ "name":"阿里云OSS",
+ "type":"计划任务",
+ "ps":"将网站或数据库打包备份到阿里云OSS对象存储空间,阿里云OSS提供5GB免费存储空间, 点击申请",
+ "status":false,
+ "opt":"alioss",
+ "module":"oss2",
+ "script":"alioss",
+ "help":"http://www.bt.cn/bbs/thread-1061-1-1.html",
+ "key":"AccessKeyId|请输入AccessKeyId|阿里云的AccessKeyId",
+ "secret":"AccessKeySecret|请输入AccessKeySecret|阿里云的AccessKeySecret",
+ "bucket":"Bucket|请输入Bucket名称|阿里云OSS中您创建的Bucket名称",
+ "domain":"外链域名|请输入Endpoint域名|阿里云OSS外链域名,不包括Bucket名",
+ "check":["/usr/lib/python2.6/site-packages/oss2/auth.py","/usr/lib/python2.7/site-packages/oss2/auth.py"]
+},{
+ "name":"FTP存储空间",
+ "type":"计划任务",
+ "ps":"将网站或数据库打包备份到FTP存储空间.",
+ "status":false,
+ "opt":"ftp",
+ "module":"ftp",
+ "script":"ftp",
+ "help":"http://www.bt.cn/bbs",
+ "key":"Host|请输入主机地址|FTP服务器地址,例:192.168.0.1:21",
+ "secret":"用户名|请输入登陆用户名|指定FTP用户名",
+ "bucket":"密码|请输入登陆密码|指定FTP密码",
+ "domain":"存储位置|请输入存储位置|相对于FTP根目录的路径,如 /backup",
+ "check":["/www/server/panel/script/backup_ftp.py"]
+},{
+ "name":"申请内测资格",
+ "type":"其它",
+ "ps":"申请内测资格,审核完成后将会获得内测版本更新推送,并可在宝塔论坛内测专用版块参与讨论",
+ "status":false,
+ "opt":"beta",
+ "module":"beta",
+ "script":"beta",
+ "help":"http://www.bt.cn/bbs/thread-1392-1-1.html",
+ "key":"",
+ "secret":"",
+ "bucket":"",
+ "domain":"",
+ "check":["data/beta.pl"]
+}]
\ No newline at end of file
diff --git a/route/static/app/crontab.js b/route/static/app/crontab.js
index 6883dafea..a4f16b422 100755
--- a/route/static/app/crontab.js
+++ b/route/static/app/crontab.js
@@ -44,7 +44,6 @@ function getCronData(){
var load = layer.msg(lan.public.the,{icon:16,time:0,shade: [0.3, '#000']});
$.post('/crontab/list', '', function(rdata){
layer.close(load);
- console.log(rdata);
var cbody = "";
if(rdata == ""){
cbody="
"+lan.crontab.task_empty+" |
";
@@ -231,21 +230,20 @@ function planAdd(){
}
$("#set-Config input[name='save']").val(save);
-
-
$("#set-Config input[name='week']").val($(".planweek").find("b").attr("val"));
+
var sType = $(".planjs").find("b").attr("val");
var sBody = encodeURIComponent($("#implement textarea[name='sBody']").val());
if(sType == 'toFile'){
if($("#viewfile").val() == ''){
- layer.msg(lan.crontab.input_file_err,{icon:2});
+ layer.msg('请选择脚本文件!',{icon:2});
return;
}
- }else{
+ } else {
if(sBody == ''){
$("#implement textarea[name='sBody']").focus();
- layer.msg(lan.crontab.input_script_err,{icon:2});
+ layer.msg('脚本代码不能为空!',{icon:2});
return;
}
}
@@ -253,12 +251,12 @@ function planAdd(){
var urladdress = $("#urladdress").val();
if(sType == 'toUrl'){
if(!isURL(urladdress)){
- layer.msg(lan.crontab.input_url_err,{icon:2});
+ layer.msg('URL地址不正确!',{icon:2});
$("implement textarea[name='urladdress']").focus();
return;
}
}
- urladdress = encodeURIComponent(urladdress);
+ // urladdress = encodeURIComponent(urladdress);
$("#set-Config input[name='urladdress']").val(urladdress);
$("#set-Config input[name='sType']").val(sType);
$("#set-Config textarea[name='sBody']").val(decodeURIComponent(sBody));
@@ -268,7 +266,6 @@ function planAdd(){
$("#backupTo").val(backupTo);
}
-
var sName = $("#sName").attr("val");
if(sName == 'backupAll'){
@@ -279,16 +276,15 @@ function planAdd(){
dataList.push(tmp);
}
if(dataList.length < 1){
- layer.msg(lan.crontab.input_empty_err,{icon:5});
+ layer.msg('对象列表为空,无法继续!',{icon:5});
return;
}
-
allAddCrontab(dataList,0,'');
return;
}
$("#set-Config input[name='sName']").val(sName);
- layer.msg(lan.public.the_add,{icon:16,time:0,shade: [0.3, '#000']});
+ layer.msg('正在添加,请稍候...!',{icon:16,time:0,shade: [0.3, '#000']});
var data= $("#set-Config").serialize() + '&sBody='+sBody + '&urladdress=' + urladdress;
$.post('/crontab/add',data,function(rdata){
if(!rdata.status) {
@@ -358,7 +354,7 @@ $(".dropdown ul li a").click(function(){
break;
case 'day-n':
closeOpt();
- toWhere1(lan.crontab.day);
+ toWhere1('天');
toHour();
toMinute();
break;
@@ -368,12 +364,12 @@ $(".dropdown ul li a").click(function(){
break;
case 'hour-n':
closeOpt();
- toWhere1(lan.crontab.hour);
+ toWhere1('小时');
toMinute();
break;
case 'minute-n':
closeOpt();
- toWhere1(lan.crontab.minute);
+ toWhere1('分钟');
break;
case 'week':
closeOpt();
@@ -383,7 +379,7 @@ $(".dropdown ul li a").click(function(){
break;
case 'month':
closeOpt();
- toWhere1(lan.crontab.sun);
+ toWhere1('日');
toHour();
toMinute();
break;
@@ -392,27 +388,27 @@ $(".dropdown ul li a").click(function(){
break;
case 'toShell':
toShell();
- $(".controls").html(lan.crontab.sbody);
+ $(".controls").html('脚本内容');
break;
case 'rememory':
rememory();
- $(".controls").html(lan.public.msg);
+ $(".controls").html('提示');
break;
case 'site':
toBackup('sites');
- $(".controls").html(lan.crontab.backup_site);
+ $(".controls").html('备份网站');
break;
case 'database':
toBackup('databases');
- $(".controls").html(lan.crontab.backup_database);
+ $(".controls").html('备份数据库');
break;
case 'logs':
toBackup('logs');
- $(".controls").html(lan.crontab.log_site);
+ $(".controls").html('切割网站');
break;
case 'toUrl':
toUrl();
- $(".controls").html(lan.crontab.url_address);
+ $(".controls").html('URL地址');
break;
}
})
@@ -423,20 +419,20 @@ function toBackup(type){
var sMsg = "";
switch(type){
case 'sites':
- sMsg = lan.crontab.backup_site;
+ sMsg = '备份网站';
sType = "sites";
break;
case 'databases':
- sMsg = lan.crontab.backup_database;
+ sMsg = '备份数据库';
sType = "databases";
break;
case 'logs':
- sMsg = lan.crontab.backup_log;
+ sMsg = '切割日志';
sType = "sites";
break;
}
var data='type='+sType
- $.post('/crontab?action=GetDataList',data,function(rdata){
+ $.post('/crontab/get_data_list',data,function(rdata){
$(".planname input[name='name']").attr('readonly','true').css({"background-color":"#f6f6f6","color":"#666"});
var sOpt = "";
if(rdata.data.length == 0){
@@ -455,14 +451,13 @@ function toBackup(type){
orderOpt += ''+rdata.orderOpt[i].name+''
}
-
var sBody = '\
\
\
\
@@ -487,7 +482,7 @@ function toBackup(type){
if(!sName) return;
$(".planname input[name='name']").val(sMsg+'['+sName+']');
});
- });
+ },'json');
}
@@ -496,17 +491,18 @@ function editTaskInfo(id){
layer.msg('正在获取,请稍候...',{icon:16,time:0,shade: [0.3, '#000']});
$.post('/crontab/get_crond_find',{id:id},function(rdata){
layer.closeAll();
+ // console.log('init:', rdata);
var sTypeName = '',sTypeDom = '',cycleName = '',cycleDom = '',weekName = '',weekDom = '',sNameName ='',sNameDom = '',backupsName = '',backupsDom ='';
obj = {
from:{
id:rdata.id,
name: rdata.name,
- type: rdata.type,
+ type: rdata['type'],
+ stype: rdata.stype,
where1: rdata.where1,
hour: rdata.where_hour,
minute: rdata.where_minute,
week: rdata.where1,
- stype: rdata.stype,
sbody: rdata.sbody,
sname: rdata.sname,
backup_to: rdata.backup_to,
@@ -519,7 +515,6 @@ function editTaskInfo(id){
sNameArray:[],
backupsArray:[],
create:function(callback){
- console.log(obj);
for(var i = 0; i '+ obj['sNameArray'][i]['ps'] +'';
}
for(var i = 0; i '+ obj['backupsArray'][i]['name'] +'';
}
callback();
- });
+ },'json');
}else{
callback();
}
@@ -657,6 +656,8 @@ function editTaskInfo(id){
$('.site_list').show();
}
+ obj.from.minute = $('.minute_create').val();
+
$('.sName_create').blur(function () {
obj.from.name = $(this).val();
});
@@ -736,6 +737,7 @@ function editTaskInfo(id){
obj.from.where1 = '';
obj.from.hour = '';
obj.from.minute = 30;
+ console.log(obj.from);
break;
case 'week':
$('.week_btn').show();
@@ -774,7 +776,7 @@ function editTaskInfo(id){
if(obj.from.type == 'hour-n'){
obj.from.where1 = obj.from.hour;
obj.from.hour = '';
- }else if(obj.from.type == 'minute-n'){
+ } else if(obj.from.type == 'minute-n') {
obj.from.where1 = obj.from.minute;
obj.from.minute = '';
}
@@ -807,34 +809,34 @@ function closeOpt(){
function toWeek(){
var mBody = '\
\
\
';
$("#ptime").html(mBody);
- getselectname()
+ getselectname();
}
//指定1
function toWhere1(ix){
var mBody ='\
\
'+ix+'\
-
';
+ ';
$("#ptime").append(mBody);
}
//小时
function toHour(){
var mBody = '\
\
- '+lan.crontab.hour+'\
+ 小时\
';
$("#ptime").append(mBody);
}
@@ -843,7 +845,7 @@ function toHour(){
function toMinute(){
var mBody = '\
\
- '+lan.crontab.minute+'\
+ 分钟\
';
$("#ptime").append(mBody);
diff --git a/scripts/backup.py b/scripts/backup.py
new file mode 100755
index 000000000..7cd0337ca
--- /dev/null
+++ b/scripts/backup.py
@@ -0,0 +1,226 @@
+#!/usr/bin/python
+# coding: utf-8
+#-----------------------------
+# 网站备份工具
+#-----------------------------
+
+import sys
+import os
+
+if sys.platform != 'darwin':
+ os.chdir('/www/server/mdserver-web')
+
+
+chdir = os.getcwd()
+sys.path.append(chdir + '/class/core')
+reload(sys)
+sys.setdefaultencoding('utf-8')
+
+
+import public
+import db
+import time
+
+
+class backupTools:
+
+ def backupSite(self, name, count):
+ sql = db.Sql()
+ path = sql.table('sites').where('name=?', (name,)).getField('path')
+ startTime = time.time()
+ if not path:
+ endDate = time.strftime('%Y/%m/%d %X', time.localtime())
+ log = u"网站[" + name + "]不存在!"
+ print(u"★[" + endDate + "] " + log)
+ print(
+ "----------------------------------------------------------------------------")
+ return
+
+ backup_path = public.getRootDir() + '/backup/site'
+ if not os.path.exists(backup_path):
+ public.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")
+
+ endDate = time.strftime('%Y/%m/%d %X', time.localtime())
+
+ print filename
+ if not os.path.exists(filename):
+ log = u"网站[" + name + u"]备份失败!"
+ print(u"★[" + endDate + "] " + log)
+ print(
+ u"----------------------------------------------------------------------------")
+ return
+
+ outTime = time.time() - startTime
+ pid = sql.table('sites').where('name=?', (name,)).getField('id')
+ 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)
+ print(u"★[" + endDate + "] " + log)
+ print(u"|---保留最新的[" + count + u"]份备份")
+ print(u"|---文件名:" + filename)
+
+ # 清理多余备份
+ backups = sql.table('backup').where(
+ 'type=? and pid=?', ('0', pid)).field('id,filename').select()
+
+ num = len(backups) - int(count)
+ if num > 0:
+ for backup in backups:
+ public.execShell("rm -f " + backup['filename'])
+ sql.table('backup').where('id=?', (backup['id'],)).delete()
+ num -= 1
+ print(u"|---已清理过期备份文件:" + backup['filename'])
+ if num < 1:
+ break
+
+ def backupDatabase(self, name, count):
+ sql = db.Sql()
+ path = sql.table('databases').where('name=?', (name,)).getField('path')
+ startTime = time.time()
+ if not path:
+ endDate = time.strftime('%Y/%m/%d %X', time.localtime())
+ log = u"数据库[" + name + u"]不存在!"
+ print(u"★[" + endDate + "] " + log)
+ print(
+ u"----------------------------------------------------------------------------")
+ return
+
+ backup_path = public.getRootDir() + '/backup/database'
+ if not os.path.exists(backup_path):
+ public.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 = sql.table('config').where(
+ "id=?", (1,)).getField('mysql_root')
+
+ mycnf = public.readFile('/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('/etc/my.cnf', mycnf)
+
+ public.execShell(
+ "/www/server/mysql/bin/mysqldump --opt --default-character-set=utf8 " + name + " | gzip > " + filename)
+
+ if not os.path.exists(filename):
+ endDate = time.strftime('%Y/%m/%d %X', time.localtime())
+ log = u"数据库[" + name + u"]备份失败!"
+ print(u"★[" + endDate + "] " + log)
+ print(
+ u"----------------------------------------------------------------------------")
+ return
+
+ mycnf = public.readFile('/etc/my.cnf')
+ mycnf = mycnf.replace(subStr, sea)
+ if len(mycnf) > 100:
+ public.writeFile('/etc/my.cnf', mycnf)
+
+ endDate = time.strftime('%Y/%m/%d %X', time.localtime())
+ outTime = time.time() - startTime
+ pid = sql.table('databases').where('name=?', (name,)).getField('id')
+
+ sql.table('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)
+ print("★[" + endDate + "] " + log)
+ print(u"|---保留最新的[" + count + u"]份备份")
+ print(u"|---文件名:" + filename)
+
+ # 清理多余备份
+ backups = sql.table('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'])
+ sql.table('backup').where('id=?', (backup['id'],)).delete()
+ num -= 1
+ print(u"|---已清理过期备份文件:" + backup['filename'])
+ if num < 1:
+ break
+
+ # 备份指定目录
+ def backupPath(self, path, count):
+ sql = db.Sql()
+ startTime = time.time()
+ if path[-1:] == '/':
+ path = path[:-1]
+ name = os.path.basename(path)
+ backup_path = sql.table('config').where(
+ "id=?", (1,)).getField('backup_path') + '/path'
+ if not os.path.exists(backup_path):
+ os.makedirs(backup_path)
+ filename = backup_path + "/Path_" + name + "_" + \
+ time.strftime('%Y%m%d_%H%M%S', time.localtime()) + '.tar.gz'
+ os.system("cd " + os.path.dirname(path) + " && tar zcvf '" +
+ filename + "' '" + os.path.basename(path) + "' > /dev/null")
+
+ endDate = time.strftime('%Y/%m/%d %X', time.localtime())
+ if not os.path.exists(filename):
+ log = u"目录[" + path + "]备份失败"
+ print(u"★[" + endDate + "] " + log)
+ print(
+ u"----------------------------------------------------------------------------")
+ return
+
+ outTime = time.time() - startTime
+ sql.table('backup').add('type,name,pid,filename,addtime,size',
+ ('2', path, '0', filename, endDate, os.path.getsize(filename)))
+ log = u"目录[" + path + "]备份成功,用时[" + str(round(outTime, 2)) + "]秒"
+ public.writeLog(u'计划任务', log)
+ print(u"★[" + endDate + "] " + log)
+ print(u"|---保留最新的[" + count + u"]份备份")
+ print(u"|---文件名:" + filename)
+
+ # 清理多余备份
+ backups = sql.table('backup').where(
+ 'type=? and pid=? and name=?', ('2', 0, path)).field('id,filename').select()
+ num = len(backups) - int(count)
+ if num > 0:
+ for backup in backups:
+ public.execShell("rm -f " + backup['filename'])
+ sql.table('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()
+ for site in sites:
+ self.backupSite(site['name'], save)
+
+ def backupDatabaseAll(self, save):
+ databases = public.M('databases').field('name').select()
+ for database in databases:
+ self.backupDatabase(database['name'], save)
+
+
+if __name__ == "__main__":
+ backup = backupTools()
+ type = sys.argv[1]
+ if type == 'site':
+ if sys.argv[2] == 'ALL':
+ backup.backupSiteAll(sys.argv[3])
+ else:
+ backup.backupSite(sys.argv[2], sys.argv[3])
+ elif type == 'path':
+ backup.backupPath(sys.argv[2], sys.argv[3])
+ elif type == 'database':
+ if sys.argv[2] == 'ALL':
+ backup.backupDatabaseAll(sys.argv[3])
+ else:
+ backup.backupDatabase(sys.argv[2], sys.argv[3])
diff --git a/scripts/logs_backup.py b/scripts/logs_backup.py
new file mode 100755
index 000000000..beed24ba9
--- /dev/null
+++ b/scripts/logs_backup.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+# coding: utf-8
+#-----------------------------
+# 网站日志切割脚本
+#-----------------------------
+import sys
+import os
+import shutil
+import time
+import glob
+
+if sys.platform != 'darwin':
+ os.chdir('/www/server/mdserver-web')
+
+
+chdir = os.getcwd()
+sys.path.append(chdir + '/class/core')
+reload(sys)
+sys.setdefaultencoding('utf-8')
+
+import public
+print('==================================================================')
+print('★[' + time.strftime("%Y/%m/%d %H:%M:%S") + '],切割日志')
+print('==================================================================')
+print('|--当前保留最新的[' + sys.argv[2] + ']份')
+logsPath = public.getLogsDir()
+px = '.log'
+
+
+def split_logs(oldFileName, num):
+ global logsPath
+ if not os.path.exists(oldFileName):
+ print('|---' + oldFileName + '文件不存在!')
+ return
+
+ logs = sorted(glob.glob(oldFileName + "_*"))
+ count = len(logs)
+ num = count - num
+
+ for i in range(count):
+ if i > num:
+ break
+ os.remove(logs[i])
+ print('|---多余日志[' + logs[i] + ']已删除!')
+
+ newFileName = oldFileName + '_' + time.strftime("%Y-%m-%d_%H%M%S") + '.log'
+ shutil.move(oldFileName, newFileName)
+ print('|---已切割日志到:' + newFileName)
+
+
+def split_all(save):
+ sites = public.M('sites').field('name').select()
+ for site in sites:
+ oldFileName = logsPath + site['name'] + px
+ split_logs(oldFileName, save)
+
+if __name__ == '__main__':
+ num = int(sys.argv[2])
+ if sys.argv[1].find('ALL') == 0:
+ split_all(num)
+ else:
+ siteName = sys.argv[1]
+ if siteName[-4:] == '.log':
+ siteName = siteName[:-4]
+ else:
+ siteName = siteName.replace("-access_log", '')
+ oldFileName = logsPath + '/' + sys.argv[1]
+ split_logs(oldFileName, num)
+ path = public.getServerDir()
+ os.system("kill -USR1 `cat " + path + "/openresty/nginx/logs/nginx.pid`")
diff --git a/scripts/rememory.sh b/scripts/rememory.sh
index f132f632d..eb55fcec4 100755
--- a/scripts/rememory.sh
+++ b/scripts/rememory.sh
@@ -6,71 +6,73 @@ export PATH
#+------------------------------------
endDate=`date +"%Y-%m-%d %H:%M:%S"`
+sysName=`uname`
+curPath=`pwd`
+rootPath=$(dirname "$curPath")
+
log="释放内存!"
echo "★[$endDate] $log"
echo '----------------------------------------------------------------------------'
-if [ -f "/etc/init.d/php-fpm-52" ];then
- /etc/init.d/php-fpm-52 reload
-fi
-
-if [ -f "/etc/init.d/php-fpm-53" ];then
- /etc/init.d/php-fpm-53 reload
+if [ $sysName == 'Darwin' ]; then
+ echo '苹果内存释放!'
+else
+ echo 'do start!'
fi
-if [ -f "/etc/init.d/php-fpm-54" ];then
- /etc/init.d/php-fpm-54 reload
+if [ -f $rootPath"/php/init.d/php52" ];then
+ $rootPath"/php/init.d/php52" reload
fi
-if [ -f "/etc/init.d/php-fpm-55" ];then
- /etc/init.d/php-fpm-55 reload
-fi
-if [ -f "/etc/init.d/php-fpm-56" ];then
- /etc/init.d/php-fpm-56 reload
+if [ -f $rootPath"/php/init.d/php53" ];then
+ $rootPath"/php/init.d/php53" reload
fi
-if [ -f "/etc/init.d/php-fpm-70" ];then
- /etc/init.d/php-fpm-70 reload
+if [ -f $rootPath"/php/init.d/php54" ];then
+ $rootPath"/php/init.d/php54" reload
fi
-if [ -f "/etc/init.d/php-fpm-71" ];then
- /etc/init.d/php-fpm-71 reload
+if [ -f $rootPath"/php/init.d/php55" ];then
+ $rootPath"/php/init.d/php55" reload
fi
-if [ -f "/etc/init.d/php-fpm-72" ];then
- /etc/init.d/php-fpm-72 reload
+if [ -f $rootPath"/php/init.d/php56" ];then
+ $rootPath"/php/init.d/php56" reload
fi
-if [ -f "/etc/init.d/php-fpm-73" ];then
- /etc/init.d/php-fpm-73 reload
+if [ -f $rootPath"/php/init.d/php70" ];then
+ $rootPath"/php/init.d/php70" reload
fi
-if [ -f "/etc/init.d/php-fpm-74" ];then
- /etc/init.d/php-fpm-74 reload
+if [ -f $rootPath"/php/init.d/php71" ];then
+ $rootPath"/php/init.d/php71" reload
fi
-if [ -f "/etc/init.d/mysqld" ];then
- /etc/init.d/mysqld reload
+if [ -f $rootPath"/php/init.d/php72" ];then
+ $rootPath"/php/init.d/php72" reload
fi
-if [ -f "/etc/init.d/nginx" ];then
- /etc/init.d/nginx reload
+if [ -f $rootPath"/php/init.d/php73" ];then
+ $rootPath"/php/init.d/php73" reload
fi
-if [ -f "/etc/init.d/httpd" ];then
- /etc/init.d/httpd graceful
+if [ -f $rootPath"/php/init.d/php74" ];then
+ $rootPath"/php/init.d/php74" reload
fi
-if [ -f "/etc/init.d/pure-ftpd" ];then
- pkill -9 pure-ftpd
- sleep 0.3
- /etc/init.d/pure-ftpd start 2>/dev/null
+if [ -f $rootPath"/openresty/nginx/sbin/nginx" ];then
+ $rootPath"/openresty/nginx/sbin/nginx" -s reload
fi
sync
sleep 2
sync
-echo 3 > /proc/sys/vm/drop_caches
+
+if [ $sysName == 'Darwin' ]; then
+ echo 'done!'
+else
+ echo 3 > /proc/sys/vm/drop_caches
+fi
echo '----------------------------------------------------------------------------'
\ No newline at end of file