3 from bup import hashsplit, git, options, client
4 from bup.helpers import *
8 bup split [-tcb] [-n name] [--bench] [filenames...]
10 r,remote= remote repository path
11 b,blobs output a series of blob ids
12 t,tree output a tree id
13 c,commit output a commit id
14 n,name= name of backup set to update (if any)
15 d,date= date for the commit (seconds since the epoch)
16 q,quiet don't print progress messages
17 v,verbose increase log output (can be used more than once)
18 keep-boundaries don't let one chunk span two input files
19 noop don't actually save the data anywhere
20 copy just copy input to output, hashsplitting along the way
21 bench print benchmark timings to stderr
22 max-pack-size= maximum bytes in a single pack
23 max-pack-objects= maximum number of objects in a single pack
24 fanout= maximum number of blobs in a single tree
25 bwlimit= maximum bytes/sec to transmit to server
27 o = options.Options('bup split', optspec)
28 (opt, flags, extra) = o.parse(sys.argv[1:])
31 git.check_repo_or_die()
32 if not (opt.blobs or opt.tree or opt.commit or opt.name or
33 opt.noop or opt.copy):
34 o.fatal("use one or more of -b, -t, -c, -n, -N, --copy")
35 if (opt.noop or opt.copy) and (opt.blobs or opt.tree or
36 opt.commit or opt.name):
37 o.fatal('-N and --copy are incompatible with -b, -t, -c, -n')
40 git.verbose = opt.verbose - 1
43 hashsplit.max_pack_size = parse_num(opt.max_pack_size)
44 if opt.max_pack_objects:
45 hashsplit.max_pack_objects = parse_num(opt.max_pack_objects)
47 hashsplit.fanout = parse_num(opt.fanout)
51 client.bwlimit = parse_num(opt.bwlimit)
53 date = parse_date_or_fatal(opt.date, o.fatal)
58 is_reverse = os.environ.get('BUP_SERVER_REVERSE')
59 if is_reverse and opt.remote:
60 o.fatal("don't use -r in reverse mode; it's automatic")
61 start_time = time.time()
63 refname = opt.name and 'refs/heads/%s' % opt.name or None
64 if opt.noop or opt.copy:
65 cli = pack_writer = oldref = None
66 elif opt.remote or is_reverse:
67 if opt.remote and opt.remote.find(":") == -1:
68 o.fatal("--remote argument must contain a colon")
70 cli = client.Client(opt.remote)
71 except client.ClientError:
72 o.fatal("server exited unexpectedly; see errors above")
73 oldref = refname and cli.read_ref(refname) or None
74 pack_writer = cli.new_packwriter()
77 oldref = refname and git.read_ref(refname) or None
78 pack_writer = git.PackWriter()
80 files = extra and (open(fn) for fn in extra) or [sys.stdin]
82 shalist = hashsplit.split_to_shalist(pack_writer, files,
83 keep_boundaries=opt.keep_boundaries)
84 tree = pack_writer.new_tree(shalist)
87 for (blob, bits) in hashsplit.hashsplit_iter(files,
88 keep_boundaries=opt.keep_boundaries):
89 hashsplit.total_split += len(blob)
91 sys.stdout.write(str(blob))
92 megs = hashsplit.total_split/1024/1024
93 if not opt.quiet and last != megs:
94 progress('%d Mbytes read\r' % megs)
96 progress('%d Mbytes read, done.\n' % megs)
101 for (mode,name,bin) in shalist:
102 print bin.encode('hex')
104 print tree.encode('hex')
105 if opt.commit or opt.name:
106 msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
107 ref = opt.name and ('refs/heads/%s' % opt.name) or None
108 commit = pack_writer.new_commit(oldref, tree, date, msg)
110 print commit.encode('hex')
113 pack_writer.close() # must close before we can update the ref
117 cli.update_ref(refname, commit, oldref)
119 git.update_ref(refname, commit, oldref)
124 secs = time.time() - start_time
125 size = hashsplit.total_split
127 log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
128 % (size/1024., secs, size/1024./secs))