aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrumps <max@ofmax.li>2018-11-19 21:52:50 -0800
committergrumps <max@ofmax.li>2018-11-19 21:52:50 -0800
commit2851ad72c28f21c9baf7a91c22daec9291d630a9 (patch)
tree611cc24515beeff7eece3e134b124459a37610a1
parent47eefe5fafc70dbc585e63a2bf03932d2e7c2759 (diff)
downloadrestic-wrapper-2851ad72c28f21c9baf7a91c22daec9291d630a9.tar.gz
clean up stuff from system units
-rw-r--r--etc/restic-wrapper.service3
-rw-r--r--restic.py26
2 files changed, 17 insertions, 12 deletions
diff --git a/etc/restic-wrapper.service b/etc/restic-wrapper.service
index 98da7bb..dd32cdd 100644
--- a/etc/restic-wrapper.service
+++ b/etc/restic-wrapper.service
@@ -1,8 +1,7 @@
[Unit]
Description=Runs restic backups
-Wants=restic-wrapper.timer
[Service]
-ExecStart=rw backup
+ExecStart=%h/.local/bin/rw backup
WorkingDirectory=%h
[Install]
WantedBy=multi-user.target
diff --git a/restic.py b/restic.py
index daf4c40..95be705 100644
--- a/restic.py
+++ b/restic.py
@@ -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():