-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtermuxMenager.py
More file actions
60 lines (54 loc) · 2.29 KB
/
termuxMenager.py
File metadata and controls
60 lines (54 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import asyncio
import subprocess
class Color:
GREEN = '\033[92m'
RED = '\033[91m'
END = '\033[0m'
class BackupManager:
def __init__(self, source_dir, backup_file):
self.source_dir = source_dir
self.backup_file = backup_file
async def backup_data(self):
cmd = ["tar", "-cvf", self.backup_file, "."]
process = await asyncio.create_subprocess_exec(*cmd, cwd=self.source_dir)
await process.communicate()
if process.returncode == 0:
print(Color.GREEN + "Backup successful." + Color.END)
else:
print(Color.RED + "Backup failed." + Color.END)
async def restore_data(self):
cmd = ["tar", "-xvf", self.backup_file, "-C", self.source_dir]
process = await asyncio.create_subprocess_exec(*cmd)
await process.communicate()
if process.returncode == 0:
print(Color.GREEN + "Data restoration successful." + Color.END)
else:
print(Color.RED + "Data restoration failed." + Color.END)
async def main():
source_dir = "/data/data/com.termux"
backup_file = input("Enter the path where you want to store the backup (default is /sdcard/termux_backup.tar): ")
if not backup_file:
backup_file = "/sdcard/termux_backup.tar"
print("No path entered. The backup will be stored at /sdcard/termux_backup.tar by default.")
backup_manager = BackupManager(source_dir, backup_file)
while True:
print("1. Backup data")
print("2. Restore data")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == '1':
await backup_manager.backup_data()
elif choice == '2':
restore_file = input("Enter the path of the backup file you want to restore (default is /sdcard/termux_backup.tar): ")
if not restore_file:
restore_file = "/sdcard/termux_backup.tar"
print("No path entered. The backup will be restored from /sdcard/termux_backup.tar by default.")
backup_manager.backup_file = restore_file
await backup_manager.restore_data()
elif choice == '3':
break
else:
print(Color.RED + "Invalid choice. Please try again." + Color.END)
if __name__ == "__main__":
asyncio.run(main())