mirror of
https://github.com/deajan/obackup.git
synced 2024-12-26 15:33:41 +01:00
Added missing -r to read
This commit is contained in:
parent
40af118c1e
commit
7b378dafb7
135
dev/n_obackup.sh
135
dev/n_obackup.sh
@ -1,14 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
#TODO: rework old IFS= statements
|
|
||||||
|
|
||||||
|
|
||||||
###### Remote push/pull (or local) backup script for files & databases
|
###### Remote push/pull (or local) backup script for files & databases
|
||||||
PROGRAM="obackup"
|
PROGRAM="obackup"
|
||||||
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.1-dev
|
PROGRAM_VERSION=2.1-dev
|
||||||
PROGRAM_BUILD=2016080801
|
PROGRAM_BUILD=2016080803
|
||||||
IS_STABLE=yes
|
IS_STABLE=yes
|
||||||
|
|
||||||
source "./ofunctions.sh"
|
source "./ofunctions.sh"
|
||||||
@ -205,10 +202,12 @@ function _ListDatabasesRemote {
|
|||||||
function ListDatabases {
|
function ListDatabases {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
local output_file # Return of subfunction
|
local outputFile # Return of subfunction
|
||||||
local db_name
|
local dbName
|
||||||
local db_size
|
local dbSize
|
||||||
local db_backup
|
local dbBackup
|
||||||
|
|
||||||
|
local dbArray
|
||||||
|
|
||||||
if [ $CAN_BACKUP_SQL -ne 1 ]; then
|
if [ $CAN_BACKUP_SQL -ne 1 ]; then
|
||||||
Logger "Cannot list databases." "ERROR"
|
Logger "Cannot list databases." "ERROR"
|
||||||
@ -220,61 +219,56 @@ function ListDatabases {
|
|||||||
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]; then
|
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]; then
|
||||||
_ListDatabasesLocal
|
_ListDatabasesLocal
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
output_file=""
|
outputFile=""
|
||||||
else
|
else
|
||||||
output_file="$RUN_DIR/$PROGRAM._ListDatabasesLocal.$SCRIPT_PID"
|
outputFile="$RUN_DIR/$PROGRAM._ListDatabasesLocal.$SCRIPT_PID"
|
||||||
fi
|
fi
|
||||||
elif [ "$BACKUP_TYPE" == "pull" ]; then
|
elif [ "$BACKUP_TYPE" == "pull" ]; then
|
||||||
_ListDatabasesRemote
|
_ListDatabasesRemote
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
output_file=""
|
outputFile=""
|
||||||
else
|
else
|
||||||
output_file="$RUN_DIR/$PROGRAM._ListDatabasesRemote.$SCRIPT_PID"
|
outputFile="$RUN_DIR/$PROGRAM._ListDatabasesRemote.$SCRIPT_PID"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$output_file" ] && [ $CAN_BACKUP_SQL -eq 1 ]; then
|
if [ -f "$outputFile" ] && [ $CAN_BACKUP_SQL -eq 1 ]; then
|
||||||
OLD_IFS=$IFS
|
while read -r line; do
|
||||||
IFS=$' \n'
|
while read -r name size; do dbName=$name; dbSize=$size; done <<< "$line"
|
||||||
for line in $(cat "$output_file")
|
#db_name="${line% *}"
|
||||||
do
|
#db_size="${line# *}"
|
||||||
db_name=$(echo $line | cut -f1)
|
#db_name=$(echo $line | cut -f1)
|
||||||
db_size=$(echo $line | cut -f2)
|
#db_size=$(echo $line | cut -f2)
|
||||||
|
|
||||||
if [ "$DATABASES_ALL" == "yes" ]; then
|
if [ "$DATABASES_ALL" == "yes" ]; then
|
||||||
db_backup=1
|
dbBackup=1
|
||||||
IFS=$PATH_SEPARATOR_CHAR
|
IFs=$PATH_SEPARATOR_CHAR read -r -a dbArray <<< "$DATABASES_ALL_EXCLUDE_LIST"
|
||||||
for j in $DATABASES_ALL_EXCLUDE_LIST
|
for j in "${dbArray[@]}"; do
|
||||||
do
|
if [ "$dbName" == "$j" ]; then
|
||||||
if [ "$db_name" == "$j" ]; then
|
dbBackup=0
|
||||||
db_backup=0
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
IFS=$' \n'
|
|
||||||
else
|
else
|
||||||
db_backup=0
|
dbBackup=0
|
||||||
IFS=$PATH_SEPARATOR_CHAR
|
IFs=$PATH_SEPARATOR_CHAR read -r -a dbArray <<< "$DATABASES_LIST"
|
||||||
for j in $DATABASES_LIST
|
for j in "${dbArray[@]}"; do
|
||||||
do
|
if [ "$dbName" == "$j" ]; then
|
||||||
if [ "$db_name" == "$j" ]; then
|
dbBackup=1
|
||||||
db_backup=1
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
IFS=$' \n'
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $db_backup -eq 1 ]; then
|
if [ $dbBackup -eq 1 ]; then
|
||||||
if [ "$SQL_BACKUP_TASKS" != "" ]; then
|
if [ "$SQL_BACKUP_TASKS" != "" ]; then
|
||||||
SQL_BACKUP_TASKS="$SQL_BACKUP_TASKS $db_name"
|
SQL_BACKUP_TASKS="$SQL_BACKUP_TASKS $dbName"
|
||||||
else
|
else
|
||||||
SQL_BACKUP_TASKS="$db_name"
|
SQL_BACKUP_TASKS="$dbName"
|
||||||
fi
|
fi
|
||||||
TOTAL_DATABASES_SIZE=$((TOTAL_DATABASES_SIZE+$db_size))
|
TOTAL_DATABASES_SIZE=$((TOTAL_DATABASES_SIZE+$dbSize))
|
||||||
else
|
else
|
||||||
SQL_EXCLUDED_TASKS="$SQL_EXCLUDED_TASKS $db_name"
|
SQL_EXCLUDED_TASKS="$SQL_EXCLUDED_TASKS $dbName"
|
||||||
fi
|
fi
|
||||||
done
|
done < "$outputFile"
|
||||||
IFS=$OLD_IFS
|
|
||||||
|
|
||||||
Logger "Database backup list: $SQL_BACKUP_TASKS" "DEBUG"
|
Logger "Database backup list: $SQL_BACKUP_TASKS" "DEBUG"
|
||||||
Logger "Database exclude list: $SQL_EXCLUDED_TASKS" "DEBUG"
|
Logger "Database exclude list: $SQL_EXCLUDED_TASKS" "DEBUG"
|
||||||
@ -292,7 +286,7 @@ function _ListRecursiveBackupDirectoriesLocal {
|
|||||||
local directory
|
local directory
|
||||||
local retval
|
local retval
|
||||||
|
|
||||||
IFS=$PATH_SEPARATOR_CHAR read -a directories <<< "$RECURSIVE_DIRECTORY_LIST"
|
IFS=$PATH_SEPARATOR_CHAR read -r -a directories <<< "$RECURSIVE_DIRECTORY_LIST"
|
||||||
for directory in "${directories[@]}"; do
|
for directory in "${directories[@]}"; do
|
||||||
# No sudo here, assuming you should have all necessary rights for local checks
|
# No sudo here, assuming you should have all necessary rights for local checks
|
||||||
cmd="$FIND_CMD -L $directory/ -mindepth 1 -maxdepth 1 -type d >> $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID 2> $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID"
|
cmd="$FIND_CMD -L $directory/ -mindepth 1 -maxdepth 1 -type d >> $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID 2> $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID"
|
||||||
@ -323,7 +317,7 @@ function _ListRecursiveBackupDirectoriesRemote {
|
|||||||
local directory
|
local directory
|
||||||
local retval
|
local retval
|
||||||
|
|
||||||
IFS=$PATH_SEPARATOR_CHAR read -a directories <<< "$RECURSIVE_DIRECTORY_LIST"
|
IFS=$PATH_SEPARATOR_CHAR read -r -a directories <<< "$RECURSIVE_DIRECTORY_LIST"
|
||||||
for directory in "${directories[@]}"; do
|
for directory in "${directories[@]}"; do
|
||||||
cmd=$SSH_CMD' "'$COMMAND_SUDO' '$REMOTE_FIND_CMD' -L '$directory'/ -mindepth 1 -maxdepth 1 -type d" >> '$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID' 2> '$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID
|
cmd=$SSH_CMD' "'$COMMAND_SUDO' '$REMOTE_FIND_CMD' -L '$directory'/ -mindepth 1 -maxdepth 1 -type d" >> '$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID' 2> '$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID
|
||||||
Logger "cmd: $cmd" "DEBUG"
|
Logger "cmd: $cmd" "DEBUG"
|
||||||
@ -351,6 +345,8 @@ function ListRecursiveBackupDirectories {
|
|||||||
local output_file
|
local output_file
|
||||||
local file_exclude
|
local file_exclude
|
||||||
|
|
||||||
|
local fileArray
|
||||||
|
|
||||||
Logger "Listing directories to backup." "NOTICE"
|
Logger "Listing directories to backup." "NOTICE"
|
||||||
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]; then
|
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]; then
|
||||||
_ListRecursiveBackupDirectoriesLocal
|
_ListRecursiveBackupDirectoriesLocal
|
||||||
@ -369,19 +365,14 @@ function ListRecursiveBackupDirectories {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$output_file" ]; then
|
if [ -f "$output_file" ]; then
|
||||||
OLD_IFS=$IFS
|
while read -r line; do
|
||||||
IFS=$' \n'
|
|
||||||
for line in $(cat "$output_file")
|
|
||||||
do
|
|
||||||
file_exclude=0
|
file_exclude=0
|
||||||
IFS=$PATH_SEPARATOR_CHAR
|
IFS=$PATH_SEPARATOR_CHAR read -r -a fileArray <<< "$RECURSIVE_EXCLUDE_LIST"
|
||||||
for k in $RECURSIVE_EXCLUDE_LIST
|
for k in "${fileArray[@]}"; do
|
||||||
do
|
|
||||||
if [ "$k" == "$line" ]; then
|
if [ "$k" == "$line" ]; then
|
||||||
file_exclude=1
|
file_exclude=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
IFS=$' \n'
|
|
||||||
|
|
||||||
if [ $file_exclude -eq 0 ]; then
|
if [ $file_exclude -eq 0 ]; then
|
||||||
if [ "$FILE_RECURSIVE_BACKUP_TASKS" == "" ]; then
|
if [ "$FILE_RECURSIVE_BACKUP_TASKS" == "" ]; then
|
||||||
@ -394,14 +385,11 @@ function ListRecursiveBackupDirectories {
|
|||||||
else
|
else
|
||||||
FILE_RECURSIVE_EXCLUDED_TASKS="$FILE_RECURSIVE_EXCLUDED_TASKS$PATH_SEPARATOR_CHAR$line"
|
FILE_RECURSIVE_EXCLUDED_TASKS="$FILE_RECURSIVE_EXCLUDED_TASKS$PATH_SEPARATOR_CHAR$line"
|
||||||
fi
|
fi
|
||||||
done
|
done < "$output_file"
|
||||||
IFS=$OLD_IFS
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLD_IFS=$IFS
|
IFS=$PATH_SEPARATOR_CHAR read -r -a fileArray <<< "$DIRECTORY_LIST"
|
||||||
IFS=$PATH_SEPARATOR_CHAR
|
for directory in "${fileArray[@]}"; do
|
||||||
for directory in $DIRECTORY_LIST
|
|
||||||
do
|
|
||||||
FILE_SIZE_LIST="$FILE_SIZE_LIST $(EscapeSpaces $directory)"
|
FILE_SIZE_LIST="$FILE_SIZE_LIST $(EscapeSpaces $directory)"
|
||||||
if [ "$FILE_BACKUP_TASKS" == "" ]; then
|
if [ "$FILE_BACKUP_TASKS" == "" ]; then
|
||||||
FILE_BACKUP_TASKS="$directory"
|
FILE_BACKUP_TASKS="$directory"
|
||||||
@ -409,7 +397,6 @@ function ListRecursiveBackupDirectories {
|
|||||||
FILE_BACKUP_TASKS="$FILE_BACKUP_TASKS$PATH_SEPARATOR_CHAR$directory"
|
FILE_BACKUP_TASKS="$FILE_BACKUP_TASKS$PATH_SEPARATOR_CHAR$directory"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
IFS=$OLD_IFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _GetDirectoriesSizeLocal {
|
function _GetDirectoriesSizeLocal {
|
||||||
@ -817,8 +804,6 @@ function BackupDatabases {
|
|||||||
|
|
||||||
local database
|
local database
|
||||||
|
|
||||||
OLD_IFS=$IFS
|
|
||||||
IFS=$' \t\n'
|
|
||||||
for database in $SQL_BACKUP_TASKS
|
for database in $SQL_BACKUP_TASKS
|
||||||
do
|
do
|
||||||
Logger "Backing up database [$database]." "NOTICE"
|
Logger "Backing up database [$database]." "NOTICE"
|
||||||
@ -826,7 +811,6 @@ function BackupDatabases {
|
|||||||
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME_DB_TASK $HARD_MAX_EXEC_TIME_DB_TASK ${FUNCNAME[0]} false true
|
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME_DB_TASK $HARD_MAX_EXEC_TIME_DB_TASK ${FUNCNAME[0]} false true
|
||||||
CheckTotalExecutionTime
|
CheckTotalExecutionTime
|
||||||
done
|
done
|
||||||
IFS=$OLD_IFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Rsync {
|
function Rsync {
|
||||||
@ -927,7 +911,7 @@ function FilesBackup {
|
|||||||
local backupTask
|
local backupTask
|
||||||
local backupTasks
|
local backupTasks
|
||||||
|
|
||||||
IFS=$PATH_SEPARATOR_CHAR read -a backupTasks <<< "$FILE_BACKUP_TASKS"
|
IFS=$PATH_SEPARATOR_CHAR read -r -a backupTasks <<< "$FILE_BACKUP_TASKS"
|
||||||
for backupTask in "${backupTasks[@]}"; do
|
for backupTask in "${backupTasks[@]}"; do
|
||||||
Logger "Beginning file backup of [$backupTask]." "NOTICE"
|
Logger "Beginning file backup of [$backupTask]." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ]; then
|
if [ "$ENCRYPTION" == "yes" ]; then
|
||||||
@ -938,7 +922,7 @@ function FilesBackup {
|
|||||||
CheckTotalExecutionTime
|
CheckTotalExecutionTime
|
||||||
done
|
done
|
||||||
|
|
||||||
IFS=$PATH_SEPARATOR_CHAR read -a backupTasks <<< "$RECURSIVE_DIRECTORY_LIST"
|
IFS=$PATH_SEPARATOR_CHAR read -r -a backupTasks <<< "$RECURSIVE_DIRECTORY_LIST"
|
||||||
for backupTask in "${backupTasks[@]}"; do
|
for backupTask in "${backupTasks[@]}"; do
|
||||||
Logger "Beginning non recursive file backup of [$backupTask]." "NOTICE"
|
Logger "Beginning non recursive file backup of [$backupTask]." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ]; then
|
if [ "$ENCRYPTION" == "yes" ]; then
|
||||||
@ -949,12 +933,9 @@ function FilesBackup {
|
|||||||
CheckTotalExecutionTime
|
CheckTotalExecutionTime
|
||||||
done
|
done
|
||||||
|
|
||||||
IFS=$PATH_SEPARATOR_CHAR read -a backupTasks <<< "$FILE_RECURSIVE_BACKUP_TASKS"
|
IFS=$PATH_SEPARATOR_CHAR read -r -a backupTasks <<< "$FILE_RECURSIVE_BACKUP_TASKS"
|
||||||
for backupTask in "${backupTasks[@]}"; do
|
for backupTask in "${backupTasks[@]}"; do
|
||||||
|
|
||||||
# Backup sub directories of recursive directories
|
# Backup sub directories of recursive directories
|
||||||
#for BACKUP_TASK in $FILE_RECURSIVE_BACKUP_TASKS
|
|
||||||
#do
|
|
||||||
Logger "Beginning recursive file backup of [$backupTask]." "NOTICE"
|
Logger "Beginning recursive file backup of [$backupTask]." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ]; then
|
if [ "$ENCRYPTION" == "yes" ]; then
|
||||||
Duplicity "$backupTask" "recurse"
|
Duplicity "$backupTask" "recurse"
|
||||||
@ -963,7 +944,6 @@ function FilesBackup {
|
|||||||
fi
|
fi
|
||||||
CheckTotalExecutionTime
|
CheckTotalExecutionTime
|
||||||
done
|
done
|
||||||
#IFS=$OLD_IFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckTotalExecutionTime {
|
function CheckTotalExecutionTime {
|
||||||
@ -991,13 +971,9 @@ function _RotateBackupsLocal {
|
|||||||
local cmd
|
local cmd
|
||||||
local path
|
local path
|
||||||
|
|
||||||
OLD_IFS=$IFS
|
find "$backup_path" -iname "*.$PROGRAM.*" -print0 | while IFS= read -r -d $'\0' backup; do
|
||||||
IFS=$'\t\n'
|
|
||||||
for backup in $(ls -I "*.$PROGRAM.*" "$backup_path")
|
|
||||||
do
|
|
||||||
copy=$rotate_copies
|
copy=$rotate_copies
|
||||||
while [ $copy -gt 1 ]
|
while [ $copy -gt 1 ]; do
|
||||||
do
|
|
||||||
if [ $copy -eq $rotate_copies ]; then
|
if [ $copy -eq $rotate_copies ]; then
|
||||||
cmd="rm -rf \"$backup_path/$backup.$PROGRAM.$copy\""
|
cmd="rm -rf \"$backup_path/$backup.$PROGRAM.$copy\""
|
||||||
Logger "cmd: $cmd" "DEBUG"
|
Logger "cmd: $cmd" "DEBUG"
|
||||||
@ -1050,7 +1026,6 @@ function _RotateBackupsLocal {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
IFS=$OLD_IFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _RotateBackupsRemote {
|
function _RotateBackupsRemote {
|
||||||
@ -1100,13 +1075,9 @@ function RemoteLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _RotateBackupsRemoteSSH {
|
function _RotateBackupsRemoteSSH {
|
||||||
OLD_IFS=$IFS
|
find "$backup_path" -iname "*.$PROGRAM.*" -print0 | while IFS= read -r -d $'\0' backup; do
|
||||||
IFS=$'\t\n'
|
|
||||||
for backup in $(ls -I "*.$PROGRAM.*" "$backup_path")
|
|
||||||
do
|
|
||||||
copy=$rotate_copies
|
copy=$rotate_copies
|
||||||
while [ $copy -gt 1 ]
|
while [ $copy -gt 1 ]; do
|
||||||
do
|
|
||||||
if [ $copy -eq $rotate_copies ]; then
|
if [ $copy -eq $rotate_copies ]; then
|
||||||
cmd="$COMMAND_SUDO rm -rf \"$backup_path/$backup.$PROGRAM.$copy\""
|
cmd="$COMMAND_SUDO rm -rf \"$backup_path/$backup.$PROGRAM.$copy\""
|
||||||
RemoteLogger "cmd: $cmd" "DEBUG"
|
RemoteLogger "cmd: $cmd" "DEBUG"
|
||||||
@ -1154,7 +1125,6 @@ function _RotateBackupsRemoteSSH {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
IFS=$OLD_IFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_RotateBackupsRemoteSSH
|
_RotateBackupsRemoteSSH
|
||||||
@ -1321,8 +1291,7 @@ function GetCommandlineArguments {
|
|||||||
Usage
|
Usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for i in "$@"
|
for i in "$@"; do
|
||||||
do
|
|
||||||
case $i in
|
case $i in
|
||||||
--dry)
|
--dry)
|
||||||
_DRYRUN=1
|
_DRYRUN=1
|
||||||
|
Loading…
Reference in New Issue
Block a user