Skip to content

Instantly share code, notes, and snippets.

@andreztz
Created August 13, 2016 06:34
Show Gist options
  • Save andreztz/588fd6e1d9349f58ad5bceaa4287b0e1 to your computer and use it in GitHub Desktop.
Save andreztz/588fd6e1d9349f58ad5bceaa4287b0e1 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import shutil
import os
import time
import sys
origem = '/home/suporte/Downloads'
destino = '/home/suporte/%s' % time.strftime('%d-%m-%Y_%H:%M:%S')
'''
FORMATOS DISPONÍVEIS
('bztar', "bzip2'ed tar-file"), ('gztar', "gzip'ed tar-file"),
('tar', 'uncompressed tar file'), ('xztar', "xz'ed tar-file"),
('zip', 'ZIP file')
'''
tipo = 'zip'
log = destino+'.txt'
def cabecalho():
hora_inicio = (time.strftime("%d-%m-%Y"))
data_inicio = (time.strftime('%H:%M:%S'))
inicio = '''
======================================================================
|| ____ _____ _ ___ _ _____ ______ _ _ _ _ ||
|| | _ \ /\ / ____| |/ / | | | __ \ | ____| | | | | | | ||
|| | |_) | / \ | | | ' /| | | | |__) | | |__ | | | | | | | ||
|| | _ < / /\ \| | | < | | | | ___/ | __| | | | | | | | ||
|| | |_) / ____ \ |____| . \| |__| | | | | | |__| | |____| |____ ||
|| |____/_/ \_\_____|_|\_ \____/|_| |_| \____/|______|______| ||
|| ||
|| ||
|| BACKUP FULL INICIADO EM %s ÀS %s ||
======================================================================
\n ''' % (hora_inicio, data_inicio)
return inicio
def rodape():
data_final = (time.strftime('%H:%M:%S'))
hora_final = (time.strftime('%d-%m-%Y'))
fim = '''
===========================================================================
BACKUP FULL FINALIZADO
FINALIZADO EM : %s - %s
ARQUIVO DE LOG SALVO EM : %s
ORIGEM DO BACKUP : %s
DESTINO DO BACKUP : %s.%s
===========================================================================
\n''' % (hora_final, data_final, log, origem, destino, tipo)
return fim
def gerar_ilog():
# GRAVAR ARQUIVO COM O LOG INICIAL.
cab = cabecalho()
ilog = open(log, 'a')
ilog.write(cab)
ilog.close()
def gerar_flog():
# GRAVAR ARQUIVO COM O LOG FINAL.
rod = rodape()
flog = open(log, 'a')
flog.write(rod)
flog.close()
def gerar_backup():
gerar_ilog()
print('[!] GERANDO BACKUP AGUARDE [!]')
compactar = shutil.make_archive(destino, tipo, origem)
tamanho = os.path.getsize(compactar)
banner = '''
===========================================================================
TAMANHO TOTAL DO BACKUP COMPACTADO %d b (Byte).
TAMANHO TOTAL DO BACKUP COMPACTADO %.2f Kb (KiloByte).
TAMANHO TOTAL DO BACKUP COMPACTADO %.2f Mb (MegaByte).
TAMANHO TOTAL DO BACKUP COMPACTADO %.2f Gb (GigaByte).
===========================================================================
\n''' % (tamanho, (tamanho/1024), (tamanho/1024/1024), (tamanho/1024/1024/1024))
size = open(log, 'a')
size.write(banner)
size.close()
gerar_flog()
print('[!] BACKUP CONCLUÍDO [!]')
def sair():
print('[!] saindo do sistema [!]')
sys.exit()
def opcoes(x):
try:
opcao = {'1': gerar_backup, '2': sair}
opcao[x]()
except Exception as e:
print('[!] DIGITE UMA OPÇÃO VALIDA !! %s [!]' % e)
def menu():
print(' \
1 - Fazer backup completo 2 - Sair \n')
opcao = str(input('Digite o numero da opção desejada: '))
return opcao
if __name__ == '__main__':
opcoes(menu())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment