mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-20 03:40:17 +00:00
Updated backup scripts for dual VPN
This commit is contained in:
parent
ba7c46aae8
commit
427c484cac
4 changed files with 48 additions and 20 deletions
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
backupdir=pivpnbackup
|
||||
date=$(date +%Y%m%d-%H%M%S)
|
||||
# PiVPN: Backup Script
|
||||
|
||||
# Find the rows and columns. Will default to 80x24 if it can not be detected.
|
||||
screen_size=$(stty size 2>/dev/null || echo 24 80)
|
||||
|
@ -15,23 +13,45 @@ c=$(( columns / 2 ))
|
|||
r=$(( r < 20 ? 20 : r ))
|
||||
c=$(( c < 70 ? 70 : c ))
|
||||
|
||||
chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "Choose a VPN configuration to backup (press space to select):" "${r}" "${c}" 2)
|
||||
VPNChooseOptions=(WireGuard "" on
|
||||
OpenVPN "" off)
|
||||
backupdir=pivpnbackup
|
||||
date=$(date +%Y%m%d-%H%M%S)
|
||||
setupVarsFile="setupVars.conf"
|
||||
setupConfigDir="/etc/pivpn"
|
||||
|
||||
if VPN=$("${chooseVPNCmd[@]}" "${VPNChooseOptions[@]}" 2>&1 >/dev/tty) ; then
|
||||
echo "::: Using VPN: $VPN"
|
||||
VPN="${VPN,,}"
|
||||
else
|
||||
echo "::: Cancel selected, exiting...."
|
||||
exit 1
|
||||
fi
|
||||
if [ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ] && [ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]; then
|
||||
|
||||
setupVars="/etc/pivpn/${VPN}/setupVars.conf"
|
||||
# Two protocols have been installed, check if the script has passed
|
||||
# an argument, otherwise ask the user which one he wants to remove
|
||||
if [ $# -ge 1 ]; then
|
||||
VPN="$1"
|
||||
echo "::: Backing up VPN: $VPN"
|
||||
else
|
||||
chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Backup" --separate-output --radiolist "Both OpenVPN and WireGuard are installed, choose a VPN to backup (press space to select):" "${r}" "${c}" 2)
|
||||
VPNChooseOptions=(WireGuard "" on
|
||||
OpenVPN "" off)
|
||||
|
||||
if VPN=$("${chooseVPNCmd[@]}" "${VPNChooseOptions[@]}" 2>&1 >/dev/tty) ; then
|
||||
echo "::: Backing up VPN: $VPN"
|
||||
VPN="${VPN,,}"
|
||||
else
|
||||
echo "::: Cancel selected, exiting...."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
setupVars="${setupConfigDir}/${VPN}/${setupVarsFile}"
|
||||
else
|
||||
|
||||
if [ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ]; then
|
||||
setupVars="${setupConfigDir}/wireguard/${setupVarsFile}"
|
||||
elif [ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]; then
|
||||
setupVars="${setupConfigDir}/openvpn/${setupVarsFile}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
|
@ -53,7 +73,7 @@ backup_openvpn(){
|
|||
backupzip=$date-pivpnovpnbackup.tgz
|
||||
# shellcheck disable=SC2210
|
||||
tar czpf "$install_home"/"$backupdir"/"$backupzip" "$openvpndir" "$ovpnsdir" > /dev/null 2>&1
|
||||
echo -e "Backup created in $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||
echo -e "Backup created in $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/OpenVPN#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||
|
||||
}
|
||||
|
||||
|
@ -64,7 +84,7 @@ backup_wireguard(){
|
|||
checkbackupdir
|
||||
backupzip=$date-pivpnwgbackup.tgz
|
||||
tar czpf "$install_home"/"$backupdir"/"$backupzip" "$wireguarddir" "$configsdir" > /dev/null 2>&1
|
||||
echo -e "Backup created in $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||
echo -e "Backup created in $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/WireGuard#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ function update {
|
|||
}
|
||||
|
||||
function backup {
|
||||
$SUDO ${scriptDir}/backup.sh
|
||||
$SUDO ${scriptDir}/backup.sh "${vpn}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@ uninstallServer(){
|
|||
exit 0
|
||||
}
|
||||
|
||||
backup(){
|
||||
$SUDO ${scriptDir}/backup.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
showHelp(){
|
||||
echo "::: To pass off to the pivpn command for each protocol"
|
||||
echo ":::"
|
||||
|
@ -25,6 +30,7 @@ showHelp(){
|
|||
echo ":::"
|
||||
echo "::: -h, help Show this help dialog"
|
||||
echo "::: -u, uninstall Uninstall pivpn from your system!"
|
||||
echo "::: -bk, backup Backup VPN configs and user profiles"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
@ -38,5 +44,6 @@ case "$1" in
|
|||
ovpn ) "${scriptDir}/openvpn/pivpn.sh" "${@:2}";;
|
||||
"-h" | "help" ) showHelp;;
|
||||
"-u" | "uninstall" ) uninstallServer;;
|
||||
"-bk" | "backup" ) backup ;;
|
||||
* ) showHelp;;
|
||||
esac
|
||||
|
|
|
@ -59,7 +59,8 @@ updateScripts(){
|
|||
}
|
||||
|
||||
backup(){
|
||||
$SUDO ${scriptdir}/backup.sh
|
||||
$SUDO ${scriptdir}/backup.sh "${vpn}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
showHelp(){
|
||||
|
|
Loading…
Reference in a new issue