Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed librarization correctly by not relying on globals

  • Loading branch information...
commit c381459001b0b09f918c0b2069c332bb0e454941 1 parent 0f7fc56
root authored
Showing with 17 additions and 12 deletions.
  1. +7 −4 zfslib.py
  2. +10 −8 zmirror
View
11 zfslib.py
@@ -274,26 +274,29 @@ def snapshot_recursively(self,name,snapshotname):
run_command(self.command+["snapshot","-r","%s@%s"%(name,snapshotname)])
self._dirty = True
- def send(self,name,opts=None):
+ def send(self,name,opts=None,bufsize=-1):
if not opts: opts = []
cmd = self.command + ["send"] + opts + [name]
p = subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,bufsize=bufsize)
return p
- def receive(self,name,pipe,opts=None):
+ def receive(self,name,pipe,opts=None,bufsize=-1):
if not opts: opts = []
cmd = self.command + ["receive"] + opts + [name]
p = subprocess.Popen(cmd,stdin=pipe,stdout=subprocess.PIPE,bufsize=bufsize)
return p
- def transfer(src_conn,dst_conn,s,d,fromsnapshot=None,showprogress=False):
+ def transfer(src_conn,dst_conn,s,d,fromsnapshot=None,showprogress=False,bufsize=-1):
if fromsnapshot: fromsnapshot=["-i",fromsnapshot]
else: fromsnapshot = []
sndprg = src_conn.send(s,opts=["-v"]+fromsnapshot)
if showprogress:
+ barargs = []
+ if bufsize != -1:
+ barargs = ["-bs",str(bufsize)]
try: barprg = subprocess.Popen(
- ["clpbar","-dan","-bs",str(bufsize)],
+ ["clpbar","-dan"] + barargs,
stdin=sndprg.stdout,stdout=subprocess.PIPE,bufsize=bufsize)
except OSError:
os.kill(sndprg.pid,15)
View
18 zmirror
@@ -4,6 +4,8 @@
import sys
import optparse
import os
+import time
+import sets
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from zfslib import children_first, parents_first, chronosorted
from zfslib import Dataset, Pool, Snapshot, PoolSet, ZFSConnection
@@ -120,39 +122,39 @@ for srcpath in [ x.get_path() for x in source_dataset.walk() if not isinstance(x
print " s0r0: snapshotting and sending full snapshot"
if not opts.dryrun:
src_conn.snapshot_recursively(srcpath,snapshot_unique_name)
- src_conn.transfer(dst_conn, mksn(srcpath,snapshot_unique_name), mksn(dstpath,snapshot_unique_name),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,snapshot_unique_name), mksn(dstpath,snapshot_unique_name),showprogress=opts.progress,bufsize=bufsize)
else:
print " s0r>0: destroying receiver side filesystems, snapshotting and sending full snapshot"
if not opts.dryrun:
dst_conn.destroy(dstpath)
src_conn.snapshot_recursively(srcpath,snapshot_unique_name)
- src_conn.transfer(dst_conn, mksn(srcpath,snapshot_unique_name), mksn(dstpath,snapshot_unique_name),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,snapshot_unique_name), mksn(dstpath,snapshot_unique_name),showprogress=opts.progress,bufsize=bufsize)
elif one(ssn):
if no(dsn):
# one snapshot on the sender, none here
print " s1r0: sending latest snapshot in full"
if not opts.dryrun:
- src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress,bufsize=bufsize)
else:
if last(ssn) == last(dsn):
# matching snapshots on both sides
print " s1rXmatch: snapshotting and sending incremental snapshot"
if not opts.dryrun:
src_conn.snapshot_recursively(srcpath,snapshot_unique_name)
- src_conn.transfer(dst_conn, mksn(srcpath,snapshot_unique_name), mksn(dstpath,snapshot_unique_name), last(ssn),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,snapshot_unique_name), mksn(dstpath,snapshot_unique_name), last(ssn),showprogress=opts.progress,bufsize=bufsize)
else:
print " s1rXnomatch: destroying receiver side filesystems, sending full snapshot"
if not opts.dryrun:
dst_conn.destroy(dstpath)
- src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress,bufsize=bufsize)
else:
if no(dsn):
# two snapshots on the sender, none here
print " s>1r0: sending latest snapshot in full"
if not opts.dryrun:
- src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress,bufsize=bufsize)
else:
if last(ssn) == last(dsn):
# latest matching snapshots on both sides
@@ -161,12 +163,12 @@ for srcpath in [ x.get_path() for x in source_dataset.walk() if not isinstance(x
# two snapshots on the sender, the old one matching here
print " s>1rXmatch: sending incremental snapshot"
if not opts.dryrun:
- src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)), last(dsn),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)), last(dsn),showprogress=opts.progress,bufsize=bufsize)
else:
print " s2r1nomatch: destroying receiver side filesystems, sending full snapshot"
if not opts.dryrun:
dst_conn.destroy(dstpath)
- src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress)
+ src_conn.transfer(dst_conn, mksn(srcpath,last(ssn)), mksn(dstpath,last(ssn)),showprogress=opts.progress,bufsize=bufsize)
backed_up_datasets.add(dstpath)
print ""
Please sign in to comment.
Something went wrong with that request. Please try again.