-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup_xui.py
45 lines (45 loc) · 1.72 KB
/
backup_xui.py
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
import subprocess
import os
import shutil
def backup_do():
os.chdir('/root/')
try :
shutil.rmtree('/root/backup-xui/', ignore_errors=True)
finally:
os.mkdir("/root/backup-xui/")
shutil.copyfile("/root/Config-server/backup.py", "/root/backup-xui/backup.py")
shutil.copyfile("/root/Config-server/data.py", "/root/backup-xui/data.py")
p1 = subprocess.run(["apt", '-y', 'update'])
if p1.returncode == 0 :
print("\napt update done")
else :
print("\nunable to do update")
p1 = subprocess.run(["apt", 'install', 'python3'])
if p1.returncode == 0 :
print("\npython3 installed")
else :
print("\nunable to install python3")
p1 = subprocess.run(["apt", 'install', 'cron'])
if p1.returncode == 0 :
print("\ncron installed")
else :
print("\nunable to install cron")
p1 = subprocess.run(["apt", 'install', 'python3-pip'])
if p1.returncode == 0 :
print("\npython3-pip installed")
else :
print("\nunable to install python3-pip")
p1 = subprocess.run(["pip", 'install', 'pyTelegramBotAPI'])
if p1.returncode == 0 :
print("download pyTelegramBotAPI done")
else :
print("unable to download pyTelegramBotAPI")
script_path = '/root/backup-xui/backup.py'
cron_job = f'\n0 * * * * /usr/bin/python3 {script_path}\n'
try :
with open('/etc/cron.d/mycron', 'w') as file:
file.write(cron_job)
print("\nCronjob created")
except :
print ("\ncronjob failed")
subprocess.run(["python3", "/root/backup-xui/backup.py"])