-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.py
executable file
·45 lines (36 loc) · 1.15 KB
/
sql.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
#!/usr/bin/python
import config
import os
def processSql(sqlTmpDir, filename):
log = "Processing sql sources\n"
# First, let's make sure we're actually using the sql database source flag in config
if config.sqlBackup == True:
# If the SQL temp backup location doesn't exist, create it.
if not os.path.exists(sqlTmpDir):
os.makedirs(sqlTmpDir)
# Then process each database
for source in config.sqlServers:
sql = createSqlConn(source[0], source[1], source[2], source[3])
dbFileName = sqlTmpDir + "/" + source[0] + "_" + filename + ".sql"
processBackup(sql, dbFileName)
log += sql.log
else:
log += "SQL Backup not enabled\n"
return {
'log':log,
'enabled':config.sqlBackup
}
def createSqlConn(backend, db_user, db_pass, db_host):
if backend == "mysql":
import backup_sources.databases.mysql
sql = backup_sources.databases.mysql.sql(db_user, db_pass, db_host)
return sql
else:
raise Exception("No valid SQL providers match the source given.")
def processBackup(sql, dbFileName):
sql.obtainBackup(dbFileName)
def checkDir(d):
if not os.path.exists(d):
os.makedirs(d)
if __name__ == "__main__":
processSql("temp")