mirror of
https://github.com/deajan/obackup.git
synced 2025-05-10 20:23:41 +02:00
Obackup v1.84 RC2 upload
This commit is contained in:
parent
50c7f2fd82
commit
84a2b3a532
21
CHANGELOG.md
21
CHANGELOG.md
@ -1,11 +1,26 @@
|
|||||||
|
## FUTURE IMPROVEMENTS
|
||||||
|
|
||||||
|
- Rewrite rsync exclude patterns using \"pattern\" instead of escaped chars
|
||||||
|
|
||||||
|
## Known issues
|
||||||
|
|
||||||
|
- Backup size check counts excluded patterns
|
||||||
|
|
||||||
## Latest changelog
|
## Latest changelog
|
||||||
|
|
||||||
|
- 18 Aug. 2013: Now v1.84 RC2
|
||||||
|
- Added personalized log file option
|
||||||
|
- Simplified dryrun (removed dryrun function and merged it with main function)
|
||||||
|
- Simplified Init function
|
||||||
|
- Added --stat switch to rsync execution
|
||||||
|
- Added bandwidth limit
|
||||||
|
- Added --no-maxtime switch
|
||||||
- Fixed LoadConfigFile function will not warn on wrong config file
|
- Fixed LoadConfigFile function will not warn on wrong config file
|
||||||
- More code cleanup
|
- More code cleanup
|
||||||
- Added --verbose parameter (yeah... Feature freeze i said ? Well this is not a feature)
|
- Added --verbose switch (will add databases list, rsync commands, and file backup list)
|
||||||
- Improved task execution checks and more code cleanup
|
- Improved task execution checks and more code cleanup
|
||||||
- Fixed CleanUp even if DEBUG=yes
|
- Fixed CleanUp function if DEBUG=yes, also function is now launched from TrapQuit
|
||||||
- 16 Jul. 2013 Feature freeze, version tagged as v1.84 RC1
|
- 16 Jul. 2013: version tagged as v1.84 RC1
|
||||||
- Code cleanup
|
- Code cleanup
|
||||||
- Uploaded first documentation
|
- Uploaded first documentation
|
||||||
- Fixed an issue with RotateBackups
|
- Fixed an issue with RotateBackups
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
###### Remote (or local) backup script for files & databases
|
###### Remote (or local) backup script for files & databases
|
||||||
###### (L) 2013 by Ozy de Jong (www.badministrateur.com)
|
###### (L) 2013 by Ozy de Jong (www.badministrateur.com)
|
||||||
###### Config file rev 0408201301
|
###### Config file rev 1808201301
|
||||||
|
|
||||||
## Backup identification, any string you want
|
## Backup identification, any string you want
|
||||||
BACKUP_ID="your backup name"
|
BACKUP_ID="your backup name"
|
||||||
|
|
||||||
|
## Leaving this empty will create a logfile at /var/log/obackup_version_BACKUP_ID.log
|
||||||
|
LOGFILE=""
|
||||||
|
|
||||||
## General backup options
|
## General backup options
|
||||||
BACKUP_SQL=no
|
BACKUP_SQL=no
|
||||||
BACKUP_FILES=yes
|
BACKUP_FILES=yes
|
||||||
@ -22,6 +25,9 @@ BACKUP_SIZE_MINIMUM=1024
|
|||||||
## Generate an alert if local storage free space is lower than given value in Kb.
|
## Generate an alert if local storage free space is lower than given value in Kb.
|
||||||
LOCAL_STORAGE_WARN_MIN_SPACE=1048576
|
LOCAL_STORAGE_WARN_MIN_SPACE=1048576
|
||||||
|
|
||||||
|
## Bandwidth limit Kbytes / second. Leave 0 to disable limitation.
|
||||||
|
BANDWIDTH=0
|
||||||
|
|
||||||
## If enabled, file backups will be processed with sudo command. See documentation for /etc/sudoers configuration ("find", "du" and "rsync" need to be allowed). Requiretty needs to be disabled.
|
## If enabled, file backups will be processed with sudo command. See documentation for /etc/sudoers configuration ("find", "du" and "rsync" need to be allowed). Requiretty needs to be disabled.
|
||||||
SUDO_EXEC=no
|
SUDO_EXEC=no
|
||||||
## Paranoia option. Don't change this unless you read the documentation and still feel concerned about security issues.
|
## Paranoia option. Don't change this unless you read the documentation and still feel concerned about security issues.
|
||||||
|
141
obackup.sh
141
obackup.sh
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
###### Remote (or local) backup script for files & databases
|
###### Remote (or local) backup script for files & databases
|
||||||
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
|
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
|
||||||
OBACKUP_VERSION=1.84RC1
|
OBACKUP_VERSION=1.84RC2
|
||||||
OBACKUP_BUILD=0408201301
|
OBACKUP_BUILD=1808201302
|
||||||
|
|
||||||
DEBUG=no
|
DEBUG=no
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
@ -65,7 +65,6 @@ function TrapError
|
|||||||
function TrapStop
|
function TrapStop
|
||||||
{
|
{
|
||||||
LogError " /!\ WARNING: Manual exit of backup script. Backups may be in inconsistent state."
|
LogError " /!\ WARNING: Manual exit of backup script. Backups may be in inconsistent state."
|
||||||
CleanUp
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,9 +73,11 @@ function TrapQuit
|
|||||||
if [ $error_alert -ne 0 ]
|
if [ $error_alert -ne 0 ]
|
||||||
then
|
then
|
||||||
SendAlert
|
SendAlert
|
||||||
|
CleanUp
|
||||||
LogError "Backup script finished with errors."
|
LogError "Backup script finished with errors."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
CleanUp
|
||||||
Log "Backup script finshed."
|
Log "Backup script finshed."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -752,25 +753,6 @@ function RsyncExcludePattern
|
|||||||
IFS=$OLD_IFS
|
IFS=$OLD_IFS
|
||||||
}
|
}
|
||||||
|
|
||||||
function RsyncArgs
|
|
||||||
{
|
|
||||||
RSYNC_ARGS=-rlptgoDE
|
|
||||||
if [ "$PRESERVE_ACLS" == "yes" ]
|
|
||||||
then
|
|
||||||
RSYNC_ARGS=$RSYNC_ARGS"A"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$PRESERVE_XATTR" == "yes" ]
|
|
||||||
then
|
|
||||||
RSYNC_ARGS=$RSYNC_ARGS"X"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$RSYNC_COMPRESS" == "yes" ]
|
|
||||||
then
|
|
||||||
RSYNC_ARGS=$RSYNC_ARGS"z"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function Rsync
|
function Rsync
|
||||||
{
|
{
|
||||||
i="$(StripQuotes $1)"
|
i="$(StripQuotes $1)"
|
||||||
@ -800,14 +782,14 @@ function Rsync
|
|||||||
LogError "Connectivity test failed. Stopping current task."
|
LogError "Connectivity test failed. Stopping current task."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
rsync_cmd="$(which $RSYNC_EXECUTABLE) $RSYNC_ARGS --delete $RSYNC_EXCLUDE --rsync-path=\"$RSYNC_PATH\" -e \"$RSYNC_SSH_CMD\" \"$REMOTE_USER@$REMOTE_HOST:$1\" \"$local_file_storage_path\" > /dev/shm/obackup_rsync_output_$SCRIPT_PID 2>&1"
|
rsync_cmd="$(which $RSYNC_EXECUTABLE) $RSYNC_ARGS --stats --delete $RSYNC_EXCLUDE --rsync-path=\"$RSYNC_PATH\" -e \"$RSYNC_SSH_CMD\" \"$REMOTE_USER@$REMOTE_HOST:$1\" \"$local_file_storage_path\" > /dev/shm/obackup_rsync_output_$SCRIPT_PID 2>&1"
|
||||||
else
|
else
|
||||||
rsync_cmd="$(which $RSYNC_EXECUTABLE) $RSYNC_ARGS --delete $RSYNC_EXCLUDE --rsync-path=\"$RSYNC_PATH\" \"$1\" \"$local_file_storage_path\" > /dev/shm/obackup_rsync_output_$SCRIPT_PID 2>&1"
|
rsync_cmd="$(which $RSYNC_EXECUTABLE) $RSYNC_ARGS --stats --delete $RSYNC_EXCLUDE --rsync-path=\"$RSYNC_PATH\" \"$1\" \"$local_file_storage_path\" > /dev/shm/obackup_rsync_output_$SCRIPT_PID 2>&1"
|
||||||
fi
|
fi
|
||||||
#### Eval is used so the full command is processed without bash adding single quotes round variables
|
#### Eval is used so the full command is processed without bash adding single quotes round variables
|
||||||
if [ "$DEBUG" == "yes" ]
|
if [ $verbose -eq 1 ]
|
||||||
then
|
then
|
||||||
Log $rsync_cmd
|
Log "RSYNC_CMD: $rsync_cmd"
|
||||||
fi
|
fi
|
||||||
eval $rsync_cmd
|
eval $rsync_cmd
|
||||||
exit $?
|
exit $?
|
||||||
@ -827,6 +809,11 @@ function FilesBackup
|
|||||||
child_pid=$!
|
child_pid=$!
|
||||||
WaitForTaskCompletion $child_pid $SOFT_MAX_EXEC_TIME_FILE_TASK $HARD_MAX_EXEC_TIME_FILE_TASK
|
WaitForTaskCompletion $child_pid $SOFT_MAX_EXEC_TIME_FILE_TASK $HARD_MAX_EXEC_TIME_FILE_TASK
|
||||||
retval=$?
|
retval=$?
|
||||||
|
if [ $verbose -eq 1 ]
|
||||||
|
then
|
||||||
|
Log "List:\n$(cat /dev/shm/obackup_rsync_output_$SCRIPT_PID)"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $retval -ne 0 ]
|
if [ $retval -ne 0 ]
|
||||||
then
|
then
|
||||||
LogError "Backup failed on remote files."
|
LogError "Backup failed on remote files."
|
||||||
@ -910,7 +897,13 @@ function Init
|
|||||||
trap 'TrapError ${LINENO} $?' ERR
|
trap 'TrapError ${LINENO} $?' ERR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LOG_FILE=/var/log/obackup_$OBACKUP_VERSION-$BACKUP_ID.log
|
if [ "$LOGFILE" == "" ]
|
||||||
|
then
|
||||||
|
LOG_FILE=/var/log/obackup_$OBACKUP_VERSION-$BACKUP_ID.log
|
||||||
|
else
|
||||||
|
LOG_FILE="$LOGFILE"
|
||||||
|
fi
|
||||||
|
|
||||||
MAIL_ALERT_MSG="Warning: Execution of obackup instance $BACKUP_ID (pid $SCRIPT_PID) as $LOCAL_USER@$LOCAL_HOST produced errors."
|
MAIL_ALERT_MSG="Warning: Execution of obackup instance $BACKUP_ID (pid $SCRIPT_PID) as $LOCAL_USER@$LOCAL_HOST produced errors."
|
||||||
|
|
||||||
## Set SSH command
|
## Set SSH command
|
||||||
@ -939,6 +932,34 @@ function Init
|
|||||||
COMMAND_SUDO=""
|
COMMAND_SUDO=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## Set Rsync arguments
|
||||||
|
RSYNC_ARGS=-rlptgoDE
|
||||||
|
if [ "$PRESERVE_ACLS" == "yes" ]
|
||||||
|
then
|
||||||
|
RSYNC_ARGS=$RSYNC_ARGS"A"
|
||||||
|
fi
|
||||||
|
if [ "$PRESERVE_XATTR" == "yes" ]
|
||||||
|
then
|
||||||
|
RSYNC_ARGS=$RSYNC_ARGS"X"
|
||||||
|
fi
|
||||||
|
if [ "$RSYNC_COMPRESS" == "yes" ]
|
||||||
|
then
|
||||||
|
RSYNC_ARGS=$RSYNC_ARGS"z"
|
||||||
|
fi
|
||||||
|
if [ $verbose -eq 1 ]
|
||||||
|
then
|
||||||
|
RSYNC_ARGS=$RSYNC_ARGS"i"
|
||||||
|
fi
|
||||||
|
if [ $dryrun -eq 1 ]
|
||||||
|
then
|
||||||
|
RSYNC_ARGS=$RSYNC_ARGS"n"
|
||||||
|
DRY_WARNING="/!\ DRY RUN"
|
||||||
|
fi
|
||||||
|
if [ "$BANDWIDTH" != "0" ]
|
||||||
|
then
|
||||||
|
RSYNC_ARGS=$RSYNC_ARGS" --bwlimit=$BANDWIDTH"
|
||||||
|
fi
|
||||||
|
|
||||||
## Set compression executable and extension
|
## Set compression executable and extension
|
||||||
if [ "$COMPRESSION_PROGRAM" == "xz" ] && type -p xz > /dev/null 2>&1
|
if [ "$COMPRESSION_PROGRAM" == "xz" ] && type -p xz > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
@ -979,8 +1000,6 @@ function DryRun
|
|||||||
|
|
||||||
function Main
|
function Main
|
||||||
{
|
{
|
||||||
Log "Backup launched as $LOCAL_USER@$LOCAL_HOST (PID $SCRIPT_PID)"
|
|
||||||
|
|
||||||
if [ "$BACKUP_SQL" != "no" ]
|
if [ "$BACKUP_SQL" != "no" ]
|
||||||
then
|
then
|
||||||
ListDatabases
|
ListDatabases
|
||||||
@ -990,26 +1009,37 @@ function Main
|
|||||||
ListDirectories
|
ListDirectories
|
||||||
GetDirectoriesSize
|
GetDirectoriesSize
|
||||||
fi
|
fi
|
||||||
CreateLocalStorageDirectories
|
if [ $dryrun -ne 1 ]
|
||||||
|
then
|
||||||
|
CreateLocalStorageDirectories
|
||||||
|
fi
|
||||||
CheckSpaceRequirements
|
CheckSpaceRequirements
|
||||||
|
|
||||||
# Make Backup
|
# Actual backup process
|
||||||
if [ "$BACKUP_SQL" != "no" ]
|
if [ "$BACKUP_SQL" != "no" ]
|
||||||
then
|
then
|
||||||
if [ "$ROTATE_BACKUPS" == "yes" ]
|
if [ $dryrun -ne 1 ]
|
||||||
then
|
then
|
||||||
RotateBackups $LOCAL_SQL_STORAGE
|
if [ "$ROTATE_BACKUPS" == "yes" ]
|
||||||
|
then
|
||||||
|
RotateBackups $LOCAL_SQL_STORAGE
|
||||||
|
fi
|
||||||
|
BackupDatabases
|
||||||
|
else
|
||||||
|
Log "DRYRUN: databases not backed up."
|
||||||
fi
|
fi
|
||||||
BackupDatabases
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$BACKUP_FILES" != "no" ]
|
if [ "$BACKUP_FILES" != "no" ]
|
||||||
then
|
then
|
||||||
if [ "$ROTATE_BACKUPS" == "yes" ]
|
if [ $dryrun -ne 1 ]
|
||||||
then
|
then
|
||||||
RotateBackups $LOCAL_FILE_STORAGE
|
if [ "$ROTATE_BACKUPS" == "yes" ]
|
||||||
|
then
|
||||||
|
RotateBackups $LOCAL_FILE_STORAGE
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
RsyncExcludePattern
|
RsyncExcludePattern
|
||||||
RsyncArgs
|
|
||||||
FilesBackup
|
FilesBackup
|
||||||
fi
|
fi
|
||||||
# Be a happy sysadmin (and drink a coffee ? Nahh... it's past midnight.)
|
# Be a happy sysadmin (and drink a coffee ? Nahh... it's past midnight.)
|
||||||
@ -1019,18 +1049,25 @@ function Usage
|
|||||||
{
|
{
|
||||||
echo "Obackup $OBACKUP_VERSION $OBACKUP_BUILD"
|
echo "Obackup $OBACKUP_VERSION $OBACKUP_BUILD"
|
||||||
echo ""
|
echo ""
|
||||||
echo "usage: obackup backup_name [--dry] [--silent] [--verbose]"
|
echo "usage: obackup backup_name [--dry] [--silent] [--verbose] [--no-maxtime]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "--dry: will run obackup without actually doing anything, just testing"
|
echo "--dry: will run obackup without actually doing anything, just testing"
|
||||||
echo "--silent: will run obackup without any output to stdout, usefull for cron backups"
|
echo "--silent: will run obackup without any output to stdout, usefull for cron backups"
|
||||||
echo "--verbose: adds command outputs"
|
echo "--verbose: adds command outputs"
|
||||||
|
echo "--no-maxtime: disables any soft and hard execution time checks"
|
||||||
exit 128
|
exit 128
|
||||||
}
|
}
|
||||||
|
|
||||||
# Command line argument flags
|
# Command line argument flags
|
||||||
dryrun=0
|
dryrun=0
|
||||||
silent=0
|
silent=0
|
||||||
verbose=0
|
no_maxtime=0
|
||||||
|
if [ "$DEBUG" == "yes" ]
|
||||||
|
then
|
||||||
|
verbose=1
|
||||||
|
else
|
||||||
|
verbose=0
|
||||||
|
fi
|
||||||
# Alert flags
|
# Alert flags
|
||||||
soft_alert_total=0
|
soft_alert_total=0
|
||||||
error_alert=0
|
error_alert=0
|
||||||
@ -1052,6 +1089,9 @@ do
|
|||||||
--verbose)
|
--verbose)
|
||||||
verbose=1
|
verbose=1
|
||||||
;;
|
;;
|
||||||
|
--no-maxtime)
|
||||||
|
no_maxtime=1
|
||||||
|
;;
|
||||||
--help|-h|--version|-v)
|
--help|-h|--version|-v)
|
||||||
Usage
|
Usage
|
||||||
;;
|
;;
|
||||||
@ -1069,18 +1109,19 @@ then
|
|||||||
Init
|
Init
|
||||||
DATE=$(date)
|
DATE=$(date)
|
||||||
Log "--------------------------------------------------------------------"
|
Log "--------------------------------------------------------------------"
|
||||||
Log "$DATE - Obackup v$OBACKUP_VERSION script begin."
|
Log "$DRY_WARNING $DATE - Obackup v$OBACKUP_VERSION script begin."
|
||||||
Log "--------------------------------------------------------------------"
|
Log "--------------------------------------------------------------------"
|
||||||
if [ $dryrun -eq 1 ]
|
Log "Backup task [$BACKUP_ID] launched as $LOCAL_USER@$LOCAL_HOST (PID $SCRIPT_PID)"
|
||||||
then
|
if [ $no_maxtime -eq 1 ]
|
||||||
DryRun
|
then
|
||||||
else
|
SOFT_MAX_EXEC_TIME=0
|
||||||
OLD_IFS=$IFS
|
HARD_MAX_EXEC_TIME=0
|
||||||
RunBeforeHook
|
fi
|
||||||
Main
|
OLD_IFS=$IFS
|
||||||
IFS=$OLD_IFS
|
RunBeforeHook
|
||||||
RunAfterHook
|
Main
|
||||||
fi
|
IFS=$OLD_IFS
|
||||||
|
RunAfterHook
|
||||||
CleanUp
|
CleanUp
|
||||||
else
|
else
|
||||||
LogError "Configuration file could not be loaded."
|
LogError "Configuration file could not be loaded."
|
||||||
|
Loading…
Reference in New Issue
Block a user