-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup_servidor.py
77 lines (71 loc) · 3.26 KB
/
backup_servidor.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
69
70
71
72
73
74
75
76
77
"""
/***************************************************************************
LEOXINGU
-------------------
begin : 2017-09-25
copyright : (C) 2017 by Leandro Franca - Cartographic Engineer
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation. *
* *
***************************************************************************/
"""
# BACKUP DE SERVIDOR
##6. BACKUP DE SERVIDOR=name
##LF01) PostGIS=group
##Host=string localhost
##Versao_do_PostgreSQL=selection 10;9.3;9.4;9.5;9.6
##Arquivo_de_backup=output file
##Usuario=string postgres
# Inputs
host = str(Host)
lista = [10,9.3,9.4,9.5,9.6]
version = str(lista[Versao_do_PostgreSQL])
saida = Arquivo_de_backup
if saida[-4:] != '.sql':
saida += '.sql'
import os
from PyQt4.QtCore import *
from qgis.gui import QgsMessageBar
from qgis.utils import iface
from qgis.core import *
import time
local = 'C:/Program Files/PostgreSQL/'+version+'/bin'
sentinela = False
if os.path.isdir(local):
os.chdir(local)
sentinela = True
else:
local = 'C:\Program Files (x86)/PostgreSQL/'+version+'/bin'
if os.path.isdir(local):
os.chdir(local)
sentinela = True
else:
progress.setInfo('<b>Problema(s) durante a execucao do backup.</b><br/>')
progress.setInfo('<b>Verifique se a versao do PostgreSQL foi definida corretamente.</b><br/>')
time.sleep(8)
iface.messageBar().pushMessage(u'Erro', "Problema(s) durante a execucao do comando.", level=QgsMessageBar.CRITICAL, duration=5)
if 'backup.file' in saida:
sentinela = False
progress.setInfo('<b>Problema(s) durante a execucao do backup.</b><br/>')
progress.setInfo('<b>Verifique se o nome do banco de dados foi escrito corretamente.</b><br/>')
time.sleep(8)
iface.messageBar().pushMessage(u'Erro', "Problema(s) durante a execucao do comando.", level=QgsMessageBar.CRITICAL, duration=5)
if sentinela:
comando = 'pg_dumpall -h %s -p 5432 -U ' %host +Usuario+ ' -v -f "%s"' %saida
progress.setInfo('<b>Realizando backup do servidor...</b><br/>')
result = os.system(comando)
if result==0:
progress.setInfo('<b>Operacao concluida com sucesso!</b><br/><br/>')
progress.setInfo('<b>Leandro França - Eng Cart</b><br/>')
time.sleep(4)
iface.messageBar().pushMessage(u'Situacao', "Operacao Concluida com Sucesso!", level=QgsMessageBar.INFO, duration=5)
else:
progress.setInfo('<b>Problema(s) durante a execucao do backup.</b><br/>')
progress.setInfo('<b>Verifique se os parametros foram definidos corretamente.</b><br/>')
time.sleep(8)
iface.messageBar().pushMessage(u'Erro', "Problema(s) durante a execucao do backup.", level=QgsMessageBar.CRITICAL, duration=10)