|
@@ -1,7 +1,6 @@
|
1
|
1
|
import os
|
2
|
2
|
from datetime import datetime, timedelta
|
3
|
3
|
import ftplib
|
4
|
|
-
|
5
|
4
|
from subprocess import Popen, PIPE
|
6
|
5
|
|
7
|
6
|
# DB_LIST = ['BDECR', 'BDEDO', 'BDEGT', 'BDEHN', 'BDENI', 'BDEPA', 'BDESV']
|
|
@@ -13,17 +12,32 @@ DB_HOST = '159.203.104.215'
|
13
|
12
|
BACKUP_PATH = '/backup/'
|
14
|
13
|
|
15
|
14
|
|
16
|
|
-def OpenFTP():
|
|
15
|
+def RemoveFile(filename):
|
17
|
16
|
try:
|
18
|
|
- ftp = ftplib.FTP("165.227.114.190")
|
19
|
|
- ftp.login("factor", 'rh$2021')
|
20
|
|
- ftp.cwd('upload')
|
21
|
|
- return ftp
|
|
17
|
+ os.remove(filename)
|
|
18
|
+ return
|
|
19
|
+ except BaseException as ex:
|
|
20
|
+ print(f'FILE REMOVE ERROR {ex}')
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+def OpenFTP(server='FACTOR'):
|
|
24
|
+ try:
|
|
25
|
+ if(server == 'FACTOR'):
|
|
26
|
+ ftp = ftplib.FTP("165.227.114.190")
|
|
27
|
+ ftp.login("factor", 'rh$2021')
|
|
28
|
+ ftp.cwd('upload')
|
|
29
|
+ return ftp
|
|
30
|
+ else:
|
|
31
|
+ ## port 2023
|
|
32
|
+ ftp = ftplib.FTP()
|
|
33
|
+ ftp.connect("190.122.187.218", 2023)
|
|
34
|
+ ftp.login("ming", 'dit2020 2020')
|
|
35
|
+
|
22
|
36
|
except ftplib.Error as er:
|
23
|
37
|
print(f'FTP open error { er }')
|
24
|
38
|
return
|
25
|
39
|
|
26
|
|
-def DeleteFromStorage(filename):
|
|
40
|
+def DeleteFromSSHStorage(filename):
|
27
|
41
|
try:
|
28
|
42
|
ftp = OpenFTP()
|
29
|
43
|
ftp.delete(filename)
|
|
@@ -35,7 +49,7 @@ def DeleteFromStorage(filename):
|
35
|
49
|
def lessDate(fecha,dias):
|
36
|
50
|
return ( fecha - timedelta(days=dias)).strftime('%Y-%m-%d')
|
37
|
51
|
|
38
|
|
-def deleteFactorRH():
|
|
52
|
+def DeleteFactorRH():
|
39
|
53
|
try:
|
40
|
54
|
ftp = OpenFTP()
|
41
|
55
|
NOW = datetime.now()
|
|
@@ -49,16 +63,16 @@ def deleteFactorRH():
|
49
|
63
|
|
50
|
64
|
ftp.close()
|
51
|
65
|
except Exception as error:
|
52
|
|
- print(error)
|
53
|
|
- print('FTP FACTOR DELETE ERROR {error}')
|
|
66
|
+ print(f'FTP FACTOR DELETE ERROR {error}')
|
54
|
67
|
|
55
|
68
|
|
56
|
|
-def PutOverSSH(path = '/home/ming/CODE/PyKup/backup/BDEDO-20082021-1145.sql', remote='mingmecca.sql'):
|
|
69
|
+def PutOverSSH(path='/home/ming/CODE/PyKup/backup/BDEDO-20082021-1145.sql',remote='mingmecca.sql'):
|
57
|
70
|
try:
|
58
|
71
|
ftp = OpenFTP()
|
59
|
72
|
with open(path, "rb") as file:
|
60
|
73
|
ftp.storbinary('STOR %s' % remote, file)
|
61
|
74
|
ftp.close()
|
|
75
|
+ RemoveFile(path)
|
62
|
76
|
except BaseException as err:
|
63
|
77
|
print(f"FTP CREATE ERROR {err}")
|
64
|
78
|
return
|
|
@@ -106,11 +120,11 @@ def MysqlBK():
|
106
|
120
|
|
107
|
121
|
|
108
|
122
|
PutOverSSH(FILE_NAME, FILE)
|
109
|
|
- DeleteFromStorage( f'{DB_NAME}-' + TO_DELETE + '.sql' )
|
|
123
|
+ DeleteFromSSHStorage( f'{DB_NAME}-' + TO_DELETE + '.sql' )
|
110
|
124
|
return
|
111
|
125
|
|
112
|
|
-# MysqlBK()
|
|
126
|
+MysqlBK()
|
|
127
|
+DeleteFactorRH()
|
113
|
128
|
# MongoBK()
|
114
|
|
-deleteFactorRH()
|
115
|
129
|
# Backup()
|
116
|
130
|
# PutOverSSH()
|