Пример #1
0
 def job(self, run: "Run", payload: dict, device: Device) -> dict:
     now = app.strip_all(app.get_time())
     source = Path.cwd() / "projects" / "migrations" / f"backup_{now}.tgz"
     app.migrate_export(Path.cwd(), {
         "import_export_types": import_classes,
         "name": f"backup_{now}"
     })
     with open_tar(source, "w:gz") as tar:
         tar.add(Path.cwd() / "projects" / "migrations" / f"backup_{now}",
                 arcname="/")
     ssh_client = SSHClient()
     ssh_client.set_missing_host_key_policy(AutoAddPolicy())
     ssh_client.connect(
         device.ip_address,
         username=device.username,
         password=device.password,
         look_for_keys=False,
     )
     destination = f"{run.sub(run.destination_path, locals())}/backup_{now}.tgz"
     run.transfer_file(ssh_client, [(source, destination)])
     ssh_client.close()
     if run.delete_folder:
         rmtree(Path.cwd() / "projects" / "migrations" / f"backup_{now}")
     if run.delete_archive:
         remove(source)
     return {
         "success": True,
         "result": f"backup stored in {destination} ({device.ip_address})",
     }
Пример #2
0
 def filename(self):
     return app.strip_all(self.name)