From 185502edc9cd902e8f5d4e0305b79c922b35144c Mon Sep 17 00:00:00 2001 From: jose <627622230@qq.com> Date: Wed, 26 Jun 2019 18:26:45 +0800 Subject: [PATCH] Provide decompression support for bz2 compression format --- class/panelTask.py | 2 ++ script/backup.py | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/class/panelTask.py b/class/panelTask.py index 63044f6a..6e7ef97d 100644 --- a/class/panelTask.py +++ b/class/panelTask.py @@ -257,6 +257,8 @@ class bt_task: os.system('echo "'+password+'"|' + rar_file + ' x -u -y "' + sfile + '" "' + dfile + '" &> ' + log_file) elif sfile[-4:] == '.war': os.system("unzip -P '"+password+"' -o '" + sfile + "' -d '" + dfile + "' &> " + log_file) + elif sfile[-4:] == '.bz2': + os.system("tar jxvf '" + sfile + "' -C '" + dfile + "' &> " + log_file) else: os.system("gunzip -c " + sfile + " > " + sfile[:-3]) diff --git a/script/backup.py b/script/backup.py index ca9112d9..0ef0418b 100644 --- a/script/backup.py +++ b/script/backup.py @@ -13,7 +13,11 @@ if sys.version_info[0] == 2: import public,db,time class backupTools: - + __exclude = "" + + def __init__(self): + self.get_exclode() + def backupSite(self,name,count): sql = db.Sql(); path = sql.table('sites').where('name=?',(name,)).getField('path'); @@ -27,9 +31,8 @@ class backupTools: backup_path = sql.table('config').where("id=?",(1,)).getField('backup_path') + '/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") + public.ExecShell("cd " + os.path.dirname(path) + " && tar zcvf '" + filename + "' '" + os.path.basename(path) + "'"+self.__exclude +" > /dev/null") endDate = time.strftime('%Y/%m/%d %X',time.localtime()) @@ -48,6 +51,7 @@ class backupTools: print(u"★["+endDate+"] " + log) print(public.GetMsg("KEEP_PART",(count,))) print(public.GetMsg("FTP_FILE_NAME")+filename) + if self.__exclude: print(u"|---Exclusion rules: " + self.__exclude) #清理多余备份 backups = sql.table('backup').where('type=? and pid=? and filename!=? and filename!=? and filename!=? and filename!=? and filename!=?',('0',pid,'alioss','txcos','upyun','qiniu','ftp')).field('id,filename').select(); @@ -150,7 +154,8 @@ class backupTools: print(u"★["+endDate+"] " + log) print(public.GetMsg("KEEP_PART",(count,))) print(public.GetMsg("FTP_FILE_NAME")+filename) - + if self.__exclude: print(u"|---Exclusion rules: " + self.__exclude) + #清理多余备份 backups = sql.table('backup').where('type=? and pid=? and name=?',('2',0,path)).field('id,filename').select(); num = len(backups) - int(count) @@ -174,7 +179,14 @@ class backupTools: for database in databases: self.backupDatabase(database['name'],save) - + def get_exclode(self): + tmp_exclude = os.getenv('BT_EXCLUDE') + if not tmp_exclude: return "" + for ex in tmp_exclude.split(','): + self.__exclude += " --exclude=\"" + ex + "\"" + self.__exclude += " " + return self.__exclude + if __name__ == "__main__":