fixing repo initialization

This commit is contained in:
brent s 2019-06-02 16:58:57 -04:00
parent 68669a7fd5
commit 5af337fca7

View File

@ -194,38 +194,38 @@ class Backup(object):
_loc_env['BORG_PASSPHRASE'] = getpass.getpass('Password (will NOT echo back): ') _loc_env['BORG_PASSPHRASE'] = getpass.getpass('Password (will NOT echo back): ')
else: else:
_loc_env['BORG_PASSPHRASE'] = repo['password'] _loc_env['BORG_PASSPHRASE'] = repo['password']
_cmd = [self.borgbin, _cmd = [self.borgbin,
'--log-json', '--log-json',
'--{0}'.format(self.args['loglevel']), '--{0}'.format(self.args['loglevel']),
'init', 'init',
'-e', 'repokey'] '-e', 'repokey']
if self.repos[server]['remote'].lower()[0] in ('1', 't'): if self.repos[server]['remote'].lower()[0] in ('1', 't'):
repo_tgt = '{0}@{1}'.format(_user, server) repo_tgt = '{0}@{1}'.format(_user, server)
else: else:
repo_tgt = os.path.abspath(os.path.expanduser(server)) repo_tgt = os.path.abspath(os.path.expanduser(server))
_cmd.append('{0}:{1}'.format(repo_tgt, _cmd.append('{0}:{1}'.format(repo_tgt,
repo['name'])) repo['name']))
self.logger.debug('VARS: {0}'.format(vars(self))) self.logger.debug('VARS: {0}'.format(vars(self)))
if not self.args['dryrun']: if not self.args['dryrun']:
_out = subprocess.run(_cmd, _out = subprocess.run(_cmd,
env = _loc_env, env = _loc_env,
stdout = subprocess.PIPE, stdout = subprocess.PIPE,
stderr = subprocess.PIPE) stderr = subprocess.PIPE)
_stdout = _out.stdout.decode('utf-8').strip() _stdout = _out.stdout.decode('utf-8').strip()
_stderr = _out.stderr.decode('utf-8').strip() _stderr = _out.stderr.decode('utf-8').strip()
_returncode = _out.returncode _returncode = _out.returncode
self.logger.debug('[{0}]: (RESULT) {1}'.format(repo['name'], _stdout)) self.logger.debug('[{0}]: (RESULT) {1}'.format(repo['name'], _stdout))
# sigh. borg uses stderr for verbose output. # sigh. borg uses stderr for verbose output.
self.logger.debug('[{0}]: STDERR: ({2})\n{1}'.format(repo['name'], self.logger.debug('[{0}]: STDERR: ({2})\n{1}'.format(repo['name'],
_stderr, _stderr,
' '.join(_cmd))) ' '.join(_cmd)))
if _returncode != 0: if _returncode != 0:
self.logger.error( self.logger.error(
'[{0}]: FAILED: {1}'.format(repo['name'], ' '.join(_cmd))) '[{0}]: FAILED: {1}'.format(repo['name'], ' '.join(_cmd)))
if _stderr != '' and self.cron and _returncode != 0: if _stderr != '' and self.cron and _returncode != 0:
self.logger.warning('Command {0} failed: {1}'.format(' '.join(_cmd), self.logger.warning('Command {0} failed: {1}'.format(' '.join(_cmd),
_stderr)) _stderr))
self.logger.info('[{0}]: END INITIALIZATION'.format(repo['name'])) self.logger.info('[{0}]: END INITIALIZATION'.format(repo['name']))
return() return()


def create(self): def create(self):