1
0
mirror of https://github.com/deajan/obackup.git synced 2024-12-04 20:53:41 +01:00

BSD compat and fixes

This commit is contained in:
deajan 2016-04-13 12:16:23 +02:00
parent 2c51055209
commit e7fb070400

View File

@ -6,7 +6,13 @@ AUTHOR="(C) 2015 by Orsiris \"Ozy\" de Jong"
CONTACT="http://www.netpower.fr/obacup - ozy@netpower.fr"
OLD_PROGRAM_VERSION="v1.x"
NEW_PROGRAM_VERSION="v2.x"
PROGRAM_BUILD=2016040601
PROGRAM_BUILD=2016041201
## type -p does not work on platforms other than linux (bash). If if does not work, always as$
if ! type "$BASH" > /dev/null; then
echo "Please run this script only with bash shell. Tested on bash >= 3.2"
exit 127
fi
function Usage {
echo "$PROGRAM $PROGRAM_BUILD"
@ -45,7 +51,7 @@ function RewriteConfigFiles {
fi
echo "Backing up [$config_file] as [$config_file.save]"
cp --preserve "$config_file" "$config_file.save"
cp -p "$config_file" "$config_file.save"
if [ $? != 0 ]; then
echo "Cannot backup config file."
exit 1
@ -53,32 +59,38 @@ function RewriteConfigFiles {
echo "Rewriting config file $config_file"
sed -i 's/^BACKUP_ID=/INSTANCE_ID=/g' "$config_file"
sed -i 's/^BACKUP_SQL=/SQL_BACKUP=/g' "$config_file"
sed -i 's/^BACKUP_FILES=/FILE_BACKUP=/g' "$config_file"
sed -i 's/^LOCAL_SQL_STORAGE=/SQL_STORAGE=/g' "$config_file"
sed -i 's/^LOCAL_FILE_STORAGE=/FILE_STORAGE=/g' "$config_file"
sed -i '/^FILE_STORAGE=*/a ENCRYPTION=no' "$config_file"
sed -i 's/^DISABLE_GET_BACKUP_FILE_SIZE=no/GET_BACKUP_SIZE=yes/g' "$config_file"
sed -i 's/^DISABLE_GET_BACKUP_FILE_SIZE=yes/GET_BACKUP_SIZE=no/g' "$config_file"
sed -i 's/^LOCAL_STORAGE_KEEP_ABSOLUTE_PATHS=/KEEP_ABSOLUTE_PATHS=/g' "$config_file"
sed -i 's/^LOCAL_STORAGE_WARN_MIN_SPACE=/SQL_WARN_MIN_SPACE=/g' "$config_file"
VALUE=$(cat $config_file | grep "SQL_WARN_MIN_SPACE=")
VALUE=${VALUE#*=}
sed -i '/^SQL_WARN_MIN_SPACE=*/a FILE_WARN_MIN_SPACE='$VALUE "$config_file"
# Add encryption
sed -i 's/^DIRECTORIES_SIMPLE_LIST=/DIRECTORY_LIST=/g' "$config_file"
sed -i 's/^DIRECTORIES_RECURSE_LIST=/RECURSIVE_DIRECTORY_LIST=/g' "$config_file"
sed -i 's/^DIRECTORIES_RECURSE_EXCLUDE_LIST=/RECURSIVE_EXCLUDE_LIST=/g' "$config_file"
sed -i 's/^ROTATE_BACKUPS=/ROTATE_SQL_BACKUPS=/g' "$config_file"
VALUE=$(cat $config_file | grep "ROTATE_SQL_BACKUPS=")
VALUE=${VALUE#*=}
sed -i '/^ROTATE_SQL_BACKUPS=*/a ROTATE_FILE_BACKUPS='$VALUE "$config_file"
sed -i 's/^ROTATE_COPIES=/ROTATE_SQL_COPIES=/g' "$config_file"
VALUE=$(cat $config_file | grep "ROTATE_SQL_COPIES=")
VALUE=${VALUE#*=}
sed -i '/^ROTATE_SQL_COPIES=*/a ROTATE_FILE_COPIES='$VALUE "$config_file"
sed -i'.tmp' 's/^BACKUP_ID=/INSTANCE_ID=/g' "$config_file"
sed -i'.tmp' 's/^BACKUP_SQL=/SQL_BACKUP=/g' "$config_file"
sed -i'.tmp' 's/^BACKUP_FILES=/FILE_BACKUP=/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"
if ! grep "^ENCRYPTION=" "$config_file" > /dev/null; then
sed -i'.tmp' '/^FILE_STORAGE=*/a\'$'\n''ENCRYPTION=no\'$'\n''' "$config_file"
fi
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=yes/GET_BACKUP_SIZE=no/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"
if ! grep "^FILE_WARN_MIN_SPACE=" "$config_file" > /dev/null; then
VALUE=$(cat $config_file | grep "SQL_WARN_MIN_SPACE=")
VALUE=${VALUE#*=}
sed -i'.tmp' '/^SQL_WARN_MIN_SPACE=*/a\'$'\n''FILE_WARN_MIN_SPACE='$VALUE'\'$'\n''' "$config_file"
fi
sed -i'.tmp' 's/^DIRECTORIES_SIMPLE_LIST=/DIRECTORY_LIST=/g' "$config_file"
sed -i'.tmp' 's/^DIRECTORIES_RECURSE_LIST=/RECURSIVE_DIRECTORY_LIST=/g' "$config_file"
sed -i'.tmp' 's/^DIRECTORIES_RECURSE_EXCLUDE_LIST=/RECURSIVE_EXCLUDE_LIST=/g' "$config_file"
sed -i'.tmp' 's/^ROTATE_BACKUPS=/ROTATE_SQL_BACKUPS=/g' "$config_file"
if ! grep "^ROTATE_FILE_BACKUPS=" "$config_file" > /dev/null; then
VALUE=$(cat $config_file | grep "ROTATE_SQL_BACKUPS=")
VALUE=${VALUE#*=}
sed -i'.tmp' '/^ROTATE_SQL_BACKUPS=*/a\'$'\n''ROTATE_FILE_BACKUPS='$VALUE'\'$'\n''' "$config_file"
fi
sed -i'.tmp' 's/^ROTATE_COPIES=/ROTATE_SQL_COPIES=/g' "$config_file"
if ! grep "^ROTATE_FILE_COPIES=" "$config_file" > /dev/null; then
VALUE=$(cat $config_file | grep "ROTATE_SQL_COPIES=")
VALUE=${VALUE#*=}
sed -i'.tmp' '/^ROTATE_SQL_COPIES=*/a\'$'\n''ROTATE_FILE_COPIES='$VALUE'\'$'\n''' "$config_file"
fi
REMOTE_BACKUP=$(cat $config_file | grep "REMOTE_BACKUP=")
REMOTE_BACKUP=${REMOTE_BACKUP#*=}
if [ "$REMOTE_BACKUP" == "yes" ]; then
@ -91,89 +103,92 @@ function RewriteConfigFiles {
REMOTE_SYSTEM_URI="ssh://$REMOTE_USER@$REMOTE_HOST:$REMOTE_PORT/"
sed -i 's#^REMOTE_BACKUP=yes#REMOTE_SYSTEM_URI='$REMOTE_SYSTEM_URI'#g' "$config_file"
sed -i '/^REMOTE_USER=*/d' "$config_file"
sed -i '/^REMOTE_HOST=*/d' "$config_file"
sed -i '/^REMOTE_PORT=*/d' "$config_file"
sed -i'.tmp' 's#^REMOTE_BACKUP=yes#REMOTE_SYSTEM_URI='$REMOTE_SYSTEM_URI'#g' "$config_file"
sed -i'.tmp' '/^REMOTE_USER=*/d' "$config_file"
sed -i'.tmp' '/^REMOTE_HOST=*/d' "$config_file"
sed -i'.tmp' '/^REMOTE_PORT=*/d' "$config_file"
sed -i '/^INSTANCE_ID=*/a BACKUP_TYPE=pull' "$config_file"
sed -i'.tmp' '/^INSTANCE_ID=*/a\'$'\n''BACKUP_TYPE=pull\'$'\n''' "$config_file"
else
sed -i '/^INSTANCE_ID=*/a BACKUP_TYPE=local' "$config_file"
if ! grep "^BACKUP_TYPE=" "$config_file" > /dev/null; then
sed -i'.tmp' '/^INSTANCE_ID=*/a\'$'\n''BACKUP_TYPE=local\'$'\n''' "$config_file"
fi
fi
# Add new config values from v1.1 if they don't exist
if ! grep "^ENCRYPTION=" "$config_file" > /dev/null; then
sed -i '/^FILE_STORAGE=*/a ENCRYPTION=no' "$config_file"
sed -i'.tmp' '/^FILE_STORAGE=*/a\'$'\n''ENCRYPTION=no\'$'\n''' "$config_file"
fi
if ! grep "^CREATE_DIRS=" "$config_file" > /dev/null; then
sed -i '/^ENCRYPTION=*/a CREATE_DIRS=yes' "$config_file"
sed -i'.tmp' '/^ENCRYPTION=*/a\'$'\n''CREATE_DIRS=yes\'$'\n''' "$config_file"
fi
if ! grep "^GET_BACKUP_SIZE=" "$config_file" > /dev/null; then
sed -i '/^BACKUP_SIZE_MINIMUM=*/a GET_BACKUP_SIZE=yes' "$config_file"
sed -i'.tmp' '/^BACKUP_SIZE_MINIMUM=*/a\'$'\n''GET_BACKUP_SIZE=yes\'$'\n''' "$config_file"
fi
if ! grep "^RSYNC_REMOTE_PATH=" "$config_file" > /dev/null; then
sed -i '/^SSH_COMPRESSION=*/a RSYNC_REMOTE_PATH=' "$config_file"
sed -i'.tmp' '/^SSH_COMPRESSION=*/a\'$'\n''RSYNC_REMOTE_PATH=\'$'\n''' "$config_file"
fi
if ! grep "^SSH_IGNORE_KNOWN_HOSTS=" "$config_file" > /dev/null; then
sed -i '/^SSH_COMPRESSION=*/a SSH_IGNORE_KNOWN_HOSTS=no' "$config_file"
sed -i'.tmp' '/^SSH_COMPRESSION=*/a\'$'\n''SSH_IGNORE_KNOWN_HOSTS=no\'$'\n''' "$config_file"
fi
if ! grep "^REMOTE_HOST_PING=" "$config_file" > /dev/null; then
sed -i '/^RSYNC_REMOTE_PATH=*/a REMOTE_HOST_PING=yes' "$config_file"
sed -i'.tmp' '/^RSYNC_REMOTE_PATH=*/a\'$'\n''REMOTE_HOST_PING=yes\'$'\n''' "$config_file"
fi
if ! grep "^COPY_SYMLINKS=" "$config_file" > /dev/null; then
sed -i '/^PRESERVE_XATTR=*/a COPY_SYMLINKS=yes' "$config_file"
sed -i'.tmp' '/^PRESERVE_XATTR=*/a\'$'\n''COPY_SYMLINKS=yes\'$'\n''' "$config_file"
fi
if ! grep "^KEEP_DIRLINKS=" "$config_file" > /dev/null; then
sed -i '/^COPY_SYMLINKS=*/a KEEP_DIRLINKS=yes' "$config_file"
sed -i'.tmp' '/^COPY_SYMLINKS=*/a\'$'\n''KEEP_DIRLINKS=yes\'$'\n''' "$config_file"
fi
if ! grep "^PRESERVE_HARDLINKS=" "$config_file" > /dev/null; then
sed -i '/^KEEP_DIRLINKS=*/a PRESERVE_HARDLINKS=no' "$config_file"
sed -i'.tmp' '/^KEEP_DIRLINKS=*/a\'$'\n''PRESERVE_HARDLINKS=no\'$'\n''' "$config_file"
fi
if ! grep "^RSYNC_PATTERN_FIRST=" "$config_file" > /dev/null; then
sed -i '/^LOGFILE=*/a RSYNC_PATTERN_FIRST=include' "$config_file"
sed -i'.tmp' '/^LOGFILE=*/a\'$'\n''RSYNC_PATTERN_FIRST=include\'$'\n''' "$config_file"
fi
if ! grep "^RSYNC_INCLUDE_PATTERN=" "$config_file" > /dev/null; then
sed -i '/^RSYNC_EXCLUDE_PATTERN=*/a RSYNC_INCLUDE_PATTERN=""' "$config_file"
sed -i'.tmp' '/^RSYNC_EXCLUDE_PATTERN=*/a\'$'\n''RSYNC_INCLUDE_PATTERN=""\'$'\n''' "$config_file"
fi
if ! grep "^RSYNC_INCLUDE_FROM=" "$config_file" > /dev/null; then
sed -i '/^RSYNC_EXCLUDE_FROM=*/a RSYNC_INCLUDE_FROM=""' "$config_file"
sed -i'.tmp' '/^RSYNC_EXCLUDE_FROM=*/a\'$'\n''RSYNC_INCLUDE_FROM=""\'$'\n''' "$config_file"
fi
if ! grep "^PARTIAL=" "$config_file" > /dev/null; then
sed -i '/^HARD_MAX_EXEC_TIME_FILE_TASK==*/a PARTIAL=no' "$config_file"
sed -i'.tmp' '/^HARD_MAX_EXEC_TIME_FILE_TASK==*/a\'$'\n''PARTIAL=no\'$'\n''' "$config_file"
fi
if ! grep "^DELETE_VANISHED_FILES=" "$config_file" > /dev/null; then
sed -i '/^PARTIAL=*/a DELETE_VANISHED_FILES=no' "$config_file"
sed -i'.tmp' '/^PARTIAL=*/a\'$'\n''DELETE_VANISHED_FILES=no\'$'\n''' "$config_file"
fi
if ! grep "^DELTA_COPIES=" "$config_file" > /dev/null; then
sed -i '/^PARTIAL=*/a DELTA_COPIES=yes' "$config_file"
sed -i'.tmp' '/^PARTIAL=*/a\'$'\n''DELTA_COPIES=yes\'$'\n''' "$config_file"
fi
if ! grep "^BANDWIDTH=" "$config_file" > /dev/null; then
sed -i '/^DELTA_COPIES=*/a BANDWIDTH=0' "$config_file"
sed -i'.tmp' '/^DELTA_COPIES=*/a\'$'\n''BANDWIDTH=0\'$'\n''' "$config_file"
fi
if ! grep "^STOP_ON_CMD_ERROR=" "$config_file" > /dev/null; then
sed -i '/^MAX_EXEC_TIME_PER_CMD_AFTER=*/a STOP_ON_CMD_ERROR=no' "$config_file"
sed -i'.tmp' '/^MAX_EXEC_TIME_PER_CMD_AFTER=*/a\'$'\n''STOP_ON_CMD_ERROR=no\'$'\n''' "$config_file"
fi
if ! grep "^RUN_AFTER_CMD_ON_ERROR=" "$config_file" > /dev/null; then
sed -i '/^STOP_ON_CMD_ERROR=*/a RUN_AFTER_CMD_ON_ERROR=no' "$config_file"
sed -i'.tmp' '/^STOP_ON_CMD_ERROR=*/a\'$'\n''RUN_AFTER_CMD_ON_ERROR=no\'$'\n''' "$config_file"
fi
rm -f "$config_file.tmp"
}
if [ "$1" != "" ] && [ -f "$1" ] && [ -w "$1" ]; then