-
Notifications
You must be signed in to change notification settings - Fork 0
/
htdoxer.py
68 lines (63 loc) · 2.45 KB
/
htdoxer.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os, shutil
# nama program
program_name = 'HTDoxer'
author = 'github.com/powzee'
# isi path dibawah
path = 'C:\\xampp\\htdocs\\'
xampp_mysql_path = 'C:\\xampp\\mysql\\bin\\'
output_backup = f'D:\\{program_name}\\'
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
clear()
class HTDoxer():
def __init__(self):
self.listdir = os.listdir(path)
self.listdir = [i for i in self.listdir if '.' not in i]
self.listdir = [i for i in self.listdir if i not in ['dashboard','img','webalizer','xampp','test']]
def add_path(self):
if xampp_mysql_path not in os.environ['PATH']:
os.environ['PATH'] += f';{xampp_mysql_path}'
else:
pass
def make_backup_folder(self):
if not os.path.exists(f'{output_backup}'):
os.mkdir(f'{output_backup}')
else:
pass
def backup_database(self, db_name, folder_name):
try:
os.system(f'mysqldump -u root {db_name} > {output_backup}{folder_name}\\database\\{db_name}.sql')
except:
print('XAMPP tidak aktif atau XAMPP MySQL tidak tersedia di path sistem!')
def xampp_dir(self):
num = 0
for i in self.listdir:
num += 1
print(f'{num}. {i}')
def backup(self):
self.add_path()
print('='*25 + f' {program_name.upper()} ' + '='*25)
print('List Folder di htdocs kamu:')
self.xampp_dir()
print('='*59)
print('Created by: ' + author)
print('='*59)
folder_index = int(input('Pilih Folder: '))
database_name = input('Nama Database: ')
folder_name = self.listdir[folder_index-1]
print('='*59)
if folder_name not in os.listdir(path):
print('Folder tidak ada!')
else:
print(f'Sedang mem-backup folder {folder_name}...')
self.make_backup_folder()
if folder_name in os.listdir(output_backup):
shutil.rmtree(f'{output_backup}{folder_name}')
shutil.copytree(f'{path}{folder_name}', f'{output_backup}{folder_name}')
os.mkdir(f'{output_backup}{folder_name}\\database')
print(f'Sedang mem-backup database {database_name} ...')
self.backup_database(database_name, folder_name)
print('Backup Selesai')
if __name__ == '__main__':
htdoxer = HTDoxer()
htdoxer.backup()