update 20160609

This commit is contained in:
stubbfel
2016-06-09 00:41:48 +02:00
parent 784c32a214
commit 010000e5cd
4 changed files with 191 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#!/bin/bash
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
reset=`tput sgr0`
echo "${green}### start complete backup${reset}"
CMD=("ssh" "-t" "root.router" "./mount_backup.sh")
if ! "${CMD[@]}"; then
ssh root.router "./umount_backup.sh"
echo "${red}Error(1): remote mount failed${reset}"
exit 1
else
echo "${green}Succesfull(1): remote mount success.${reset}"
fi
echo "${green}### start backup for ${yellow}system root${reset}"
sudo sh rsync_backup_lv.sh system root root.router:/mnt/backup
echo "${green}### finished backup for ${yellow}system home${reset}"
echo "${green}### start backup for ${yellow}system home${reset}"
sudo sh rsync_backup_lv.sh system home root.router:/mnt/backup
echo "${green}### finished backup for ${yellow}system home${reset}"
echo "${green}### start backup for ${yellow}tank playonlinux${reset}"
sudo sh rsync_backup_lv.sh tank playonlinux root.router:/mnt/backup
echo "${green}### finished backup for ${yellow}tank playonlinux${reset}"
echo "${green}### start backup for ${yellow}tank steamgames${reset}"
sudo sh rsync_backup_lv.sh tank steamgames root.router:/mnt/backup
echo "${green}### finished backup for ${yellow}tank steamgames${reset}"
echo "${green}### unmount remote dir${reset}"
ssh root.router "./umount_backup.sh"
echo "${green}### finished complete backup${reset}"

28
mount_encrypt.sh Normal file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
Device=$1
MountPoint=$2
MapName=$3
ContainerName="${MapName}foo"
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
CMD=("cryptsetup" "luksOpen" "$Device" "$ContainerName")
if ! "${CMD[@]}"; then
echo "${red} can't open Device $Device ${reset}"
exit 1
fi
sleep 3
vgchange -ay
sleep 3
CMD=("mount" "/dev/mapper/${MapName}" "$MountPoint")
if ! "${CMD[@]}"; then
lvchange -a n "/dev/mapper/${MapName}"
cryptsetup luksClose "$ContainerName"
echo "${red}mount of $Device to $MountPoint failed ${reset}"
exit 1
fi
echo "${green}success mount $Device to $MountPoint ${reset}"

99
rsync_backup_lv.sh Normal file
View File

@@ -0,0 +1,99 @@
#!/bin/bash
VG=$1
LV=$2
BPATH=$3
SNAME="${VG}-${LV}-snapshot"
OLVPATH="/dev/${VG}/${LV}"
MLVPATH="/mnt/${SNAME}"
SPATH="/dev/${VG}/${SNAME}"
ZPATH="${BPATH}/${SNAME}"
red=`tput setaf 1`
blue=`tput setaf 4`
green=`tput setaf 2`
yellow=`tput setaf 3`
pink=`tput setaf 5`
reset=`tput sgr0`
function removeSnapshot
{
COLOR="$1"
STEP="$2"
CMD=("sudo" "lvremove" "-f" "$SPATH")
if ! "${CMD[@]}"; then
echo "${red}Error(${STEP}): removed snapshot - ${yellow}$SPATH${red} failed${reset}"
exit 1
else
echo "${COLOR}Succesfull(${STEP}): removed snapshot - ${yellow}$SPATH${reset}"
fi
}
function removeMountDir
{
COLOR="$1"
STEP="$2"
CMD=("sudo" "rmdir" "$MLVPATH")
if ! "${CMD[@]}"; then
echo "${red}Error(${STEP}): removed mount folder - ${yellow}$SPATH${red} failed${reset}"
exit 1
else
echo "${COLOR}Succesfull(${STEP}): removed mount folder - ${yellow}$MLVPATH${reset}"
fi
}
function unMountDir
{
COLOR="$1"
STEP="$2"
CMD=("sudo" "umount" "$MLVPATH")
if ! "${CMD[@]}"; then
echo "${red}Error(${STEP}): unmounted - ${yellow}$MLVPATH${red} failed${reset}"
exit 1
else
echo "${COLOR}Succesfull(${STEP}): unmounted - ${yellow}$MLVPATH${reset}"
fi
}
echo "${green}=== start backup for ${yellow}$OLVPATH${reset}"
CMD=("sudo" "lvcreate" "-L10G" "-s" "-n" "$SNAME" "$OLVPATH")
if ! $"${CMD[@]}"; then
echo "${red}Error(1): snapshot ${yellow}$SNAME${green} failed${reset}"
exit 1
else
echo "${green}Succesfull(1): snapshot ${yellow}$SNAME${green} created.${reset}"
fi
CMD=("sudo" "mkdir" "-p" "$MLVPATH")
if ! $"${CMD[@]}"; then
echo "${red}Error(2): snapshot mount folder ${yellow}$MLVPATH${green} failed${pink}"
removeSnapshot $blue "Cleanup"
exit 1
else
echo "${green}Succesfull(2): snapshot mount folder ${yellow}$MLVPATH${green} created.${reset}"
fi
CMD=("sudo" "mount" "$SPATH" "$MLVPATH")
if ! "${CMD[@]}"; then
echo "${red}Error(3): mount ${yellow}$SPATH${red} to ${yellow}$MLVPATH${red} failed${reset}"
removeMountDir $blue "Cleanup"
removeSnapshot $blue "Cleanup"
exit 1
else
echo "${green}Succesfull(3): mount ${yellow}$SPATH${green} to ${yellow}$MLVPATH${reset}"
fi
echo "${green}--- start rsync-backup from ${yellow}$MLVPATH${green} to ${yellow}$ZPATH${reset}"
CMD=("sudo" "rsync" "-Pavxh" "--delete" "--progress" "-e" "ssh" "$MLVPATH" "$ZPATH")
if ! "${CMD[@]}"; then
echo "${red}Error(4): rsync-backup aborted${pink}"
unMountDir $blue "Cleanup"
removeMountDir $blue "Cleanup"
removeSnapshot $blue "Cleanup"
exit 1
else
echo "${green}Succesfull(4): rdiff-backup finished${reset}"
fi
unMountDir $green "5"
removeMountDir $green "6"
removeSnapshot $green "7"

27
umount_encrypt.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
MapName=$1
ContainerName="${MapName}foo"
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
CMD=("umount" "/dev/mapper/${MapName}")
if ! "${CMD[@]}"; then
echo "${red}can't umount ${MapName}${reset}"
exit 1
fi
CMD=("lvchange" "-a" "n" "/dev/mapper/${MapName}")
if ! "${CMD[@]}"; then
echo "${red}can't remove lv ${MapName}${reset}"
exit 1
fi
CMD=("cryptsetup" "luksClose" "$ContainerName")
if ! "${CMD[@]}"; then
echo "${red}can't close luks ${ContainerName}${reset}"
exit 1
fi
echo "${green}success umount ${MapName} ${reset}"