Skip to content

Instantly share code, notes, and snippets.

@decko
Created December 11, 2020 00:23
Show Gist options
  • Save decko/ed3dcf9b93392768645e785a4095fa8a to your computer and use it in GitHub Desktop.
Save decko/ed3dcf9b93392768645e785a4095fa8a to your computer and use it in GitHub Desktop.
My oldest python script...
#! /usr/bin/python
# -*- coding: utf-8 -*-
##############################################################
# Programa para Backup de Partições XFS.
# André Filipe de Assuncao e Brito (decko@noisemakers.org)
# Fabricio Coutinho Medeiros (fabriciocoutinho@terra.com.br)
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##############################################################
import os, sys, time
EMAILADMIN='decko@stacasa.dom.br;fabricio@stacasa.dom.br' #Email dos administradores do sistema para receberem uma copia do log
DEVICEDEST='/home' #Dispositivo ou arquivo de destino do backup
DEVICEORIG='/home' #Diretorio de Origem do Backup. XFS Obrigatoriamente.
DEVICETAPE='/dev/tape'
BKPFITA='0' #1 se o backup for em fita magnetica, 0 se for em um arquivo.
def diahoje():
epoch=time.time()
localtime=time.localtime(epoch)
return time.strftime('%d', localtime)
def datacompleta():
epoch=time.time()
localtime=time.localtime(epoch)
return time.strftime('%b-%Y', localtime)
def default(DEVICEORIG,DEVICEDEST,DEVICETAPE,BKPFITA):
print "Modo padrão de backup"
HOJE = diahoje()
DATA = datacompleta()
HOME = os.getenv('HOME')
BKDST = DEVICEDEST + HOJE + DATA + '.xfsdump'
LOG=open(HOME + '/' + HOJE + '-' + DATA + '.log','w')
if HOJE == 1:
if BKPFITA == "0":
xfs=os.popen('xfsdump -l 0 -p 2 -L ' + HOJE + DATA + ' ' + '-M file -f ' + DEVICEDEST + BKDST + 'l0' + ' ' + DEVICEORIG)
for line in xfs.readlines():
print line,
LOG.write(line)
else:
xfs=os.popen('xfsdump -l 0 -p 2 -L ' + HOJE + DATA + ' ' + '-M tape -f ' + DEVICETAPE + ' ' + DEVICEORIG)
for line in xfs.readlines():
print line,
LOG.write(line)
else:
if BKPFITA == "0":
xfs=os.popen('xfsdump -l 1 -p 2 -L ' + HOJE + DATA + ' ' + '-M file -f ' + DEVICEDEST + BKDST + 'l1' + ' ' + DEVICEORIG)
for line in xfs.readlines():
print line,
LOG.write(line)
else:
xfs=os.popen('xfsdump -l 1 -p 2 -L ' + HOJE + DATA + ' ' + '-M file -f ' + DEVICETAPE + ' ' + DEVICEORIG)
for line in xfs.readlines():
print line,
LOG.write(line)
if __name__ == '__main__':
print sys.copyright
print "Backup system by André Filipe e Fabricio Coutinho"
if len(sys.argv) != 1:
print "Use: %s" % sys.argv[0]
else:
default(DEVICEORIG,DEVICEDEST,DEVICETAPE,BKPFITA)
@ZamanOof
Copy link

Nice, Thanks
what about increment to -l 2,-l3,-l4 etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment