def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) self.parsed_url = parsed_url self.remote_path = self.parsed_url.path self.rclone_cmd = u"rclone" try: rc, o, e = self._subprocess_safe_popen(self.rclone_cmd + u" version") except Exception: log.FatalError(u"rclone not found: please install rclone", log.ErrorCode.backend_error) verb = log.getverbosity() if verb >= log.DEBUG: os.environ[u"RCLONE_LOG_LEVEL"] = u"DEBUG" elif verb >= log.INFO: os.environ[u"RCLONE_LOG_LEVEL"] = u"INFO" elif verb >= log.NOTICE: os.environ[u"RCLONE_LOG_LEVEL"] = u"NOTICE" elif verb >= log.ERROR: os.environ[u"RCLONE_LOG_LEVEL"] = u"ERROR" if parsed_url.path.startswith(u"//"): self.remote_path = self.remote_path[2:].replace(u":/", u":", 1) self.remote_path = util.fsdecode(self.remote_path)
def get_duplicity_log_level(): """ Get the current duplicity log level as a stdlib-compatible logging level""" duplicity_log_level = log.LevelName(log.getverbosity()) # notice is a duplicity-specific logging level not supported by stdlib if duplicity_log_level == 'NOTICE': duplicity_log_level = 'INFO' return duplicity_log_level
def get_duplicity_log_level(): u""" Get the current duplicity log level as a stdlib-compatible logging level""" duplicity_log_level = log.LevelName(log.getverbosity()) # notice is a duplicity-specific logging level not supported by stdlib if duplicity_log_level == u'NOTICE': duplicity_log_level = u'INFO' return duplicity_log_level
def Log(s, verb_level, code=1, extra=None, force_print=False): if verb_level <= log.getverbosity(): output.extend(s.split("\n"))
def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) # we expect an output try: p = os.popen("lftp --version") fout = p.read() ret = p.close() except Exception: pass # there is no output if lftp not found if not fout: log.FatalError("LFTP not found: Please install LFTP.", log.ErrorCode.ftps_lftp_missing) # version is the second word of the second part of the first line version = fout.split('\n')[0].split(' | ')[1].split()[1] log.Notice("LFTP version is %s" % version) self.parsed_url = parsed_url # self.url_string = duplicity.backend.strip_auth_from_url(self.parsed_url) # # strip lftp+ prefix # self.url_string = duplicity.backend.strip_prefix(self.url_string, 'lftp') self.scheme = duplicity.backend.strip_prefix(parsed_url.scheme, 'lftp').lower() self.scheme = re.sub('^webdav', 'http', self.scheme) self.url_string = self.scheme + '://' + parsed_url.hostname if parsed_url.port: self.url_string += ":%s" % parsed_url.port self.remote_path = re.sub('^/', '', parsed_url.path) # Fix up an empty remote path if len(self.remote_path) == 0: self.remote_path = '/' # Use an explicit directory name. if self.remote_path[-1] != '/': self.remote_path += '/' self.authflag = '' if self.parsed_url.username: self.username = self.parsed_url.username self.password = self.get_password() self.authflag = "-u '%s,%s'" % (self.username, self.password) if globals.ftp_connection == 'regular': self.conn_opt = 'off' else: self.conn_opt = 'on' # check for cacert file if https self.cacert_file = globals.ssl_cacert_file if self.scheme == 'https' and not globals.ssl_no_check_certificate: cacert_candidates = ["~/.duplicity/cacert.pem", "~/duplicity_cacert.pem", "/etc/duplicity/cacert.pem"] # if not self.cacert_file: for path in cacert_candidates: path = os.path.expanduser(path) if (os.path.isfile(path)): self.cacert_file = path break # still no cacert file, inform user if not self.cacert_file: raise duplicity.errors.FatalBackendException("""For certificate verification a cacert database file is needed in one of these locations: %s Hints: Consult the man page, chapter 'SSL Certificate Verification'. Consider using the options --ssl-cacert-file, --ssl-no-check-certificate .""" % ", ".join(cacert_candidates)) self.tempfile, self.tempname = tempdir.default().mkstemp() os.write(self.tempfile, "set ssl:verify-certificate " + ("false" if globals.ssl_no_check_certificate else "true") + "\n") if globals.ssl_cacert_file: os.write(self.tempfile, "set ssl:ca-file '" + globals.ssl_cacert_file + "'\n") if self.parsed_url.scheme == 'ftps' or self.parsed_url.scheme == 'ftpes': os.write(self.tempfile, "set ftp:ssl-allow true\n") os.write(self.tempfile, "set ftp:ssl-protect-data true\n") os.write(self.tempfile, "set ftp:ssl-protect-list true\n") else: os.write(self.tempfile, "set ftp:ssl-allow false\n") os.write(self.tempfile, "set http:use-propfind true\n") os.write(self.tempfile, "set net:timeout %s\n" % globals.timeout) os.write(self.tempfile, "set net:max-retries %s\n" % globals.num_retries) os.write(self.tempfile, "set ftp:passive-mode %s\n" % self.conn_opt) if log.getverbosity() >= log.DEBUG: os.write(self.tempfile, "debug\n") log.Debug("Changed") os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.parsed_url.hostname)) # os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.url_string)) # os.write(self.tempfile, "open %s %s\n" % (self.portflag, self.parsed_url.hostname)) # allow .netrc auth by only setting user/pass when user was actually given # if self.parsed_url.username: # os.write(self.tempfile, "user %s %s\n" % (self.parsed_url.username, self.password)) os.close(self.tempfile) if log.getverbosity() >= log.DEBUG: f = open(self.tempname, 'r') log.Debug("SETTINGS: \n" "%s" % f.readlines())
def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) # we expect an output try: p = os.popen(u"lftp --version") fout = p.read() ret = p.close() except Exception: pass # there is no output if lftp not found if not fout: log.FatalError(u"LFTP not found: Please install LFTP.", log.ErrorCode.ftps_lftp_missing) # version is the second word of the second part of the first line version = fout.split(u'\n')[0].split(u' | ')[1].split()[1] log.Notice(u"LFTP version is %s" % version) self.parsed_url = parsed_url self.scheme = duplicity.backend.strip_prefix(parsed_url.scheme, u'lftp').lower() self.scheme = re.sub(u'^webdav', u'http', self.scheme) self.url_string = self.scheme + u'://' + parsed_url.hostname if parsed_url.port: self.url_string += u":%s" % parsed_url.port self.remote_path = re.sub(u'^/', u'', parsed_url.path) # Fix up an empty remote path if len(self.remote_path) == 0: self.remote_path = u'/' # Use an explicit directory name. if self.remote_path[-1] != u'/': self.remote_path += u'/' self.authflag = u'' if self.parsed_url.username: self.username = self.parsed_url.username self.password = self.get_password() self.authflag = u"-u '%s,%s'" % (self.username, self.password) if globals.ftp_connection == u'regular': self.conn_opt = u'off' else: self.conn_opt = u'on' # check for cacert file if https self.cacert_file = globals.ssl_cacert_file if self.scheme == u'https' and not globals.ssl_no_check_certificate: cacert_candidates = [ u"~/.duplicity/cacert.pem", u"~/duplicity_cacert.pem", u"/etc/duplicity/cacert.pem" ] # look for a default cacert file if not self.cacert_file: for path in cacert_candidates: path = os.path.expanduser(path) if (os.path.isfile(path)): self.cacert_file = path break # save config into a reusable temp file self.tempfd, self.tempname = tempdir.default().mkstemp() self.tempfile = os.fdopen(self.tempfd, u"w") self.tempfile.write(u"set ssl:verify-certificate " + ( u"false" if globals.ssl_no_check_certificate else u"true") + u"\n") if self.cacert_file: self.tempfile.write(u"set ssl:ca-file " + cmd_quote(self.cacert_file) + u"\n") if globals.ssl_cacert_path: self.tempfile.write(u"set ssl:ca-path " + cmd_quote(globals.ssl_cacert_path) + u"\n") if self.parsed_url.scheme == u'ftps': self.tempfile.write(u"set ftp:ssl-allow true\n") self.tempfile.write(u"set ftp:ssl-protect-data true\n") self.tempfile.write(u"set ftp:ssl-protect-list true\n") elif self.parsed_url.scheme == u'ftpes': self.tempfile.write(u"set ftp:ssl-force on\n") self.tempfile.write(u"set ftp:ssl-protect-data on\n") self.tempfile.write(u"set ftp:ssl-protect-list on\n") else: self.tempfile.write(u"set ftp:ssl-allow false\n") self.tempfile.write(u"set http:use-propfind true\n") self.tempfile.write(u"set net:timeout %s\n" % globals.timeout) self.tempfile.write(u"set net:max-retries %s\n" % globals.num_retries) self.tempfile.write(u"set ftp:passive-mode %s\n" % self.conn_opt) if log.getverbosity() >= log.DEBUG: self.tempfile.write(u"debug\n") if self.parsed_url.scheme == u'ftpes': self.tempfile.write( u"open %s %s\n" % (self.authflag, self.url_string.replace(u'ftpes', u'ftp'))) else: self.tempfile.write(u"open %s %s\n" % (self.authflag, self.url_string)) self.tempfile.close() # print settings in debug mode if log.getverbosity() >= log.DEBUG: f = open(self.tempname, u'r') log.Debug(u"SETTINGS: \n" u"%s" % f.read())
def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) # we expect an output try: p = os.popen("lftp --version") fout = p.read() ret = p.close() except Exception: pass # there is no output if lftp not found if not fout: log.FatalError("LFTP not found: Please install LFTP.", log.ErrorCode.ftps_lftp_missing) # version is the second word of the second part of the first line version = fout.split('\n')[0].split(' | ')[1].split()[1] log.Notice("LFTP version is %s" % version) self.parsed_url = parsed_url self.scheme = duplicity.backend.strip_prefix(parsed_url.scheme, 'lftp').lower() self.scheme = re.sub('^webdav', 'http', self.scheme) self.url_string = self.scheme + '://' + parsed_url.hostname if parsed_url.port: self.url_string += ":%s" % parsed_url.port self.remote_path = re.sub('^/', '', parsed_url.path) # Fix up an empty remote path if len(self.remote_path) == 0: self.remote_path = '/' # Use an explicit directory name. if self.remote_path[-1] != '/': self.remote_path += '/' self.authflag = '' if self.parsed_url.username: self.username = self.parsed_url.username self.password = self.get_password() self.authflag = "-u '%s,%s'" % (self.username, self.password) if globals.ftp_connection == 'regular': self.conn_opt = 'off' else: self.conn_opt = 'on' # check for cacert file if https self.cacert_file = globals.ssl_cacert_file if self.scheme == 'https' and not globals.ssl_no_check_certificate: cacert_candidates = ["~/.duplicity/cacert.pem", "~/duplicity_cacert.pem", "/etc/duplicity/cacert.pem"] # look for a default cacert file if not self.cacert_file: for path in cacert_candidates: path = os.path.expanduser(path) if (os.path.isfile(path)): self.cacert_file = path break # save config into a reusable temp file self.tempfile, self.tempname = tempdir.default().mkstemp() os.write(self.tempfile, "set ssl:verify-certificate " + ("false" if globals.ssl_no_check_certificate else "true") + "\n") if self.cacert_file: os.write(self.tempfile, "set ssl:ca-file " + cmd_quote(self.cacert_file) + "\n") if globals.ssl_cacert_path: os.write(self.tempfile, "set ssl:ca-path " + cmd_quote(globals.ssl_cacert_path) + "\n") if self.parsed_url.scheme == 'ftps': os.write(self.tempfile, "set ftp:ssl-allow true\n") os.write(self.tempfile, "set ftp:ssl-protect-data true\n") os.write(self.tempfile, "set ftp:ssl-protect-list true\n") elif self.parsed_url.scheme == 'ftpes': os.write(self.tempfile, "set ftp:ssl-force on\n") os.write(self.tempfile, "set ftp:ssl-protect-data on\n") os.write(self.tempfile, "set ftp:ssl-protect-list on\n") else: os.write(self.tempfile, "set ftp:ssl-allow false\n") os.write(self.tempfile, "set http:use-propfind true\n") os.write(self.tempfile, "set net:timeout %s\n" % globals.timeout) os.write(self.tempfile, "set net:max-retries %s\n" % globals.num_retries) os.write(self.tempfile, "set ftp:passive-mode %s\n" % self.conn_opt) if log.getverbosity() >= log.DEBUG: os.write(self.tempfile, "debug\n") if self.parsed_url.scheme == 'ftpes': os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.url_string.replace('ftpes', 'ftp'))) else: os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.url_string)) os.close(self.tempfile) # print settings in debug mode if log.getverbosity() >= log.DEBUG: f = open(self.tempname, 'r') log.Debug("SETTINGS: \n" "%s" % f.read())
def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) # we expect an output try: p = os.popen("lftp --version") fout = p.read() ret = p.close() except Exception: pass # there is no output if lftp not found if not fout: log.FatalError("LFTP not found: Please install LFTP.", log.ErrorCode.ftps_lftp_missing) # version is the second word of the second part of the first line version = fout.split('\n')[0].split(' | ')[1].split()[1] log.Notice("LFTP version is %s" % version) self.parsed_url = parsed_url # self.url_string = duplicity.backend.strip_auth_from_url(self.parsed_url) # # strip lftp+ prefix # self.url_string = duplicity.backend.strip_prefix(self.url_string, 'lftp') self.scheme = duplicity.backend.strip_prefix(parsed_url.scheme, 'lftp').lower() self.scheme = re.sub('^webdav', 'http', self.scheme) self.url_string = self.scheme + '://' + parsed_url.hostname if parsed_url.port: self.url_string += ":%s" % parsed_url.port self.remote_path = re.sub('^/', '', parsed_url.path) # Fix up an empty remote path if len(self.remote_path) == 0: self.remote_path = '/' # Use an explicit directory name. if self.remote_path[-1] != '/': self.remote_path += '/' self.authflag = '' if self.parsed_url.username: self.username = self.parsed_url.username self.password = self.get_password() self.authflag = "-u '%s,%s'" % (self.username, self.password) if globals.ftp_connection == 'regular': self.conn_opt = 'off' else: self.conn_opt = 'on' # check for cacert file if https self.cacert_file = globals.ssl_cacert_file if self.scheme == 'https' and not globals.ssl_no_check_certificate: cacert_candidates = ["~/.duplicity/cacert.pem", "~/duplicity_cacert.pem", "/etc/duplicity/cacert.pem"] # if not self.cacert_file: for path in cacert_candidates: path = os.path.expanduser(path) if (os.path.isfile(path)): self.cacert_file = path break # still no cacert file, inform user if not self.cacert_file: raise duplicity.errors.FatalBackendException("""For certificate verification a cacert database file is needed in one of these locations: %s Hints: Consult the man page, chapter 'SSL Certificate Verification'. Consider using the options --ssl-cacert-file, --ssl-no-check-certificate .""" % ", ".join(cacert_candidates)) self.tempfile, self.tempname = tempdir.default().mkstemp() os.write(self.tempfile, "set ssl:verify-certificate " + ("false" if globals.ssl_no_check_certificate else "true") + "\n") if globals.ssl_cacert_file: os.write(self.tempfile, "set ssl:ca-file '" + globals.ssl_cacert_file + "'\n") if self.parsed_url.scheme == 'ftps': os.write(self.tempfile, "set ftp:ssl-allow true\n") os.write(self.tempfile, "set ftp:ssl-protect-data true\n") os.write(self.tempfile, "set ftp:ssl-protect-list true\n") elif self.parsed_url.scheme == 'ftpes': os.write(self.tempfile, "set ftp:ssl-force on\n") os.write(self.tempfile, "set ftp:ssl-protect-data on\n") os.write(self.tempfile, "set ftp:ssl-protect-list on\n") else: os.write(self.tempfile, "set ftp:ssl-allow false\n") os.write(self.tempfile, "set http:use-propfind true\n") os.write(self.tempfile, "set net:timeout %s\n" % globals.timeout) os.write(self.tempfile, "set net:max-retries %s\n" % globals.num_retries) os.write(self.tempfile, "set ftp:passive-mode %s\n" % self.conn_opt) if log.getverbosity() >= log.DEBUG: os.write(self.tempfile, "debug\n") if self.parsed_url.scheme == 'ftpes': os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.url_string.replace('ftpes','ftp'))) else: os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.url_string)) # os.write(self.tempfile, "open %s %s\n" % (self.portflag, self.parsed_url.hostname)) # allow .netrc auth by only setting user/pass when user was actually given # if self.parsed_url.username: # os.write(self.tempfile, "user %s %s\n" % (self.parsed_url.username, self.password)) os.close(self.tempfile) if log.getverbosity() >= log.DEBUG: f = open(self.tempname, 'r') log.Debug("SETTINGS: \n" "%s" % f.readlines())