diff --git a/borgbackup.sh b/borgbackup.sh new file mode 100644 index 0000000..791ff24 --- /dev/null +++ b/borgbackup.sh @@ -0,0 +1,64 @@ +#!/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}" diff --git a/cloneBackup.sh b/cloneBackup.sh new file mode 100644 index 0000000..d3d7e1c --- /dev/null +++ b/cloneBackup.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +MountScript="$1" +UmountScript="$2" +CloneMnt="$3" + +red=`tput setaf 1` +green=`tput setaf 2` +yellow=`tput setaf 3` +reset=`tput sgr0` + +echo "${green}### start clone backup${reset}" + +CMD=("sudo" "sh" "${MountScript}") +if ! "${CMD[@]}"; then + sudo sh "${UmountScript}" + echo "${red}Error(1): execution of mount script ${yellow} ${MountScript} ${red} failed${reset}" + exit 1 +else + echo "${green}Succesfull(1): mount script ${yellow} ${MountScript} ${green} execution was successfull.${reset}" +fi + +CMD=("ssh" "-t" "root.router" "./mount_backup.sh") +if ! "${CMD[@]}"; then + ssh root.router "./umount_backup.sh" + sudo sh "${UmountScript}" + echo "${red}Error(2): remote mount failed${reset}" + exit 1 +else + echo "${green}Succesfull(2): remote mount success.${reset}" +fi + +echo "${green}--- start rsync-clonebackup from ${yellow}root.router:/mnt/backup${green} to ${yellow}$CloneMnt${reset}" +CMD=("sudo" "rsync" "-PWavxh" "--delete" "--progress" "-e" "ssh" "root.router:/mnt/backup" "$CloneMnt") +if ! "${CMD[@]}"; then + ssh root.router "./umount_backup.sh" + sudo sh "${UmountScript}" + echo "${red}Error(4): rsync-clonebackup aborted${reset}" + exit 1 +else + echo "${green}Succesfull(4): rdiff-backup finished${reset}" +fi + +echo "${green}### unmount folders${reset}" +ssh root.router "./umount_backup.sh" +sudo sh "${UmountScript}" + +echo "${green}### finished clone backup${reset}" diff --git a/cloneBackup_copyBox.sh b/cloneBackup_copyBox.sh new file mode 100755 index 0000000..5e271b0 --- /dev/null +++ b/cloneBackup_copyBox.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +MountScript1="$1" +UmountScript1="$2" +MountScript2="$3" +UmountScript2="$4" +CloneMntSrc="$5" +CloneMntDst="$6" + +red=`tput setaf 1` +green=`tput setaf 2` +yellow=`tput setaf 3` +reset=`tput sgr0` + +echo "${green}### start clone 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 + +echo "${green}--- start rsync-clonebackup from ${yellow}${CloneMntSrc}${green} to ${yellow}${CloneMntDst}${reset}" +CMD=("sudo" "rsync" "-PWavxh" "--delete" "--progress" "-e" "ssh" "${CloneMntSrc}" "${CloneMntDst}") +if ! "${CMD[@]}"; then + sudo sh "${UmountScript1}" + sudo sh "${UmountScript2}" + echo "${red}Error(4): rsync-clonebackup aborted${reset}" + exit 1 +else + echo "${green}Succesfull(4): rdiff-backup finished${reset}" +fi + +echo "${green}### unmount folders${reset}" +sudo sh "${UmountScript1}" +sudo sh "${UmountScript2}" + +echo "${green}### finished clone backup${reset}" diff --git a/connect2CopyBox.sh b/connect2CopyBox.sh new file mode 100755 index 0000000..c8b612e --- /dev/null +++ b/connect2CopyBox.sh @@ -0,0 +1,2 @@ +#!/bin/bash +ssh -t copybox@stubbfelpi.lan tmux a -t copyBox diff --git a/copybox@stubbfelpi.lan b/copybox@stubbfelpi.lan new file mode 100755 index 0000000..5e271b0 --- /dev/null +++ b/copybox@stubbfelpi.lan @@ -0,0 +1,51 @@ +#!/bin/bash + +MountScript1="$1" +UmountScript1="$2" +MountScript2="$3" +UmountScript2="$4" +CloneMntSrc="$5" +CloneMntDst="$6" + +red=`tput setaf 1` +green=`tput setaf 2` +yellow=`tput setaf 3` +reset=`tput sgr0` + +echo "${green}### start clone 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 + +echo "${green}--- start rsync-clonebackup from ${yellow}${CloneMntSrc}${green} to ${yellow}${CloneMntDst}${reset}" +CMD=("sudo" "rsync" "-PWavxh" "--delete" "--progress" "-e" "ssh" "${CloneMntSrc}" "${CloneMntDst}") +if ! "${CMD[@]}"; then + sudo sh "${UmountScript1}" + sudo sh "${UmountScript2}" + echo "${red}Error(4): rsync-clonebackup aborted${reset}" + exit 1 +else + echo "${green}Succesfull(4): rdiff-backup finished${reset}" +fi + +echo "${green}### unmount folders${reset}" +sudo sh "${UmountScript1}" +sudo sh "${UmountScript2}" + +echo "${green}### finished clone backup${reset}" diff --git a/rsync_backup_lv.sh b/rsync_backup_lv.sh index 18cdee3..6e1995a 100644 --- a/rsync_backup_lv.sh +++ b/rsync_backup_lv.sh @@ -83,7 +83,7 @@ else fi echo "${green}--- start rsync-backup from ${yellow}$MLVPATH${green} to ${yellow}$ZPATH${reset}" -CMD=("sudo" "rsync" "-Pavxh" "--delete" "--progress" "-e" "ssh" "$MLVPATH" "$ZPATH") +CMD=("sudo" "rsync" "-PWavxh" "--delete" "--progress" "-e" "ssh" "$MLVPATH" "$ZPATH") if ! "${CMD[@]}"; then echo "${red}Error(4): rsync-backup aborted${pink}" unMountDir $blue "Cleanup"