#!/bin/bash # #This script will automatically make an encrypted backup to a restic repository as specified with --source # helpFunction() { echo "" echo "Usage: $0 -i INPUT -c CONFIG_DIR -l LOG_DIR" echo -e "\t-i Input folder to create a repository for." echo -e "\t-c Location of config directory where the repository, password and uuid files are stored." exit 1 # Exit script after printing help } while getopts "i:c:l:" opt do case "$opt" in i ) INPUT="$OPTARG" ;; c ) CONFIG_DIR="$OPTARG" ;; ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent esac done SERVICE=${INPUT##*/} SERVICE=${SERVICE,,} PASSWORD=$(tr -dc 'A-Za-z0-9!?%=' < /dev/urandom | head -c 50) UUID=$(uuidgen) echo $PASSWORD > $CONFIG_DIR/${SERVICE}_password echo $UUID > $CONFIG_DIR/${SERVICE}_uuid echo "Created required backup directories for $INPUT" echo "Password: $PASSWORD" echo "UUID: $UUID" echo "Make sure to note this down in your password manager to be able to decrypt the repositories, and to map the repositories on the external storage"