MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / ToBackup

Method ToBackup

class/databaseModel/sqliteModel.py:109–132  ·  view source on GitHub ↗

@name 备份数据库 @param args['path'] 数据库路径 @return bool

(self,args)

Source from the content-addressed store, hash-verified

107
108
109 def ToBackup(self,args):
110 """
111 @name 备份数据库
112 @param args['path'] 数据库路径
113 @return bool
114 """
115 path = args.path
116 if not os.path.exists(path):
117 return public.returnMsg(False,'数据库不存在.')
118
119 data = self.get_database_list()
120 if not path in data:
121 return public.returnMsg(False,'数据库不存在.')
122
123 fileName = '{}_{}'.format(time.strftime('%Y%m%d_%H%M%S',time.localtime()),os.path.basename(path))
124 backup_path = '{}/database/sqlite/{}'.format(session['config']['backup_path'],public.md5(path))
125 if not os.path.exists(backup_path):
126 os.makedirs(backup_path)
127
128 backup_file = '{}/{}'.format(backup_path,fileName)
129 shutil.copy(path,backup_file)
130 if os.path.exists(backup_file):
131 return public.returnMsg(True,'备份成功.')
132 return public.returnMsg(False,'备份失败.')
133
134
135 def DelBackup(self,args):

Callers

nothing calls this directly

Calls 7

get_database_listMethod · 0.95
returnMsgMethod · 0.80
basenameMethod · 0.80
existsMethod · 0.45
formatMethod · 0.45
md5Method · 0.45
copyMethod · 0.45

Tested by

no test coverage detected