mirror of
https://github.com/deajan/obackup.git
synced 2024-11-15 04:03:41 +01:00
Improved upgrade script
This commit is contained in:
parent
d3c1f183a2
commit
1d6fb00344
@ -6,8 +6,8 @@ AUTHOR="(C) 2016 by Orsiris de Jong"
|
|||||||
CONTACT="http://www.netpower.fr/obacup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obacup - ozy@netpower.fr"
|
||||||
OLD_PROGRAM_VERSION="v1.x"
|
OLD_PROGRAM_VERSION="v1.x"
|
||||||
NEW_PROGRAM_VERSION="v2.1x"
|
NEW_PROGRAM_VERSION="v2.1x"
|
||||||
CONFIG_FILE_VERSION=2017020901
|
CONFIG_FILE_REVISION=2.1
|
||||||
PROGRAM_BUILD=2016113001
|
PROGRAM_BUILD=2019052101
|
||||||
|
|
||||||
if ! type "$BASH" > /dev/null; then
|
if ! type "$BASH" > /dev/null; then
|
||||||
echo "Please run this script only with bash shell. Tested on bash >= 3.2"
|
echo "Please run this script only with bash shell. Tested on bash >= 3.2"
|
||||||
@ -109,33 +109,33 @@ RUN_AFTER_CMD_ON_ERROR
|
|||||||
VALUES=(
|
VALUES=(
|
||||||
test-backup
|
test-backup
|
||||||
''
|
''
|
||||||
yes
|
true
|
||||||
yes
|
true
|
||||||
local
|
local
|
||||||
/home/storage/sql
|
/home/storage/sql
|
||||||
/home/storage/files
|
/home/storage/files
|
||||||
no
|
false
|
||||||
/home/storage/crypt
|
/home/storage/crypt
|
||||||
'Your Name used with GPG signature'
|
'Your Name used with GPG signature'
|
||||||
''
|
''
|
||||||
yes
|
true
|
||||||
yes
|
true
|
||||||
1024
|
1024
|
||||||
yes
|
true
|
||||||
1048576
|
1048576
|
||||||
1048576
|
1048576
|
||||||
ssh://backupuser@remote.system.tld:22/
|
ssh://backupuser@remote.system.tld:22/
|
||||||
${HOME}/.ssh/id_rsa
|
${HOME}/.ssh/id_rsa
|
||||||
''
|
''
|
||||||
SomeAlphaNumericToken9
|
SomeAlphaNumericToken9
|
||||||
yes
|
true
|
||||||
no
|
false
|
||||||
''
|
''
|
||||||
yes
|
true
|
||||||
'www.kernel.org www.google.com'
|
'www.kernel.org www.google.com'
|
||||||
no
|
false
|
||||||
root
|
root
|
||||||
yes
|
true
|
||||||
test
|
test
|
||||||
''
|
''
|
||||||
3600
|
3600
|
||||||
@ -152,21 +152,21 @@ include
|
|||||||
''
|
''
|
||||||
\;
|
\;
|
||||||
''
|
''
|
||||||
yes
|
true
|
||||||
yes
|
true
|
||||||
yes
|
true
|
||||||
yes
|
true
|
||||||
no
|
false
|
||||||
no
|
false
|
||||||
yes
|
true
|
||||||
yes
|
true
|
||||||
no
|
false
|
||||||
no
|
false
|
||||||
3600
|
3600
|
||||||
7200
|
7200
|
||||||
no
|
false
|
||||||
no
|
false
|
||||||
yes
|
true
|
||||||
0
|
0
|
||||||
rsync
|
rsync
|
||||||
infrastructure@example.com
|
infrastructure@example.com
|
||||||
@ -174,15 +174,15 @@ infrastructure@example.com
|
|||||||
sender@example.com
|
sender@example.com
|
||||||
smtp.isp.tld
|
smtp.isp.tld
|
||||||
25
|
25
|
||||||
none
|
falsene
|
||||||
''
|
''
|
||||||
''
|
''
|
||||||
30000
|
30000
|
||||||
36000
|
36000
|
||||||
1801
|
1801
|
||||||
no
|
false
|
||||||
7
|
7
|
||||||
no
|
false
|
||||||
7
|
7
|
||||||
''
|
''
|
||||||
''
|
''
|
||||||
@ -190,8 +190,8 @@ no
|
|||||||
''
|
''
|
||||||
0
|
0
|
||||||
0
|
0
|
||||||
no
|
false
|
||||||
no
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
function Usage {
|
function Usage {
|
||||||
@ -222,7 +222,7 @@ function LoadConfigFile {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function RewriteOldConfigFiles {
|
function CheckAndBackup {
|
||||||
local config_file="${1}"
|
local config_file="${1}"
|
||||||
|
|
||||||
if ! grep "BACKUP_ID=" $config_file > /dev/null && ! grep "INSTANCE_ID=" $config_file > /dev/null; then
|
if ! grep "BACKUP_ID=" $config_file > /dev/null && ! grep "INSTANCE_ID=" $config_file > /dev/null; then
|
||||||
@ -236,6 +236,10 @@ function RewriteOldConfigFiles {
|
|||||||
echo "Cannot backup config file."
|
echo "Cannot backup config file."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function RewriteOldConfigFiles {
|
||||||
|
local config_file="${1}"
|
||||||
|
|
||||||
echo "Rewriting config file $config_file"
|
echo "Rewriting config file $config_file"
|
||||||
|
|
||||||
@ -245,8 +249,8 @@ function RewriteOldConfigFiles {
|
|||||||
sed -i'.tmp' 's/^LOCAL_SQL_STORAGE=/SQL_STORAGE=/g' "$config_file"
|
sed -i'.tmp' 's/^LOCAL_SQL_STORAGE=/SQL_STORAGE=/g' "$config_file"
|
||||||
sed -i'.tmp' 's/^LOCAL_FILE_STORAGE=/FILE_STORAGE=/g' "$config_file"
|
sed -i'.tmp' 's/^LOCAL_FILE_STORAGE=/FILE_STORAGE=/g' "$config_file"
|
||||||
|
|
||||||
sed -i'.tmp' 's/^DISABLE_GET_BACKUP_FILE_SIZE=no/GET_BACKUP_SIZE=yes/g' "$config_file"
|
sed -i'.tmp' 's/^DISABLE_GET_BACKUP_FILE_SIZE=no/GET_BACKUP_SIZE=true/g' "$config_file"
|
||||||
sed -i'.tmp' 's/^DISABLE_GET_BACKUP_FILE_SIZE=yes/GET_BACKUP_SIZE=no/g' "$config_file"
|
sed -i'.tmp' 's/^DISABLE_GET_BACKUP_FILE_SIZE=yes/GET_BACKUP_SIZE=false/g' "$config_file"
|
||||||
sed -i'.tmp' 's/^LOCAL_STORAGE_KEEP_ABSOLUTE_PATHS=/KEEP_ABSOLUTE_PATHS=/g' "$config_file"
|
sed -i'.tmp' 's/^LOCAL_STORAGE_KEEP_ABSOLUTE_PATHS=/KEEP_ABSOLUTE_PATHS=/g' "$config_file"
|
||||||
sed -i'.tmp' 's/^LOCAL_STORAGE_WARN_MIN_SPACE=/SQL_WARN_MIN_SPACE=/g' "$config_file"
|
sed -i'.tmp' 's/^LOCAL_STORAGE_WARN_MIN_SPACE=/SQL_WARN_MIN_SPACE=/g' "$config_file"
|
||||||
if ! grep "^FILE_WARN_MIN_SPACE=" "$config_file" > /dev/null; then
|
if ! grep "^FILE_WARN_MIN_SPACE=" "$config_file" > /dev/null; then
|
||||||
@ -271,7 +275,7 @@ function RewriteOldConfigFiles {
|
|||||||
fi
|
fi
|
||||||
REMOTE_BACKUP=$(cat $config_file | grep "REMOTE_BACKUP=")
|
REMOTE_BACKUP=$(cat $config_file | grep "REMOTE_BACKUP=")
|
||||||
REMOTE_BACKUP=${REMOTE_BACKUP#*=}
|
REMOTE_BACKUP=${REMOTE_BACKUP#*=}
|
||||||
if [ "$REMOTE_BACKUP" == "yes" ]; then
|
if [ "$REMOTE_BACKUP" == "true" ]; then
|
||||||
REMOTE_USER=$(cat $config_file | grep "REMOTE_USER=")
|
REMOTE_USER=$(cat $config_file | grep "REMOTE_USER=")
|
||||||
REMOTE_USER=${REMOTE_USER#*=}
|
REMOTE_USER=${REMOTE_USER#*=}
|
||||||
REMOTE_HOST=$(cat $config_file | grep "REMOTE_HOST=")
|
REMOTE_HOST=$(cat $config_file | grep "REMOTE_HOST=")
|
||||||
@ -281,7 +285,7 @@ function RewriteOldConfigFiles {
|
|||||||
|
|
||||||
REMOTE_SYSTEM_URI="ssh://$REMOTE_USER@$REMOTE_HOST:$REMOTE_PORT/"
|
REMOTE_SYSTEM_URI="ssh://$REMOTE_USER@$REMOTE_HOST:$REMOTE_PORT/"
|
||||||
|
|
||||||
sed -i'.tmp' 's#^REMOTE_BACKUP=yes#REMOTE_SYSTEM_URI='$REMOTE_SYSTEM_URI'#g' "$config_file"
|
sed -i'.tmp' 's#^REMOTE_BACKUP=true#REMOTE_SYSTEM_URI='$REMOTE_SYSTEM_URI'#g' "$config_file"
|
||||||
sed -i'.tmp' '/^REMOTE_USER==*/d' "$config_file"
|
sed -i'.tmp' '/^REMOTE_USER==*/d' "$config_file"
|
||||||
sed -i'.tmp' '/^REMOTE_HOST==*/d' "$config_file"
|
sed -i'.tmp' '/^REMOTE_HOST==*/d' "$config_file"
|
||||||
sed -i'.tmp' '/^REMOTE_PORT==*/d' "$config_file"
|
sed -i'.tmp' '/^REMOTE_PORT==*/d' "$config_file"
|
||||||
@ -303,27 +307,65 @@ function AddMissingConfigOptions {
|
|||||||
if ! grep "^${KEYWORDS[$counter]}=" > /dev/null "$config_file"; then
|
if ! grep "^${KEYWORDS[$counter]}=" > /dev/null "$config_file"; then
|
||||||
echo "${KEYWORDS[$counter]} not found"
|
echo "${KEYWORDS[$counter]} not found"
|
||||||
if [ $counter -gt 0 ]; then
|
if [ $counter -gt 0 ]; then
|
||||||
sed -i'.tmp' '/^'${KEYWORDS[$((counter-1))]}'=*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file"
|
if [ "{$VALUES[$counter]}" == true ] || [ "${VALUES[$counter]}" == false ]; then
|
||||||
|
sed -i'.tmp' '/^'${KEYWORDS[$((counter-1))]}'=*/a\'$'\n'${KEYWORDS[$counter]}'='"${VALUES[$counter]}"'\'$'\n''' "$config_file"
|
||||||
|
else
|
||||||
|
sed -i'.tmp' '/^'${KEYWORDS[$((counter-1))]}'=*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file"
|
||||||
|
fi
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Cannot add missing ${[KEYWORDS[$counter]}."
|
echo "Cannot add missing ${[KEYWORDS[$counter]}."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
sed -i'.tmp' '/onfig file rev*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file"
|
if [ "{$VALUES[$counter]}" == true ] || [ "${VALUES[$counter]}" == false ]; then
|
||||||
|
sed -i'.tmp' '/[GENERAL\]$//a\'$'\n'${KEYWORDS[$counter]}'='"${VALUES[$counter]}"'\'$'\n''' "$config_file"
|
||||||
|
else
|
||||||
|
sed -i'.tmp' '/[GENERAL\]$//a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]"
|
echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]"
|
||||||
|
else
|
||||||
|
# Not the most elegant but the quickest way :)
|
||||||
|
if grep "^{$KEYWORDS[$counter]}=yes" > /dev/null "$config_file"; then
|
||||||
|
sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=true/g' "$config_file"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to true."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
elif grep "^{$KEYWORDS[$counter]}=no" > /dev/null "$config_file"; then
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to false."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=false/g' "$config_file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
counter=$((counter+1))
|
counter=$((counter+1))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function RewriteSections {
|
||||||
|
local config_file="${1}"
|
||||||
|
|
||||||
|
sed -i'.tmp' 's/###### GENERAL BACKUP OPTIONS/[GENERAL]/g' "$config_file"
|
||||||
|
sed -i'.tmp' 's/###### BACKUP STORAGE/[BACKUP STORAGE]/g' "$config_file"
|
||||||
|
sed -i'.tmp' 's/###### REMOTE ONLY OPTIONS/[REMOTE_OPTIONS]/g' "$config_file"
|
||||||
|
sed -i'.tmp' 's/###### DATABASE SPECIFIC OPTIONS/[DATABASE BACKUP SETTINGS]/g' "$config_file"
|
||||||
|
sed -i'.tmp' 's/###### FILES SPECIFIC OPTIONS/[FILE BACKUP SETTINGS]/g' "$config_file"
|
||||||
|
sed -i'.tmp' 's/###### ALERT OPTIONS/[ALERT_OPTIONS]/g' "$config_file"
|
||||||
|
sed -i'.tmp' 's/###### GENERAL BACKUP OPTIONS/[BACKUP SETTINGS]/g' "$config_file"
|
||||||
|
sed -i'.tmp' 's/###### EXECUTION HOOKS/[EXECUTION_HOOKS]/g' "$config_file"
|
||||||
|
}
|
||||||
|
|
||||||
function UpdateConfigHeader {
|
function UpdateConfigHeader {
|
||||||
local config_file="${1}"
|
local config_file="${1}"
|
||||||
|
|
||||||
# "onfig file rev" to deal with earlier variants of the file
|
if ! grep "^CONFIG_FILE_REVISION=" > /dev/null "$config_file"; then
|
||||||
sed -i'.tmp' 's/.*onfig file rev.*/##### '$SUBPROGRAM' config file rev '$CONFIG_FILE_VERSION' '$NEW_PROGRAM_VERSION'/' "$config_file"
|
# "onfig file rev" to deal with earlier variants of the file
|
||||||
|
sed -i'.tmp' 's/.*onfig file rev.*//' "$config_file"
|
||||||
rm -f "$config_file.tmp"
|
sed -i'.tmp' '/^\[GENERAL\]$/a\'$'\n'CONFIG_FILE_REVISION=$CONFIG_FILE_REVISION$'\n''' "$config_file"
|
||||||
|
rm -f "$config_file.tmp"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$1" != "" ] && [ -f "$1" ] && [ -w "$1" ]; then
|
if [ "$1" != "" ] && [ -f "$1" ] && [ -w "$1" ]; then
|
||||||
@ -331,6 +373,8 @@ if [ "$1" != "" ] && [ -f "$1" ] && [ -w "$1" ]; then
|
|||||||
# Make sure there is no ending slash
|
# Make sure there is no ending slash
|
||||||
CONF_FILE="${CONF_FILE%/}"
|
CONF_FILE="${CONF_FILE%/}"
|
||||||
LoadConfigFile "$CONF_FILE"
|
LoadConfigFile "$CONF_FILE"
|
||||||
|
CheckAndBackup "$CONF_FILE"
|
||||||
|
RewriteSections "$CONF_FILE"
|
||||||
RewriteOldConfigFiles "$CONF_FILE"
|
RewriteOldConfigFiles "$CONF_FILE"
|
||||||
AddMissingConfigOptions "$CONF_FILE"
|
AddMissingConfigOptions "$CONF_FILE"
|
||||||
UpdateConfigHeader "$CONF_FILE"
|
UpdateConfigHeader "$CONF_FILE"
|
||||||
|
Loading…
Reference in New Issue
Block a user