diff options
Diffstat (limited to 'restic.py')
| -rw-r--r-- | restic.py | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -23,10 +23,16 @@ LOGLEVELS = {'DEBUG': logging.DEBUG, 'INFO': logging.INFO, 'WARNING': logging.WARNING, 'ERROR': logging.ERROR} + +HOME_DIR = os.path.expanduser('~') +DEFAULT_CONFIG = '{}/.local/etc/restic-wrapper/restic.ini'.format(HOME_DIR) +CONFIG = os.environ.get('RESTIC_CONFIG', DEFAULT_CONFIG) + # TODO should be a configurable location -logging.basicConfig(filename='~/.local/logs/restic.log', - level=LOGLEVELS[os.getenv('RESTIC_LOGLEVEL', 'WARNING')]) +logging.basicConfig(filename='{}/.local/logs/restic.log'.format(HOME_DIR), + level=LOGLEVELS[os.getenv('RESTIC_LOGLEVEL', 'INFO')]) log = logging.getLogger(__name__) + # cmd line parser parser = argparse.ArgumentParser(description='wrapper to restic') parser.add_argument('cmd', @@ -36,26 +42,26 @@ parser.add_argument('cmd', # config cfg = configparser.ConfigParser() -cfg.read('restic.ini') +cfg.read(CONFIG) -# baked commands -HOME_DIR = os.path.expanduser('~') PASSWORD_FILE = '{}/.ssh/resticpass'.format(HOME_DIR) +exclude_file = os.path.expanduser(cfg['restic']['exclude']) +restic_uri = cfg['restic']['repo_uri'] BACKUP_CMD = sh.restic.bake('backup', '--password-file', PASSWORD_FILE, - '--exclude-file', cfg['restic']['exclude'], + '--exclude-file', exclude_file, '--exclude-caches', - '--repo', cfg['restic']['repo_uri']) + '--repo', restic_uri) PRUNE_CMD = sh.restic.bake('forget', '--password-file', PASSWORD_FILE, - '--repo', cfg['restic']['repo_uri'], + '--repo', restic_uri, '--keep-daily', 7, '--keep-weekly', 5, '--keep-monthly', 12, '--keep-yearly', 75) CHECK_CMD = sh.restic.bake('check', '--password-file', PASSWORD_FILE, - '--repo', cfg['restic']['repo_uri']) + '--repo', restic_uri) def _check_auth(): @@ -79,7 +85,7 @@ def run_backup(): with tempfile.NamedTemporaryFile(delete=True) as tmp: tmp.write('\n'.join(directories).encode()) out = BACKUP_CMD('--exclude-file', tmp.name, HOME_DIR) - log.info('{} {}'.format('restic-run', HOME_DIR)) + log.info('{} {}'.format('restic-run', HOME_DIR)) def run_prune(): |