From 959e7968ff856b6d7998722d4da54749c3287bc7 Mon Sep 17 00:00:00 2001 From: Jeff Moe Date: Sat, 14 Jul 2018 19:45:23 -0600 Subject: [PATCH] Add borg backup scripts --- .../resources/apps/borg/forksand-borg-add-key | 20 +++++++++ .../resources/apps/borg/forksand-borg-check | 30 ++++++++++++++ .../resources/apps/borg/forksand-borg-create | 41 +++++++++++++++++++ source/resources/apps/borg/forksand-borg-info | 31 ++++++++++++++ source/resources/apps/borg/forksand-borg-init | 39 ++++++++++++++++++ source/resources/apps/borg/forksand-borg-list | 30 ++++++++++++++ 6 files changed, 191 insertions(+) create mode 100755 source/resources/apps/borg/forksand-borg-add-key create mode 100755 source/resources/apps/borg/forksand-borg-check create mode 100755 source/resources/apps/borg/forksand-borg-create create mode 100755 source/resources/apps/borg/forksand-borg-info create mode 100755 source/resources/apps/borg/forksand-borg-init create mode 100755 source/resources/apps/borg/forksand-borg-list diff --git a/source/resources/apps/borg/forksand-borg-add-key b/source/resources/apps/borg/forksand-borg-add-key new file mode 100755 index 0000000..ed0051a --- /dev/null +++ b/source/resources/apps/borg/forksand-borg-add-key @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (C) 2018, Fork Sand, Inc. +# Copyright (C) 2017, aleph Objects, Inc. +# GPLv3 +# Generate a key thusly +# ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa | rsa1] [-N new_passphrase] [-C comment] [-f output_keyfile] +# ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519-borg-`hostname` + +exit 0 +set -x + +export BORG_SERVER="user@host" +export BORG_SSHPUBKEY="/root/.ssh/id_ed25519-borg-`hostname`.pub" + +# To make it the only key: +#scp $BORG_SSHPUBKEY $BORG_SERVER:.ssh/authorized_keys + +# To append the key to existing ssh keys: +cat $BORG_SSHPUBKEY | ssh $BORG_SERVER 'dd of=.ssh/authorized_keys oflag=append conv=notrunc' + diff --git a/source/resources/apps/borg/forksand-borg-check b/source/resources/apps/borg/forksand-borg-check new file mode 100755 index 0000000..6a2ce55 --- /dev/null +++ b/source/resources/apps/borg/forksand-borg-check @@ -0,0 +1,30 @@ +#!/bin/bash +# Copyright (C) 2018, Fork Sand, Inc. +# Copyright (C) 2017, aleph Objects, Inc. +# GPLv3 + +export BORG_REPO="BACKUPS/borg/`hostname`" +export BORG_SERVER="user@host" +export BORG_PASSPHRASE="`cat /root/.borgpw`" +export BORG_BINARY="borg1" +#export BORG_DISPLAY_PASSPHRASE=0 +#export BORG_LOGGING_CONF= +export BORG_RSH="ssh -i /root/.ssh/id_ed25519-borg-`hostname`" +export BORG_REMOTE_PATH=borg1 +#export BORG_FILES_CACHE_TTL=20 +#export TMPDIR= +export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=no +export BORG_RELOCATED_REPO_ACCESS_IS_OK=no +export BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=yes +export BORG_DELETE_I_KNOW_WHAT_I_AM_DOING=no +export BORG_KEYS_DIR="/root/.config/borg/keys" +export BORG_CACHE_DIR="/root/.cache/borg" + +echo "Checking Server: $BORG_SERVER" +echo "Checking Repo: $BORG_REPO" +echo + +borg check \ + --verbose \ + $BORG_SERVER:$BORG_REPO + diff --git a/source/resources/apps/borg/forksand-borg-create b/source/resources/apps/borg/forksand-borg-create new file mode 100755 index 0000000..d167dbe --- /dev/null +++ b/source/resources/apps/borg/forksand-borg-create @@ -0,0 +1,41 @@ +#!/bin/bash +# Copyright (C) 2018, Fork Sand, Inc. +# Copyright (C) 2017, aleph Objects, Inc. +# GPLv3 +set -x + +export MASTERDIR=/ +export BORG_REPO="BACKUPS/borg/`hostname`" +export BORG_SERVER="user@host" +export BORG_PASSPHRASE="`cat /root/.borgpw`" +export BORG_BINARY="borg1" +#export BORG_DISPLAY_PASSPHRASE=0 +#export BORG_LOGGING_CONF= +export BORG_RSH="ssh -i /root/.ssh/id_ed25519-borg-`hostname`" +export BORG_REMOTE_PATH=borg1 +#export BORG_FILES_CACHE_TTL=20 +#export TMPDIR= +export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=no +export BORG_RELOCATED_REPO_ACCESS_IS_OK=no +export BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=yes +export BORG_DELETE_I_KNOW_WHAT_I_AM_DOING=no +export BORG_KEYS_DIR="/root/.config/borg/keys" +export BORG_CACHE_DIR="/root/.cache/borg" +export NOW=`date +%Y%m%d%H%M%S` + +mkdir -p $BORG_KEYS_DIR +mkdir -p $BORG_CACHE_DIR + +borg create \ + --verbose \ + --stats \ + --progress \ + $BORG_SERVER:$BORG_REPO::$NOW \ + $MASTERDIR + +# --list +# --exclude +# --one-file-system +# --numeric-owner +# --compression +# --dry-run diff --git a/source/resources/apps/borg/forksand-borg-info b/source/resources/apps/borg/forksand-borg-info new file mode 100755 index 0000000..f5198a2 --- /dev/null +++ b/source/resources/apps/borg/forksand-borg-info @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright (C) 2018, Fork Sand, Inc. +# Copyright (C) 2017, aleph Objects, Inc. +# GPLv3 + +export BORG_REPO="BACKUPS/borg/`hostname`" +export BORG_SERVER="user@host" +export BORG_PASSPHRASE="`cat /root/.borgpw`" +export BORG_BINARY="borg1" +#export BORG_DISPLAY_PASSPHRASE=0 +#export BORG_LOGGING_CONF= +export BORG_RSH="ssh -i /root/.ssh/id_ed25519-borg-`hostname`" +export BORG_REMOTE_PATH=borg1 +#export BORG_FILES_CACHE_TTL=20 +#export TMPDIR= +export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=no +export BORG_RELOCATED_REPO_ACCESS_IS_OK=no +export BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=yes +export BORG_DELETE_I_KNOW_WHAT_I_AM_DOING=no +export BORG_KEYS_DIR="/root/.config/borg/keys" +export BORG_CACHE_DIR="/root/.cache/borg" + +echo "Checking Server: $BORG_SERVER" +echo "Checking Repo: $BORG_REPO" +echo + +#set -x +borg info \ + --verbose \ + $BORG_SERVER:$BORG_REPO::20161120000000 + diff --git a/source/resources/apps/borg/forksand-borg-init b/source/resources/apps/borg/forksand-borg-init new file mode 100755 index 0000000..ebd2933 --- /dev/null +++ b/source/resources/apps/borg/forksand-borg-init @@ -0,0 +1,39 @@ +#!/bin/bash +# Copyright (C) 2018, Fork Sand, Inc. +# Copyright (C) 2017, aleph Objects, Inc. +# GPLv3 +set -x + +# Encryption +# export password +# restrict to certain ssh keys +# restrict ssh key commands +# Append only ? + +export BORG_REPO="BACKUPS/borg/`hostname`" +export BORG_SERVER="user@host" +export BORG_PASSPHRASE="`cat /root/.borgpw`" +export BORG_BINARY="borg1" +#export BORG_DISPLAY_PASSPHRASE=0 +#export BORG_LOGGING_CONF= +export BORG_RSH="ssh -i /root/.ssh/id_ed25519-borg-`hostname`" +export BORG_REMOTE_PATH=borg1 +#export BORG_FILES_CACHE_TTL=20 +#export TMPDIR= +export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=no +export BORG_RELOCATED_REPO_ACCESS_IS_OK=no +export BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=yes +export BORG_DELETE_I_KNOW_WHAT_I_AM_DOING=no +export BORG_KEYS_DIR="/root/.config/borg/keys" +export BORG_CACHE_DIR="/root/.cache/borg" + +mkdir -p $BORG_KEYS_DIR +mkdir -p $BORG_CACHE_DIR + +ssh $BORG_SERVER "mkdir -p $BORG_REPO" + +borg init \ + --verbose \ + --encryption=keyfile \ + $BORG_SERVER:$BORG_REPO + diff --git a/source/resources/apps/borg/forksand-borg-list b/source/resources/apps/borg/forksand-borg-list new file mode 100755 index 0000000..accb434 --- /dev/null +++ b/source/resources/apps/borg/forksand-borg-list @@ -0,0 +1,30 @@ +#!/bin/bash +# Copyright (C) 2018, Fork Sand, Inc. +# Copyright (C) 2017, aleph Objects, Inc. +# GPLv3 + +export BORG_REPO="BACKUPS/borg/`hostname`" +export BORG_SERVER="user@host" +export BORG_PASSPHRASE="`cat /root/.borgpw`" +export BORG_BINARY="borg1" +#export BORG_DISPLAY_PASSPHRASE=0 +#export BORG_LOGGING_CONF= +export BORG_RSH="ssh -i /root/.ssh/id_ed25519-borg-`hostname`" +export BORG_REMOTE_PATH=borg1 +#export BORG_FILES_CACHE_TTL=20 +#export TMPDIR= +export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=no +export BORG_RELOCATED_REPO_ACCESS_IS_OK=no +export BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=yes +export BORG_DELETE_I_KNOW_WHAT_I_AM_DOING=no +export BORG_KEYS_DIR="/root/.config/borg/keys" +export BORG_CACHE_DIR="/root/.cache/borg" + +echo "Checking Server: $BORG_SERVER" +echo "Checking Repo: $BORG_REPO" +echo + +borg list \ + --verbose \ + $BORG_SERVER:$BORG_REPO +