]> arthur.barton.de Git - bup.git/blobdiff - cmd/save-cmd.py
cmd/split: add a new --keep-boundaries option.
[bup.git] / cmd / save-cmd.py
index edb712a1001435562f2dbaaf4fe1fdd0116d4f34..e9b6e9e9ec8e7738e21712918e2067fd6eebe000 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-import sys, re, errno, stat, time, math
+import sys, stat, time, math
 from bup import hashsplit, git, options, index, client
 from bup.helpers import *
 
@@ -7,13 +7,15 @@ from bup.helpers import *
 optspec = """
 bup save [-tc] [-n name] <filenames...>
 --
-r,remote=  remote repository path
+r,remote=  hostname:/path/to/repo of remote repository
 t,tree     output a tree id
 c,commit   output a commit id
 n,name=    name of backup set to update (if any)
+d,date=    date for the commit (seconds since the epoch)
 v,verbose  increase log output (can be used more than once)
 q,quiet    don't show progress meter
 smaller=   only back up files smaller than n bytes
+bwlimit=   maximum bytes/sec to transmit to server
 """
 o = options.Options('bup save', optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
@@ -26,6 +28,13 @@ if not extra:
 
 opt.progress = (istty and not opt.quiet)
 opt.smaller = parse_num(opt.smaller or 0)
+if opt.bwlimit:
+    client.bwlimit = parse_num(opt.bwlimit)
+
+if opt.date:
+    date = parse_date_or_fatal(opt.date, o.fatal)
+else:
+    date = time.time()
 
 is_reverse = os.environ.get('BUP_SERVER_REVERSE')
 if is_reverse and opt.remote:
@@ -33,7 +42,12 @@ if is_reverse and opt.remote:
 
 refname = opt.name and 'refs/heads/%s' % opt.name or None
 if opt.remote or is_reverse:
-    cli = client.Client(opt.remote)
+    if opt.remote and opt.remote.find(":") == -1:
+        o.fatal("--remote argument must contain a colon")
+    try:
+        cli = client.Client(opt.remote)
+    except client.ClientError:
+        o.fatal("server exited unexpectedly; see errors above")
     oldref = refname and cli.read_ref(refname) or None
     w = cli.new_packwriter()
 else:
@@ -71,8 +85,9 @@ def _pop(force_tree):
     return tree
 
 lastremain = None
+lastprint = 0
 def progress_report(n):
-    global count, subcount, lastremain
+    global count, subcount, lastremain, lastprint
     subcount += n
     cc = count + subcount
     pct = total and (cc*100.0/total) or 0
@@ -104,9 +119,17 @@ def progress_report(n):
             remainstr = '%dm%d' % (mins, secs)
         else:
             remainstr = '%ds' % secs
-    progress('Saving: %.2f%% (%d/%dk, %d/%d files) %s %s\r'
-             % (pct, cc/1024, total/1024, fcount, ftotal,
-                remainstr, kpsstr))
+    if now - lastprint > 0.1:
+        progress('Saving: %.2f%% (%d/%dk, %d/%d files) %s %s\r'
+                 % (pct, cc/1024, total/1024, fcount, ftotal,
+                    remainstr, kpsstr))
+        lastprint = now
+
+
+def vlog(s):
+    global lastprint
+    lastprint = 0
+    log(s)
 
 
 r = index.Reader(git.repo('bupindex'))
@@ -156,10 +179,10 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
         else:
             status = ' '
         if opt.verbose >= 2:
-            log('%s %-70s\n' % (status, ent.name))
+            vlog('%s %-70s\n' % (status, ent.name))
         elif not stat.S_ISDIR(ent.mode) and lastdir != dir:
             if not lastdir.startswith(dir):
-                log('%s %-70s\n' % (status, os.path.join(dir, '')))
+                vlog('%s %-70s\n' % (status, os.path.join(dir, '')))
             lastdir = dir
 
     if opt.progress:
@@ -183,6 +206,7 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
             _push(part)
 
     if not file:
+        # no filename portion means this is a subdir.  But
         # sub/parentdirectories already handled in the pop/push() part above.
         oldtree = already_saved(ent) # may be None
         newtree = _pop(force_tree = oldtree)
@@ -201,7 +225,9 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
     if hashvalid:
         mode = '%o' % ent.gitmode
         id = ent.sha
-        shalists[-1].append((mode, file, id))
+        shalists[-1].append((mode, 
+                             git.mangle_name(file, ent.mode, ent.gitmode),
+                             id))
     else:
         if stat.S_ISREG(ent.mode):
             try:
@@ -213,7 +239,7 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
                 add_error(e)
                 lastskip_name = ent.name
             else:
-                (mode, id) = hashsplit.split_to_blob_or_tree(w, [f])
+                (mode, id) = hashsplit.split_to_blob_or_tree(w, [f], False)
         else:
             if stat.S_ISDIR(ent.mode):
                 assert(0)  # handled above
@@ -234,7 +260,9 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
         if id:
             ent.validate(int(mode, 8), id)
             ent.repack()
-            shalists[-1].append((mode, file, id))
+            shalists[-1].append((mode,
+                                 git.mangle_name(file, ent.mode, ent.gitmode),
+                                 id))
     if exists and wasmissing:
         count += oldsize
         subcount = 0
@@ -254,7 +282,7 @@ if opt.tree:
 if opt.commit or opt.name:
     msg = 'bup save\n\nGenerated by command:\n%r' % sys.argv
     ref = opt.name and ('refs/heads/%s' % opt.name) or None
-    commit = w.new_commit(oldref, tree, msg)
+    commit = w.new_commit(oldref, tree, date, msg)
     if opt.commit:
         print commit.encode('hex')