summaryrefslogtreecommitdiffstats
path: root/.zshrc
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2018-03-27 06:51:01 +0200
committerTharre <tharre3@gmail.com>2018-03-27 06:51:01 +0200
commitfed13fe17ceec603c23e93cc8792548d886bfd9b (patch)
treeb040f28eddad270cf5596fad414454d1b941a73d /.zshrc
parent9f09eb3833fb53ab993684edeef933144e477590 (diff)
downloaddotfiles-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--.zshrc21
1 files changed, 21 insertions, 0 deletions
diff --git a/.zshrc b/.zshrc
index d68dcfb..c059206 100644
--- a/.zshrc
+++ b/.zshrc
@@ -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