|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#21 | |
|
Senior Member
Iscritto dal: Nov 2001
Città: Menzoberranzan(ovvero Italia..)
Messaggi: 486
|
Quote:
Cioè il tuo prog crea una lista di tutti i files presenti nelle dir che vuoi backuppare,e una volta ottenuta questa esegue un controllo sulla dimensione di ognuno,e poi?
__________________
"L'immaginazione è più importante della conoscenza. La conoscenza è limitata, l'immaginazione abbraccia il mondo." Albert Einstein |
|
|
|
|
|
|
#22 | |
|
Senior Member
Iscritto dal: Dec 2002
Città: /dev/urandom breed
Messaggi: 1689
|
Quote:
Questo che segue sostanzialmente fa quanto fa find: Codice:
#!/usr/bin/python
VERSION=0.0.1
import sys, os, getopt
EXCLUDE="/etc/mybackup/exclude.lst"
CONFIG="/etc/mybackup/mybackup.conf"
def usage():
print "%s is part of mybackup." %(sys.argv[0])
print "%s generates file list to use with mkarchive, from a given path" %(sys.argv[0])
print "usage: %s [opts] basedir" %(sys.argv[0])
print "\t-h : display this message"
print "\t-V : show version and exit"
print "\t-f <file> : use <file> as configuration file, not default (%s)" %(CONFIG)
print "\t-x <file> : optional exclude list (default: %s)" %(EXCLUDE)
def print_if(exclude, dirname, fnames):
for f in fnames:
good = 1
cur = os.path.join(dirname, f)
if(os.path.isdir(cur)):
continue
# ci pensera` un'altra invocazione fatta da os.path.walk
for x in exclude:
if cur.find(x) != -1:
good = 0
if good:
print cur
try:
opts, args = getopt.getopt(sys.argv[1:], "f:x:h")
except getopt.GetoptError:
pass
opts = dict(opts)
if opts.has_key("-V"):
print "%s version %s" %(sys.argv[0], str(VERSION))
sys.exit()
if not args or len(args) > 1 or opts.has_key("-h"):
usage()
sys.exit(0)
try:
exclude = [ f[:-1] for f in file(opts["-x"], 'r').readlines() ]
except KeyError, IOError:
exclude = []
basedir = args[0]
os.path.walk(basedir, print_if, exclude)
Codice:
#!/usr/bin/python
VERSION=0.0.1
import sys, os, getopt
MAX_SIZE=long(700*1024*1024) # in bytes!
VERBOSE=False
def usage():
print "%s is part of mybackup." %(sys.argv[0])
print "%s generates segmentated file list to use with mkarchive, to create archive limited in size" %(sys.argv[0])
print "usage: cat fulldirlist | %s [opts] segbasename" %(sys.argv[0])
print "\t-h : display this message"
print "\t-v : verbose execution"
print "\t-f <file> : --UNRECOGNIZED-- use <file> as configuration file, not default"
print "\t-s <size> : maximum segment size (default: %s)" %(str(MAX_SIZE))
def fmkname(name, seq):
return name + '_' + str(seq)
try:
opts, args = getopt.getopt(sys.argv[1:], "f:s:hv")
except getopt.GetoptError:
pass
opts = dict(opts)
if opts.has_key("-V"):
print "%s version %s" %(sys.argv[0], str(VERSION))
sys.exit()
if not args or len(args) > 1 or opts.has_key("-h"):
usage()
sys.exit(0)
try:
seg_size = long(int(opts["-s"]) * 1024 * 1024)
except KeyError:
seg_size = MAX_SIZE
if opts.has_key("-v"):
VERBOSE=True
basename = args[0]
seg_num = 0
cur_size = 0
lines = 0
f = file(fmkname(basename, seg_num), "w")
while 1:
lines += 1
l = sys.stdin.readline()[:-1]
if not l:
break
try:
s = os.stat(l)[6]
except OSError:
print("[%s] set #%s: unable to stat '%s', skipped..." %(sys.argv[0], str(seg_num), l))
if (cur_size + s) > seg_size:
# rotate file
seg_num += 1
cur_size = 0
f.close()
f = file(fmkname(basename, seg_num), "w")
cur_size += s
f.write(l + '\n')
if VERBOSE:
print("[%s] set #%s: including '%s'" %(sys.argv[0], str(seg_num), l))
if VERBOSE:
print "[%s] done: %s files in %s segments" %(sys.argv[0], str(lines), str(seg_num+1))
PS: richiesto Python 2.2 o superiore o un po` di adattamento del codice... Ultima modifica di Ikitt_Claw : 04-12-2003 alle 09:11. |
|
|
|
|
|
|
#23 |
|
Senior Member
Iscritto dal: Jun 2003
Città: Lontano Lontano icq#:121214179 Skype:sniperpat [email protected] modalità:Fancazzamento continuo
Messaggi: 1682
|
"tar -cjvf backup.tar.bz2 /"
__________________
Snu snu |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:10.



















