Finally, for my purposes, I think it is actually better to analyse the output from backup. If you use the --json
switch, as mentioned by 764287, and then work out how to process the result from subprocess.run
, something like this:
restic_result=subprocess.run(['restic', '-r', repo_location, '--verbose', '--json',
'--tag', snapshot_frequency, '-p', pwd_file, 'backup', source_location, ],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=60).stdout
restic_result=restic_result.replace(b'\x1b[2K', b'').decode('utf-8').splitlines()
for line in restic_result:
if line:
try:
json_obj=json.loads(line)
except json.decoder.JSONDecodeError:
if line.strip()=='Fatal: wrong password or no key found':
logger.error(line)
sys.exit()
else:
logger.info(f'backup command returned this line:\n|{line}|')
continue
if json_obj['message_type']=='summary':
...
… then you find that in fact the info provided is more than just “Added to the repo”, so you can do this:
if json_obj['files_new']==0 and json_obj['files_changed']==0 and \
json_obj['dirs_new']==0 and json_obj['dirs_changed']==0 and \
json_obj['data_blobs']==0 and json_obj['tree_blobs']==0 and \
json_obj['data_added']==0:
logger.info('...seems to be a no-change snapshot')
You can then use the (8-figure start of the) SHA number returned here in json_obj
to prune this “no change” snapshot, leaving an uncluttered repo, where all your snapshots are going to be “things changed” snapshots.