#!/bin/bash MountScript1="$1" UmountScript1="$2" MountScript2="$3" UmountScript2="$4" SCRPATHPREFIX="$5" REPOSITORYPATH="$6" REPOSITORYNAME="$(basename ${REPOSITORYPATH})" REPOSITORYPATH="${REPOSITORYPATH}/backup" REPOSITORYNAMENOW="${REPOSITORYNAME}-$(date +%Y-%m-%d)" red=`tput setaf 1` green=`tput setaf 2` yellow=`tput setaf 3` reset=`tput sgr0` echo "${green}### start borg backup${reset}" CMD=("sudo" "sh" "${MountScript1}") if ! "${CMD[@]}"; then sudo sh "${UmountScript1}" echo "${red}Error(1): execution of mount script ${yellow} ${MountScript1} ${red} failed${reset}" exit 1 else echo "${green}Succesfull(1): mount script ${yellow} ${MountScript1} ${green} execution was successfull.${reset}" fi CMD=("sudo" "sh" "${MountScript2}") if ! "${CMD[@]}"; then sudo sh "${UmountScript1}" sudo sh "${UmountScript2}" echo "${red}Error(1): execution of mount script ${yellow} ${MountScript2} ${red} failed${reset}" exit 1 else echo "${green}Succesfull(1): mount script ${yellow} ${MountScript2} ${green} execution was successfull.${reset}" fi CMD=("borg" "create" "-v" "--compression" "lzma,9" "${REPOSITORYPATH}::${REPOSITORYNAMENOW}" "${SCRPATHPREFIX}/backup/system-home-snapshot/dev" "${SCRPATHPREFIX}/backup/system-home-snapshot/home" "${SCRPATHPREFIX}/backup/system-home-snapshot/game/.pwsafe" "${SCRPATHPREFIX}/backup/media-docs-snapshot") if ! "${CMD[@]}"; then sudo sh "${UmountScript1}" sudo sh "${UmountScript2}" echo "${red}Error(1): creation of repo ${yellow}${REPOSITORYNAMENOW}${red} failed${reset}" exit 1 else echo "${green}Succesfull(1):repo ${yellow}${REPOSITORYNAMENOW}${green} created${reset}" fi echo "${green}### prune old borg backup${reset}" CMD=("borg" "prune" "-v" "${REPOSITORYPATH}" "--prefix" "${REPOSITORYNAME}" "--keep-daily=") if ! "${CMD[@]}"; then sudo sh "${UmountScript1}" sudo sh "${UmountScript2}" echo "${red}Error(2): prune of repo ${yellow}${REPOSITORYNAME}${red} failed${reset}" exit 1 else echo "${green}Succesfull(2): prune of repo ${yellow}${REPOSITORYNAME}${green} was Succesfull${reset}" fi echo "${green}### unmount folders${reset}" sudo sh "${UmountScript1}" sudo sh "${UmountScript2}" echo "${green}### finished borg backup${reset}"