MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / backup

Method backup

utils.py:221–242  ·  view source on GitHub ↗
(self, handler)

Source from the content-addressed store, hash-verified

219 handler.wfile.write(json.dumps({"status": "error", "message": str(e)}).encode('utf-8'))
220
221 def backup(self, handler):
222 try:
223 timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
224 backup_filename = f"backup_{timestamp}.zip"
225 backup_path = os.path.join(self.shared_data.backupdir, backup_filename)
226
227 with zipfile.ZipFile(backup_path, 'w') as backup_zip:
228 for folder in [self.shared_data.configdir, self.shared_data.datadir, self.shared_data.actions_dir, self.shared_data.resourcesdir]:
229 for root, dirs, files in os.walk(folder):
230 for file in files:
231 file_path = os.path.join(root, file)
232 backup_zip.write(file_path, os.path.relpath(file_path, self.shared_data.currentdir))
233
234 handler.send_response(200)
235 handler.send_header("Content-type", "application/json")
236 handler.end_headers()
237 handler.wfile.write(json.dumps({"status": "success", "url": f"/download_backup?filename={backup_filename}", "filename": backup_filename}).encode('utf-8'))
238 except Exception as e:
239 handler.send_response(500)
240 handler.send_header("Content-type", "application/json")
241 handler.end_headers()
242 handler.wfile.write(json.dumps({"status": "error", "message": str(e)}).encode('utf-8'))
243
244 def restore(self, handler):
245 try:

Callers

nothing calls this directly

Calls 2

writeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected