diff options
author | Tharre <tharre3@gmail.com> | 2018-03-27 06:51:01 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2018-03-27 06:51:01 +0200 |
commit | fed13fe17ceec603c23e93cc8792548d886bfd9b (patch) | |
tree | b040f28eddad270cf5596fad414454d1b941a73d /.zshrc | |
parent | 9f09eb3833fb53ab993684edeef933144e477590 (diff) | |
download | dotfiles-fed13fe17ceec603c23e93cc8792548d886bfd9b.tar.gz dotfiles-fed13fe17ceec603c23e93cc8792548d886bfd9b.tar.xz dotfiles-fed13fe17ceec603c23e93cc8792548d886bfd9b.zip |
zsh: add setup_borgbackup for setting up backups
Diffstat (limited to '.zshrc')
-rw-r--r-- | .zshrc | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -174,6 +174,27 @@ function reset_usb() { done } +function setup_borgbackup() { + setopt ERR_RETURN + + BORG_SECRET=~/.borg_secret + BORG_SSH_KEY=~/.ssh/borg_key + + if [ ! -f "$BORG_SECRET" ]; then + install -m600 /dev/null "$BORG_SECRET" + pass backups/$(hostname) > "$BORG_SECRET" + fi + + if [ ! -f "$BORG_SSH_KEY" ]; then + ssh-keygen -q -N "" -f "$BORG_SSH_KEY" + KEY=$(< ${BORG_SSH_KEY}.pub) + + printf '%s\n' "command=\"cd /srv/borgbackup/repos/$(hostname);borg serve --restrict-to-path /srv/borgbackup/repos/$(hostname)\",restrict $KEY" | ssh "$1" "cat >> /srv/borgbackup/.ssh/authorized_keys" + + echo "Added key to remote server." + fi +} + ## PATH export PATH=$PATH:$HOME/bin |