Restore database
This commit is contained in:
parent
cc72169bfd
commit
80553d9d8b
|
@ -517,14 +517,16 @@ function restore_database_from_friend {
|
|||
|
||||
function restore_database {
|
||||
RESTORE_SUBDIR="root"
|
||||
restore_app_name=$1
|
||||
restore_app_dir=$2
|
||||
|
||||
if [ -d $USB_MOUNT/backup/${1} ]; then
|
||||
if [ -d $USB_MOUNT/backup/${restore_app_name} ]; then
|
||||
echo $"Restoring ${1} database"
|
||||
local_database_dir=/root/temp${1}data
|
||||
local_database_dir=/root/temp${restore_app_name}data
|
||||
function_check restore_directory_from_usb
|
||||
restore_directory_from_usb "${local_database}" "${1}data"
|
||||
if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
|
||||
echo $"Unable to restore ${1} database"
|
||||
restore_directory_from_usb "${local_database}" "${restore_app_name}data"
|
||||
if [ ! -f /root/temp${restore_app_name}data/${RESTORE_SUBDIR}/temp${restore_app_name}data/${restore_app_name}.sql ]; then
|
||||
echo $"Unable to restore ${restore_app_name} database"
|
||||
rm -rf ${local_database}
|
||||
function_check set_user_permissions
|
||||
set_user_permissions
|
||||
|
@ -532,7 +534,7 @@ function restore_database {
|
|||
backup_unmount_drive
|
||||
exit 503
|
||||
fi
|
||||
mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < ${local_database}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
|
||||
mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${restore_app_name} -o < ${local_database}/${RESTORE_SUBDIR}/temp${restore_app_name}data/${restore_app_name}.sql)
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo "$mysqlsuccess"
|
||||
function_check set_user_permissions
|
||||
|
@ -541,32 +543,32 @@ function restore_database {
|
|||
backup_unmount_drive
|
||||
exit 964
|
||||
fi
|
||||
shred -zu ${local_database}/${RESTORE_SUBDIR}/temp${1}data/*
|
||||
shred -zu ${local_database}/${RESTORE_SUBDIR}/temp${restore_app_name}data/*
|
||||
rm -rf ${local_database}
|
||||
echo $"Restoring ${1} installation"
|
||||
if [ ! -d /root/temp${1} ]; then
|
||||
mkdir /root/temp${1}
|
||||
echo $"Restoring ${restore_app_name} installation"
|
||||
if [ ! -d /root/temp${restore_app_name} ]; then
|
||||
mkdir /root/temp${restore_app_name}
|
||||
fi
|
||||
function_check restore_directory_from_usb
|
||||
restore_directory_from_usb "/root/temp${1}" "${1}"
|
||||
restore_directory_from_usb "/root/temp${restore_app_name}" "${restore_app_name}"
|
||||
RESTORE_SUBDIR="var"
|
||||
if [ ${2} ]; then
|
||||
if [ -d /var/www/${2}/htdocs ]; then
|
||||
if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
|
||||
rm -rf /var/www/${2}/htdocs
|
||||
mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
|
||||
if [ ${restore_app_dir} ]; then
|
||||
if [ -d /var/www/${restore_app_dir}/htdocs ]; then
|
||||
if [ -d /root/temp${restore_app_name}/${RESTORE_SUBDIR}/www/${restore_app_dir}/htdocs ]; then
|
||||
rm -rf /var/www/${restore_app_dir}/htdocs
|
||||
mv /root/temp${restore_app_name}/${RESTORE_SUBDIR}/www/${restore_app_dir}/htdocs /var/www/${restore_app_dir}/
|
||||
if [ ! "$?" = "0" ]; then
|
||||
set_user_permissions
|
||||
backup_unmount_drive
|
||||
exit 683
|
||||
fi
|
||||
if [ -d /etc/letsencrypt/live/${2} ]; then
|
||||
ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
|
||||
ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
|
||||
if [ -d /etc/letsencrypt/live/${restore_app_dir} ]; then
|
||||
ln -s /etc/letsencrypt/live/${restore_app_dir}/privkey.pem /etc/ssl/private/${restore_app_dir}.key
|
||||
ln -s /etc/letsencrypt/live/${restore_app_dir}/fullchain.pem /etc/ssl/certs/${restore_app_dir}.pem
|
||||
else
|
||||
# Ensure that the bundled SSL cert is being used
|
||||
if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
|
||||
sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
|
||||
if [ -f /etc/ssl/certs/${restore_app_dir}.bundle.crt ]; then
|
||||
sed -i "s|${restore_app_dir}.crt|${restore_app_dir}.bundle.crt|g" /etc/nginx/sites-available/${restore_app_dir}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue