Example #1
0
    def connect(self):
        """
        Connect to potentially provided locations arguments, remote or local.

        Defines the current time as being the time of a potentially upcoming
        backup.
        Returns self, to be used as context manager.
        """

        if 'locations' in self.values:
            # TODO encapsulate the following lines into one
            # connections/connections_mgr construct, so that the action doesn't
            # need to care about cmdpairs and Security (which would become a
            # feature of the connection).
            cmdpairs = SetConnections.get_cmd_pairs(
                self.values.locations,
                remote_schema=self.remote_schema,
                ssh_compression=self.values.ssh_compression,
                remote_tempdir=self.remote_tempdir,
                term_verbosity=log.Log.term_verbosity)
            Security.initialize(self.get_security_class(), cmdpairs)
            self.connected_locations = list(
                map(SetConnections.get_connected_rpath, cmdpairs))
        else:
            Security.initialize(self.get_security_class(), [])
            self.connected_locations = []

        # once the connection is set, we can define "now" as being the current
        # time, unless the user defined a fixed a current time.
        Time.set_current_time(self.values.current_time)

        return self
Example #2
0
def InternalBackup(source_local, dest_local, src_dir, dest_dir,
				   current_time = None, eas = None, acls = None):
	"""Backup src to dest internally

	This is like rdiff_backup but instead of running a separate
	rdiff-backup script, use the separate *.py files.  This way the
	script doesn't have to be rebuild constantly, and stacktraces have
	correct line/file references.

	"""
	Globals.current_time = current_time
	#_reset_connections()
	Globals.security_level = "override"
	remote_schema = '%s'

	if not source_local:
		src_dir = "cd test1; python ../server.py ../%s::../%s" % \
				  (SourceDir, src_dir)
	if not dest_local:
		dest_dir = "cd test2/tmp; python ../../server.py ../../%s::../../%s" \
				   % (SourceDir, dest_dir)

	cmdpairs = SetConnections.get_cmd_pairs([src_dir, dest_dir], remote_schema)
	Security.initialize("backup", cmdpairs)
	rpin, rpout = map(SetConnections.cmdpair2rp, cmdpairs)
	for attr in ('eas_active', 'eas_write', 'eas_conn'):
		SetConnections.UpdateGlobal(attr, eas)
	for attr in ('acls_active', 'acls_write', 'acls_conn'):
		SetConnections.UpdateGlobal(attr, acls)
	Main.misc_setup([rpin, rpout])
	Main.Backup(rpin, rpout)
	Main.cleanup()
Example #3
0
def _internal_get_cmd_pairs(src_local, dest_local, src_dir, dest_dir):
    """Function returns a tuple of connections based on the given parameters.
    One or both directories are faked for remote connection if not local,
    and the connections are set accordingly.
    Note that the function relies on the global variables
    abs_remote1_dir, abs_remote2_dir and abs_testing_dir."""

    remote_schema = b'%s'  # compat200: replace with {h}
    remote_format = b"cd %s; %s/server.py::%s"

    if not src_local:
        src_dir = remote_format % (abs_remote1_dir, abs_testing_dir, src_dir)
    if not dest_local:
        dest_dir = remote_format % (abs_remote2_dir, abs_testing_dir, dest_dir)

    if src_local and dest_local:
        return SetConnections.get_cmd_pairs([src_dir, dest_dir])
    else:
        return SetConnections.get_cmd_pairs([src_dir, dest_dir], remote_schema)
Example #4
0
def InternalRestore(mirror_local,
                    dest_local,
                    mirror_dir,
                    dest_dir,
                    time,
                    eas=None,
                    acls=None):
    """Restore mirror_dir to dest_dir at given time

    This will automatically find the increments.XXX.dir representing
    the time specified.  The mirror_dir and dest_dir are relative to
    the testing directory and will be modified for remote trials.

    """
    Main.force = 1
    Main.restore_root_set = 0
    remote_schema = b'%s'
    Globals.security_level = "override"
    if not mirror_local:
        mirror_dir = b"cd %s; %s/server.py::%s" % (abs_remote1_dir,
                                                   abs_testing_dir, mirror_dir)
    if not dest_local:
        dest_dir = b"cd %s; %s/server.py::%s" % (abs_remote2_dir,
                                                 abs_testing_dir, dest_dir)

    cmdpairs = SetConnections.get_cmd_pairs([mirror_dir, dest_dir],
                                            remote_schema)
    Security.initialize("restore", cmdpairs)
    mirror_rp, dest_rp = list(map(SetConnections.cmdpair2rp, cmdpairs))
    for attr in ('eas_active', 'eas_write', 'eas_conn'):
        SetConnections.UpdateGlobal(attr, eas)
    for attr in ('acls_active', 'acls_write', 'acls_conn'):
        SetConnections.UpdateGlobal(attr, acls)
    Main.misc_setup([mirror_rp, dest_rp])
    inc = get_increment_rp(mirror_rp, time)
    if inc:
        Main.Restore(get_increment_rp(mirror_rp, time), dest_rp)
    else:  # use alternate syntax
        Main.restore_timestr = str(time)
        Main.Restore(mirror_rp, dest_rp, restore_as_of=1)
    Main.cleanup()
Example #5
0
    def connect(self):
        """
        Connect to potentially provided locations arguments, remote or local.

        Returns self, to be used as context manager.
        """

        if 'locations' in self.values:
            # TODO encapsulate the following lines into one
            # connections/connections_mgr construct, so that the action doesn't
            # need to care about cmdpairs and Security (which would become a
            # feature of the connection).
            cmdpairs = SetConnections.get_cmd_pairs(
                self.values.locations,
                remote_schema=self.remote_schema,
                ssh_compression=self.values.ssh_compression)
            Security.initialize(self.get_security_class(), cmdpairs)
            self.connected_locations = list(
                map(SetConnections.get_connected_rpath, cmdpairs))
        else:
            self.connected_locations = []

        return self
Example #6
0
def InternalRestore(mirror_local, dest_local, mirror_dir, dest_dir, time,
					eas = None, acls = None):
	"""Restore mirror_dir to dest_dir at given time

	This will automatically find the increments.XXX.dir representing
	the time specified.  The mirror_dir and dest_dir are relative to
	the testing directory and will be modified for remote trials.

	"""
	Main.force = 1
	Main.restore_root_set = 0
	remote_schema = '%s'
	Globals.security_level = "override"
	#_reset_connections()
	if not mirror_local:
		mirror_dir = "cd test1; python ../server.py ../%s::../%s" % \
					 (SourceDir, mirror_dir)
	if not dest_local:
		dest_dir = "cd test2/tmp; python ../../server.py ../../%s::../../%s" \
				   % (SourceDir, dest_dir)

	cmdpairs = SetConnections.get_cmd_pairs([mirror_dir, dest_dir],
											remote_schema)
	Security.initialize("restore", cmdpairs)
	mirror_rp, dest_rp = map(SetConnections.cmdpair2rp, cmdpairs)
	for attr in ('eas_active', 'eas_write', 'eas_conn'):
		SetConnections.UpdateGlobal(attr, eas)
	for attr in ('acls_active', 'acls_write', 'acls_conn'):
		SetConnections.UpdateGlobal(attr, acls)
	Main.misc_setup([mirror_rp, dest_rp])
	inc = get_increment_rp(mirror_rp, time)
	if inc: Main.Restore(get_increment_rp(mirror_rp, time), dest_rp)
	else: # use alternate syntax
		Main.restore_timestr = str(time)
		Main.Restore(mirror_rp, dest_rp, restore_as_of = 1)
	Main.cleanup()