1
0
mirror of https://github.com/deajan/obackup.git synced 2026-02-11 17:40:57 +01:00

143 Commits

Author SHA1 Message Date
deajan
775bd031ef Rebuilt targets 2016-08-16 23:24:54 +02:00
deajan
47e2b54117 Bumped version 2016-08-16 23:24:29 +02:00
deajan
52262f0cfc Updated changelog 2016-08-16 23:23:37 +02:00
deajan
a70b167c42 Fixed double RunAfterHook execution 2016-08-16 23:22:38 +02:00
Orsiris de Jong
41a903e74f Update README.md 2016-08-09 15:42:35 +02:00
Orsiris de Jong
7f52618b77 Update CHANGELOG.md 2016-08-08 00:28:57 +02:00
deajan
e0ebd12742 Fixed wrong ofunctions ver 2016-08-07 23:21:58 +02:00
deajan
63b82025ff Rebuilt target 2016-08-06 16:18:43 +02:00
deajan
759621c045 Renewed install info 2016-08-06 13:45:41 +02:00
deajan
200b0a8685 Bumped version to 2.0 2016-08-06 13:42:25 +02:00
deajan
7f99fd6c67 Fixed double pattern declaration 2016-08-06 13:16:45 +02:00
deajan
af8e220e33 Updated changelog 2016-08-05 23:57:10 +02:00
deajan
b1c6aeb6fc Fixed mysqldump error codes not honored 2016-07-19 13:28:16 +02:00
deajan
fcab617c0d Code cleanup 2016-07-19 13:26:16 +02:00
deajan
557738a5e5 Code cleanup 2016-07-19 12:58:05 +02:00
deajan
f2d121f38f Rebuild after osync fix #52 2016-07-19 10:53:55 +02:00
deajan
2488f9f654 Fix for osync bug #52 2016-07-19 10:53:33 +02:00
deajan
48c178ed6b Updated ofunctions 2016-05-26 22:34:08 +02:00
deajan
82e1b68398 Minor additions to ofunctions 2016-05-26 22:33:47 +02:00
deajan
22cc71c9e3 Vastly improved installer script 2016-05-26 11:11:56 +02:00
deajan
7a7a7c08bc Fixed regression for Mac/BSD 2016-05-26 11:11:43 +02:00
deajan
5808e87057 Bumped version to v2.0-RC1 2016-05-25 20:11:37 +02:00
deajan
a41fcdd00a Added more windows specific settings 2016-05-25 19:56:08 +02:00
deajan
04a66b2c9c Updated ofunctions 2016-05-25 19:55:54 +02:00
deajan
92c3b38fff Finished windows support for generic mail sending function 2016-05-25 19:55:20 +02:00
deajan
1aaf80eff7 osync specific changes, no impact on obackup 2016-05-25 19:54:47 +02:00
deajan
ba9455d7e9 Fixed systemd path 2016-05-25 00:36:50 +02:00
deajan
c68e326a45 Fixed silent option shouldn't exist in batch mode 2016-05-25 00:36:36 +02:00
deajan
104d7a0dde Fixed install on MacOS. Also added os report. 2016-05-09 11:28:33 +02:00
deajan
fdc71ceda3 Fixed installer paths 2016-04-14 18:01:18 +02:00
deajan
e7fb070400 BSD compat and fixes 2016-04-13 12:16:23 +02:00
deajan
2c51055209 More debugging love for KillChilds 2016-04-12 09:41:16 +02:00
deajan
1913c897f1 More debugging in KillChilds 2016-04-12 09:14:44 +02:00
deajan
f5dfc478a2 Fixed bogus debug line in Killchilds 2016-04-10 21:11:59 +02:00
deajan
e0e3804e27 Redirect curl to /dev/null 2016-04-08 21:11:57 +02:00
deajan
39de9cdfa5 Some msys/cygwin compat fixes 2016-04-08 21:09:00 +02:00
deajan
78233a408e Improved usage text 2016-04-06 21:08:24 +02:00
deajan
d0982a6cf6 Added more preflight checks 2016-04-06 21:02:33 +02:00
deajan
15d3d98164 Added an option to run after exec cmd on error 2016-04-06 20:47:04 +02:00
deajan
9d057ea95f Made logging begin before remote checks 2016-04-06 20:41:58 +02:00
deajan
e3c9c5cb18 Updated ofunctions.sh with userland logging 2016-04-06 20:41:34 +02:00
deajan
4ad99413f4 Added userland logging 2016-04-06 20:40:20 +02:00
deajan
4e61708b85 renamed host_backup.conf file to example 2016-04-06 14:54:07 +02:00
deajan
33570bc3f1 Reversed some function args to make debug easier 2016-04-01 21:22:18 +02:00
Orsiris de Jong
79ec8668e4 Merge pull request #6 from deajan/betterKillChilds
Better kill childs works flawlessly
2016-04-01 21:20:09 +02:00
deajan
087638c8ae Fixing wrong ofunctions.sh upload 2016-03-31 23:00:01 +02:00
deajan
d39f6d092d Better KillChild and WaitForTaskCompletion 2016-03-31 14:28:18 +02:00
deajan
b91f80702e Reverted using eval in SendAlert 2016-03-31 11:59:53 +02:00
deajan
2d95d4e64b Improved upgrade script so it can add values to v2-pre config files 2016-03-31 10:59:21 +02:00
deajan
38c39360b7 Added pre-flight check for SSH_IGNORE_KNOWN_HOSTS 2016-03-31 10:54:24 +02:00
deajan
91dd9f5104 Fixed missing SSH OPTS in RSYNC_SSH 2016-03-31 10:05:30 +02:00
deajan
60266c40a6 Fixed bogus SSH_OPTS variable 2016-03-31 10:02:42 +02:00
deajan
a7e8487df3 Added optional statistics for installer 2016-03-25 22:51:26 +01:00
deajan
6d410409a3 Added ignore ssh knownhosts to upgrade script 2016-03-25 21:52:31 +01:00
deajan
b9d2b72ac9 Added ignore known hosts option to obackup 2016-03-25 20:07:27 +01:00
deajan
7eeff3b476 Added an option to ignore ssh known hosts 2016-03-25 20:05:29 +01:00
deajan
a61cb4d7cd Fixed pfSense mail according to jimp's comment 2016-03-22 14:15:40 +01:00
deajan
ac50d769c9 Added pfSense mail.php support 2016-03-22 12:38:09 +01:00
deajan
6a4c56b939 Fixed forgotten git / values 2016-03-22 10:57:41 +01:00
deajan
7ed0e71ab4 Fixed installer for FreeBSD 2016-03-22 10:56:14 +01:00
deajan
f931227cd2 Minor enhancement in os detection log 2016-03-20 16:52:49 +01:00
deajan
c2675e125d Added cygwin to supported OS list 2016-03-20 16:49:29 +01:00
deajan
234fcd9887 Fixed not using remote find cmd defined by InitRemoteOSSettings 2016-03-18 19:20:28 +01:00
deajan
5c74224dcd Some sanity code cleanup 2016-03-14 21:50:40 +01:00
deajan
e18ebd1115 Removed default sudo exec option 2016-03-11 12:04:18 +01:00
deajan
69fc7ac9cd Reduced log level for 3rdparty pings 2016-03-10 10:26:26 +01:00
deajan
0f11faa7c7 Improved logging for execution time 2016-03-04 09:34:02 +01:00
deajan
d2ab111f90 Improved mail sending 2016-03-03 16:33:59 +01:00
deajan
d36c77d777 Moved loglevel from stdout to logfile only 2016-03-03 16:29:32 +01:00
deajan
b27ee4f8c1 Added loglevel to log filesé 2016-03-03 16:26:52 +01:00
deajan
192e1d2f65 Added instance run check. 2016-03-03 16:06:27 +01:00
deajan
6eea38afdf Fixed rsync options placement 2016-03-01 20:11:38 +01:00
deajan
18f530ce0c Raised soft exec time for RotateCopies 2016-03-01 19:35:40 +01:00
deajan
6712fc6cc7 Moved rsync patterns from obackup to ofunctions 2016-02-21 11:13:23 +01:00
deajan
42a86c116d Typo fixing and shellcheck pass 2016-02-19 22:14:13 +01:00
deajan
0096fe81c8 Minor adapts from osync 2016-02-16 21:09:57 +01:00
deajan
56f7c07e56 Improved upgrade script 2016-02-11 14:08:31 +01:00
deajan
94eee06616 Better upgrade script 2016-02-08 13:28:25 +01:00
deajan
5ddec503dc Improved upgrade script 2015-12-15 14:08:54 +01:00
deajan
d1c5de13de Fixed subject in sendmail 2015-11-30 14:49:19 +01:00
deajan
d584149e39 Added missing global config file value 2015-11-28 12:48:40 +01:00
deajan
6cd1815ed9 Added include patterns to backup 2015-11-28 12:48:19 +01:00
deajan
a95c37e67f Replaced missing symlink 2015-11-22 14:40:04 +01:00
deajan
954606b8ba Fixed bogus directory creation in some backup cases 2015-11-21 13:22:14 +01:00
deajan
61a70b1ba5 Fixed ofunctions.sh path 2015-11-19 23:05:59 +01:00
deajan
4b2b99d016 Revert "Fixed ofunctions path"
This reverts commit 896eb0b650.
2015-11-19 23:04:02 +01:00
deajan
896eb0b650 Fixed ofunctions path 2015-11-19 23:03:18 +01:00
deajan
cdf6ca15ec Conf file should not be executable 2015-11-19 22:16:22 +01:00
deajan
da043ed3ae Added remote dir creation before file backup. 2015-11-19 22:14:15 +01:00
deajan
60b3d4674e Moved config value to remote options 2015-11-18 13:31:02 +01:00
deajan
213b2de002 Fixed sudo not necessary on local commands 2015-11-18 10:52:43 +01:00
deajan
882bfd276e Added config file upgrade script to v2 2015-11-16 13:37:26 +01:00
deajan
013fbdf000 Added file / sql backup rotation distinction 2015-11-16 12:52:15 +01:00
deajan
541119dda2 Removed debug lines from config file 2015-11-15 14:50:41 +01:00
deajan
87dd950199 Fixed wrong file size detection 2015-11-15 14:47:20 +01:00
deajan
3b17f127cf Fixed remote rotation for filenames containing spaces 2015-11-15 12:20:42 +01:00
deajan
197f3036d1 Initial v2.0 upload 2015-11-12 01:26:38 +01:00
deajan
4038cd5c8f Fixing small typosé 2015-10-13 15:22:50 +02:00
deajan
1fa695e3b0 KillChild function works on Linux,bsd,macos 2015-09-15 12:56:41 +02:00
deajan
62600fff39 Added new killtree function 2015-09-14 11:20:01 +02:00
deajan
6dd92b03f8 Fixed wrong config entry in host_backup.conf 2015-09-08 10:19:05 +02:00
deajan
6326144ee4 Fixed backup size warning message when backup size ignored 2015-09-06 23:16:34 +02:00
deajan
00cefd010e Fixed nomaxtime not honored 2015-09-06 17:23:19 +02:00
deajan
1e13d259cb Added error log highlighting 2015-08-30 17:06:43 +02:00
deajan
b04891b6c7 Improved some logging 2015-08-26 00:40:23 +02:00
deajan
fb310b1026 Reverted commands for obackup 2015-08-25 15:57:05 +02:00
deajan
c00a00525c Another quick fix comming from osync 2015-08-25 15:41:00 +02:00
deajan
2080da1565 Backported some minor stuff from osync 2015-08-25 15:26:36 +02:00
deajan
48c1ef4140 QaD hack to get full last run log in SendEmail 2015-06-02 11:05:45 +02:00
deajan
5b7b9b0e28 Improved obackup-batch.sh for crontab execution 2015-04-26 22:28:56 +02:00
deajan
dfeccbdf43 Half reverted GetCommandlineArguments placement 2015-04-24 23:41:01 +02:00
deajan
d3985716d8 Updated conf file for backup size test 2015-04-24 22:34:38 +02:00
deajan
ac20502b3e Moved command line args after config file for overriding 2015-04-24 22:31:39 +02:00
deajan
4ee08d0814 Added conf file equivalent for --dontgetsize 2015-04-24 21:52:40 +02:00
deajan
ee5a770e18 Added some scripts from osync project 2015-04-24 21:23:04 +02:00
deajan
b687ba0629 Added obackup-batch.sh script 2015-04-24 21:19:30 +02:00
deajan
6f467a05b0 Forgot to set keep_logging back to a normal value after tests 2015-04-20 14:12:24 +02:00
deajan
37c0f956ea Added ignore backup size option and a cosmetic fix 2015-04-20 14:07:45 +02:00
deajan
a96707d17c Backported some fixes from Osync 2015-04-03 12:21:33 +02:00
deajan
45633d1362 Prevent exclude pattern wildcard globbing 2015-02-12 11:46:54 +01:00
deajan
2c87aee183 Fixed some more typos. Should not code at night, really 2015-01-08 20:05:58 +01:00
deajan
03e0ec4654 Fixed another horrible typo 2015-01-08 18:57:00 +01:00
deajan
9b0e673ee0 Fixing the horrible typo 2015-01-08 18:52:19 +01:00
deajan
dd9d3dc982 Added --delete option for backups 2015-01-08 17:16:57 +01:00
deajan
7c9f3f4d73 Improved mysql dry backup and corrected mysql compress ratio 2014-12-21 22:28:05 +01:00
deajan
c2b64d9479 Revert "Fixed sql dry mode output and compression level"
This reverts commit 7ee1872718.
2014-12-21 22:18:50 +01:00
deajan
7ee1872718 Fixed sql dry mode output and compression level 2014-12-21 22:12:47 +01:00
deajan
ec7140e963 Improved some output 2014-11-28 14:56:53 +01:00
deajan
4662627a4a Quick doc update 2014-11-28 13:20:21 +01:00
deajan
6b11e2be69 Updated doc and other minor fixes 2014-11-28 13:15:49 +01:00
deajan
dc784a2671 Backup files and directories reffered by symlinks 2014-11-27 15:35:56 +01:00
deajan
e828519c32 Small fixes for dry mode 2014-11-27 14:40:30 +01:00
deajan
f7c896bd53 Fixed process test cmd gets expanded too soon 2014-11-24 19:30:20 +01:00
deajan
73c0191db6 Added rsync exclude list support from osync 2014-11-24 10:28:23 +01:00
deajan
efefe2df19 Another fix for symlinks to dirs on target 2014-11-19 17:20:49 +01:00
deajan
b0e7770df2 Fixed rsync -E option should not be mandatory 2014-11-19 09:36:30 +01:00
deajan
7bdf7e0939 Fix for symlinks to directories on target can't get updated 2014-11-18 14:43:04 +01:00
deajan
e18a4ad816 Merged osync codebase 2014-09-22 22:45:18 +02:00
deajan
c317e37601 Minor enhancements 2014-03-23 21:59:13 +01:00
deajan
385c45c46f changelog upload 2014-03-23 17:48:22 +01:00
deajan
bd9664a6ec Minor fixes 2014-03-23 17:46:08 +01:00
Orsiris de Jong
4b212311ff Fixed recursive directory exclude and remote os detection 2013-11-19 16:38:10 +01:00
deajan
d963c02c06 Some minor bugfixes 2013-11-16 12:44:21 +01:00
16 changed files with 8862 additions and 1312 deletions

View File

@@ -1,14 +1,3 @@
SHORT FUTURE IMPROVEMENTS
-------------------------
- Rewrite rsync exclude patterns using \"pattern\" instead of escaped chars
- Clean most of recursive task creation code
FAR FUTURE IMPROVEMENTS
-----------------------
- (Secret world domination... Still need to get bald and get a cat)
KNOWN ISSUES
------------
@@ -19,6 +8,96 @@ KNOWN ISSUES
CHANGELOG
---------
README: FreeBSD execution needs mailer (not found), sudo missing, bash needed, sed missing (see if StripQuotes mandatory)
XX xxx 2016: obackup v2.0.1 released
- Fixed double RunAfterHook launch
06 Aug 2016: obackup v2.0 released
- Made logging begin before remote checks for sanity purposes
- RunAfterCommands can get executed when trapquit
- Improved process killing and process time control
- Added optional statistics for installer
- Added an option to ignore knownhosts for ssh connections (use with caution, this can lead to a security issue)
- Improved mail fallback
- More logging enhancements
- Improved upgrade script
- Revamped rsync patterns to allow include and exclude patterns
- Better SQL and file backup task separation (rotate copies and warnings are defined for sql and/or file)
- Added reverse backup, now backups can be local, pushed or pulled to or from a remote system
- Better fallback for SendAlert even if disk full
- Added an alert email sent on warnings while backup script is running
- Way better logging of errors in _GetDirectoriesSizeX, _BackupDatabaseX, _CreateStorageDirectoriesX
- Added bogus config file checks & environment checks
- Full code refactoring to use local and remote code once
- Fully merged codebase with osync
- Added (much) more verbose debugging (and possibility to remove debug code to gain speed)
- Replace child_pid by $? directly, add a better sub process killer in TrapQuit
- Added some automatic checks in code, for _DEBUG mode (and _PARANOIA_DEBUG now)
- Improved Logging
- Updated obackup to be fully compliant with coding style
- Fixed creation of bogus subdirectories in some cases
- A long list of minor improvements and bug fixes
v0-1.x - Jan 2013 - Oct 2015
- New function to kill child processes
- Fixed no_maxtime not honored
- Improved some logging, also added highlighting to stdout errors
- Backported some fixes from Osync
- Small improvements on install script
- Copy ssh_filter.sh from osync project
- Small improvements in obackup-batch.sh time management
- Quick and dirty hack to get the full last run log in SendAlert email
- Added detection of obackup.sh script in obackup-batch.sh to overcome mising path in crontab
- Moved command line arguments after config file load for allowing command line overrides
- Added a config file option equivalent to --dontgetsize
- Added basic install script from osync project
- Added obackup-batch.sh from osync project to rerun failed backups in row
- Delta copy algorithm is now used even for local copies (usefull for network drives), this can be overriden in config file
- Added --dontgetsize parameter to backup huge systems immediatly
- Fixed multiple keep logging messages since sleep time between commands has been lowered under a second
- Create local subdirectories if not exist before running rsync (rsync doesn't handle mkdir -p)
- Backported some fixes from Osync
- Lowered sleep time between commands
- Lowered debug sleep times
- Fixed a bug with exclude pattern globbing preventing multiple exludes
- Lowered default compression level for email alerts (for low end systems)
- Prevent exclude pattern globbing before the pattern reaches the rsync cmd
- Fixed some typos with ported code from osync rendering stats and partial downloads unusable
- Added delete on destination option for files that vanished from source
- Fixed ignoring compression level in conf file
- Added experimental partial downloads support for rsync so big files can be resumed on slow links
- Fixed dry mode sql backup output
- Prevented triggering TrapError if there are no child processes to terminate on TrapQuit
- Improved mysql debug logs
- Prevent creation of backup-id less log file when DEBUG is set
- WARNING: Default behavior is now to copy the referrent files and directories from symlinks (this can reach files outside the backup root)
- Recursive directory search now includes symlinks (find -L option. -type d cannot be replaced by -xtype d because of portability issues with BSD)
- Dry mode does not create target directories anymore
- Dry mode also tries mysqldumps now (check for error messages being logged)
- Added experimental partial download support
- Added Rsync exclude files suppport from osync
- Fixed another issue with existing symlinks to directories on target on non recursive backups
- Fixed remaining rsync -E option preventing obackup to work correctly on MacOS X
- Fixed an issue with existing symlinks to directories on target
- Prevent changed IFS to make ping commands fail
- Added RotateCopies execution time (spinner support)
- redirect stderr for mysqldump to catch problems
- Moved msys specific code to Init(Local|Remote)OSSettings except in TrapQuit that needs to work at any moment
- Added support for multithreaded gzip (if pigz is installed)
- Merged back changes from osync codebase
- Enhanced debugging
- Added language agnostic system command output
- Enhanced log sending
- Better handling of OS specific commands
- Improved WaitForTaskCompletion when DEBUG enabled or SILENT enabled
- Enhanced OS detection
- More correct error message on remote connection failure
- Gzipped logs are now deleted once sent
- Fixed some typos (thanks to Pavel Kiryukhin)
- Improved OS detection and added prelimnary MacOS X support
- Improved execution hook logs
- Improved RunLocalCommand execution hook
- 02 Nov. 2013: v1.84 RC3
- Updated documentation
- Minor rewrites in recursive backup code

147
CODING_STYLE.TXT Normal file
View File

@@ -0,0 +1,147 @@
Coding style used for my bash projects (v2.1 Oct 2015)
++++++ Header
Always use the following header
----BEGIN HEADER
#!/usr/bin/env bash
PROGRAM="program-name" # Long description
AUTHOR="(L) 20XX-20YY by Orsiris \"Ozy\" de Jong"
CONTACT="http://www.example.com me@example.com"
PROGRAM_BUILD=YYYYMMDDVV
## Optional instructions
----END HEADER
Using bind style versionning:
YYYYMMDDVV (Year, Month, Day, Revision): Example: 2015012402 = 2nd revision of 24 Jan 2015
#!/usr/bin/env bash instead of #!/bin/bash
Change old scripts with
for i in $(grep -r '#!/bin/bash' * |cut -f1 -d':'); do sed -i 's&#!/bin/bash&#!/usr/bin/env bash&g' $i; done
type instead of type -p for bash test (other shells don't know -p)
++++++ Indentation
Using tabs
Transform old shell scripts using unexpand command
++++++ Comments
Some command # comment
## Some comment on a new line
################################################# Some separation
++++++ Work comments
Whenever there is some idea to postpone, use #TODO[-version]:[dev-name:] some remark
A marker must be left where on the line a dev is working (when the work isn't finished). Marker is #WIP:dev-name: some remark
dev-name is mandatory if more than one person is coding
Example: #TODO-v2.1:deajan: need to do something
++++++ Variables
All local variables are lowercase, separated by _ (ex: low_wait)
All global variables full upercase, separated by _ (ex: EXEC_TIME)
All environment variables (verbose, silent, debug, etc) have prefix _ and are full upercase, separated by _ (ex: _PARANOIA_DEBUG)
++++++ Functions
Every word in a function begins with an uppercase (ex: SomeFunctionDoesThings)
Define functions this way. Use sed ':a;N;$!ba;s/\n{\n/ {\n/g' to adapt when opening bracket is on a new line.
function something {
}
If function has some arguments, use local variable names that are more readable than $1...$n. Explain via comments what those variables contain if needed.
function anotherthing {
local var_name="${1}"
local other_var_name="${2}" # This variable contains stuff
}
Functions should always have return status
function thirdthing {
some_command
return $?
}
++++++ Sub functions
When a function is a subroutine of another function, it is called _SomethingAsSubFunction
++++++ Function argument check
Bash does not provide any checks against missing function arguments. Also, missing quotes can lead to an inconsistent number of arguments.
Every function call will be checked by __CheckArguments which takes the number of arguments, $# (the real number of args given), the parent function name and the parent function's arguments.
__CheckArguments will trigger a critical error if number of arguments if incorrect. This will also prevent silent typo errors.
Ex:
function Something {
local some="${1}"
local other="${2}"
local args="${3}"
__CheckArguments 3 $# $FUNCNAME "$*"
__CheckArguments will only trigger if script is called with DEBUG=yes
Also, with PARANOIA_DEBUG=yes, __CheckArguments will recount all arguments given by "$*" and compare. This can mislead if arguments contain spaces.
++++++ If statements
If statements will be fully written (word "if" must be used). then is written on the same line.
(Use sed ':a;N;$!ba;s/]\n\t*then/]; then/g' to convert files to this format... Replace "],new line, zero or more tabs, then" by "; then")
if [ something ]; then
stuff
else
other stuff
fi
++++++ Logging
A logging function is available with the following levels of logging:
- DEBUG: Only log this when DEBUG flas is set in program. Any command forged for eval should be logged by this.
- NOTICE: Standard messages
- WARN: Requires attention
- ERROR: Program produced an error but continues execution
- CRITICAL: Program execution is halted
++++++ Eval
Most commands should be logged to a tmp file.
The basic way of doing is:
cmd='"something '$somevar'" > some_file 2>&1'
eval $cmd &
WaitForTaskCompletion $! 0 0 $FUNCNAME
Remote commands should exist as:
cmd=$SSH_CMD' "some; commands \"'$VARIABLE'\" some; other; commands" > some_file 2>&1'
++++++ File variables
All eval cmd should exit their content to a file called "$RUNDIR/osync.$FUNCNAME.$SCRIPT_PID"
Dots are used instead of '_' so variables can be separated with a forbidden char in variables, so they get detected.
++++++ Finding code errors
Use shellcheck.net now and then (ignore SC2086 in our case)
Use a low tech approach to find uneven number of quotes per line
tr -cd "'\n" < my_bash_file.sh | awk 'length%2==1 {print NR, $0}'
tr -cd "\"\n" < my_bash_file.sh | awk 'length%2==1 {print NR, $0}'
++++++ ofunctions
As obackup and osync share alot of common functions, ofunctions.sh will host all shared code.
Dev programs n_osync.sh and n_obackup.sh will source ofunctions.sh
Release programs will still include ofunctions.sh in order to enhance ease of use.

View File

@@ -1,4 +1,4 @@
Copyright (c) 2013, Orsiris "Ozy" de Jong. ozy@netpower.fr
Copyright (c) 2013-2016, Orsiris "Ozy" de Jong. ozy@netpower.fr
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,12 +1,11 @@
obackup
=======
A small robust file & database backup script for local to local or remote to local backups via ssh.
Works especially well for multiple virtualhost backups with 'backup divide task' functionnality.
A robust file & database backup script that works for local and remote push or pull backups via ssh.
## About
OBackup is designed from ground to make the backup process as reliable as possible.
obackup is designed to make the backup process as reliable as possible.
It divides the whole backup process into tasks, allowing each task to execute for a certain amount of time.
If a task doesn't finish in time, it's stopped and the next task in list is processed.
Before a task gets stopped, a first warning message is generated telling the task takes too long.
@@ -14,28 +13,32 @@ Every action gets logged, and if a warning has been generated, a task gets stopp
Remote backups are initiated from the backup server instead of the production server, so hacked servers won't get ssh access to the backup server.
OBackup can enumerate and backup all MariaDB / MySQL databases present on a server.
obackup can enumerate and backup all MariaDB / MySQL databases present on a server.
It can also enumarate all subdirectories of a given path and process them as separate tasks (usefull for multiple vhosts).
It will do several checks before launching a backup like execution checks, dryruns, checking backup size and available local disk space.
Obackup can execute local and remote commands before and after backup execution,
obackup can execute local and remote commands before and after backup execution,
thus providing an easy way to handle snapshots (see https://github.com/deajan/zsnap for a zfs snapshot management script).
It may also rotate backups for you.
As of today, obackup has been tested successfully on RHEL / CentOS 5, CentOS 6, Debian 6.0.7 and Linux Mint 14.
Currently, Obackup also runs on FreeBSD and Windows MSYS environment, altough it is not fully tested yet.
As of today, obackup has been tested successfully on RHEL / CentOS 5, 6 and 7, Debian 6 and 7, Linux Mint 14 and 17, FreeBSD 8.3 and 10.3.
Currently, obackup also runs on MacOSX and Windows MSYS environment.
Feel free to drop me a mail for limited support in my free time.
## Warning
Obackup now follows symlinks and treats them as the referent files / dirs, following symlinks even outside the backup root, which IMHO is more secure in terms of backups.
You may disable this behavior in the config file.
## Installation
You can download the latest obackup script from authors website.
You may also clone the following git which will maybe have some more recent builds.
$ git clone git://github.com/deajan/obackup.git
$ chmod +x ./obackup.sh
$ git clone -b "v2.0-maint" git://github.com/deajan/obackup.git
$ cd obackup
$ ./install.sh
Obackup needs to run with bash shell, using any other shell will most probably fail.
obackup needs to run with bash shell, using any other shell will most probably fail.
Once you have grabbed a copy, just edit the config file with your favorite text editor to setup your environment and you're ready to run.
A detailled documentation can be found on the author's site.
You can run multiple instances of obackup scripts with different backup environments. Just create another configuration file,
@@ -64,10 +67,12 @@ that's actually launched and it's result.
One you're happy with a test run, you may run obackup as a cron task with the "--silent" parameter so output will not be written to stdout.
All backup activity is logged to "/var/log/obackup_backupname.log" or current directory if /var/log is not writable.
You may mix "--silent" and "--verbose" parameters to output verbose input only in the log files.
## Final words
Backup tasks aren't always reliable, connectivity loss, insufficient disk space, hacked servers with tons of unusefull stuff to backup... Anything can happen.
Obackup will sent your a warning email for every issue it can handle.
obackup will sent your a warning email for every issue it can handle.
Nevertheless, you should assure yourself that your backup tasks will get done the way you meant it. Also, a backup isn't valuable until you're sure
you can successfully restore. Try to restore your backups to check whether everything is okay. Backups will keep file permissions and owners,
but may loose ACLs if destination file system won't handle them.
@@ -75,7 +80,4 @@ but may loose ACLs if destination file system won't handle them.
## Author
Feel free to mail me for limited support in my free time :)
Orsiris "Ozy" de Jong | ozy@netpower.fr
Orsiris de Jong | ozy@netpower.fr

2645
dev/debug_obackup.sh Executable file

File diff suppressed because it is too large Load Diff

71
dev/merge.sh Executable file
View File

@@ -0,0 +1,71 @@
#!/usr/bin/env bash
## MERGE 2016080601
## Merges ofunctions.sh and n_program.sh into program.sh
## Adds installer
PROGRAM=obackup
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
VERSION=${VERSION#*=}
PARANOIA_DEBUG_LINE="__WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
MINIMUM_FUNCTION_BEGIN="#### MINIMAL-FUNCTION-SET BEGIN ####"
MINIMUM_FUNCTION_END="#### MINIMAL-FUNCTION-SET END ####"
function Unexpand {
unexpand n_$PROGRAM.sh > tmp_$PROGRAM.sh
}
function MergeAll {
sed "/source \"\.\/ofunctions.sh\"/r ofunctions.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' > debug_$PROGRAM.sh
chmod +x debug_$PROGRAM.sh
}
function MergeMinimum {
sed -n "/$MINIMUM_FUNCTION_BEGIN/,/$MINIMUM_FUNCTION_END/p" ofunctions.sh > tmp_minimal.sh
sed "/source \"\.\/ofunctions.sh\"/r tmp_minimal.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' | grep -v "$PARANOIA_DEBUG_LINE" > debug_$PROGRAM.sh
rm -f tmp_minimal.sh
chmod +x debug_$PROGRAM.sh
}
function CleanDebug {
# sed explanation
#/pattern1/{ # if pattern1 is found
# p # print it
# :a # loop
# N # and accumulate lines
# /pattern2/!ba # until pattern2 is found
# s/.*\n// # delete the part before pattern2
#}
#p
sed -n '/'$PARANOIA_DEBUG_BEGIN'/{p; :a; N; /'$PARANOIA_DEBUG_END'/!ba; s/.*\n//}; p' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
chmod +x ../$PROGRAM.sh
}
function CopyCommons {
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
if [ -f "common_batch.sh" ]; then
sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh
fi
chmod +x ../install.sh
chmod +x ../$PROGRAM-batch.sh
rm -f ../tmp_install.sh
}
Unexpand
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then
MergeAll
else
MergeMinimum
fi
CleanDebug
CopyCommons
rm -f tmp_$PROGRAM.sh

1399
dev/n_obackup.sh Executable file

File diff suppressed because it is too large Load Diff

1247
dev/ofunctions.sh Normal file

File diff suppressed because it is too large Load Diff

7
exclude.list.example Normal file
View File

@@ -0,0 +1,7 @@
.AppleDouble/
._*
.DS_Store
Thumbs.db
System Volume Information
$Recycle.Bin

View File

@@ -1,163 +0,0 @@
#!/bin/bash
###### Remote (or local) backup script for files & databases
###### (L) 2013 by Ozy de Jong (www.netpower.fr)
###### Config file rev 0211201301
## ---------- GENERAL BACKUP OPTIONS
## Backup identification name.
BACKUP_ID="your backup name"
## Log file location. Leaving this empty will create log file at /var/log/obackup_version_BACKUP_ID.log (or current directory if /var/log doesn't exist)
LOGFILE=""
## Backup databases
BACKUP_SQL=no
## Backup files
BACKUP_FILES=yes
## ---------- LOCAL BACKUP STORAGE OPTIONS
## Local storage paths where to put backups
LOCAL_SQL_STORAGE="/home/storage/backup/sql"
LOCAL_FILE_STORAGE="/home/storage/backup/files"
## Create backup directories if they do not exist
CREATE_DIRS=yes
## Keep absolute source path in your backup, eg: /your/backup/storage/the/remote/server/files
## You should leave this enabled if you intend to use 'backup task division' functionality of OBackup, or everything will end up in the same directory.
LOCAL_STORAGE_KEEP_ABSOLUTE_PATHS=yes
## Generate an alert if backup size is lower than given value in Kb (this can also help identifying empty mount dirs)
BACKUP_SIZE_MINIMUM=1024
## Generate an alert if local storage free space is lower than given value in Kb.
LOCAL_STORAGE_WARN_MIN_SPACE=1048576
## ---------- MISC OPTIONS
## Bandwidth limit Kbytes / second for file backups. Leave 0 to disable limitation.
BANDWIDTH=0
## If enabled, file backups will be processed as superuser. See documentation for /etc/sudoers configuration ("find", "du" and "rsync" need to be allowed). Requiretty needs to be disabled.
SUDO_EXEC=no
## Paranoia option. Don't change this unless you read the documentation.
RSYNC_EXECUTABLE=rsync
## ---------- REMOTE BACKUP OPTIONS
## The following options allow this Obackup instance to connect to a remote system via an ssh tunnel.
## Needs public RSA key need to be put into ~/.ssh/authorized_keys in remote users home directory.
REMOTE_BACKUP=no
SSH_RSA_PRIVATE_KEY=~/.ssh/id_rsa
REMOTE_USER=backupuser
REMOTE_HOST=yourhost.local
REMOTE_PORT=22
## ssh compression should be used unless your remote connection is good enough (LAN)
SSH_COMPRESSION=yes
## Remote rsync executable path. Leave this empty in most cases
REMOTE_RSYNC_PATH=""
## Check for connectivity to remote host before launching remote backup tasks. Be sure the hosts responds to ping. Failing to ping will skip current task.
REMOTE_HOST_PING=yes
## Check for internet access by pinging one or more 3rd party hosts before remote backup tasks. Leave empty if you don't want this check to be be performed. Failing to ping will skip current task.
REMOTE_3RD_PARTY_HOSTS="www.kernel.org www.google.com"
## ---------- DATABASE BACKUP OPTIONS
## Database backup user
SQL_USER=backupuser
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exlude list.
## Every found database will be backed up as separate backup task.
DATABASES_ALL=yes
DATABASES_ALL_EXCLUDE_LIST="test;mysql"
## Alternatively, if DATABASES_ALL=no, you can specifiy a list of databases to backup separated by spaces.
DATABASES_LIST=""
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max ecec time generates a warning and stops current backup task.
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
SOFT_MAX_EXEC_TIME_DB_TASK=3600
HARD_MAX_EXEC_TIME_DB_TASK=7200
## Preferred SQL dump compression. Can be set to xz, lzma or gzip.
## Generally, xz level 5 is a good compromise between cpu, memory hunger and compress ratio. Gzipped files are set to be rsyncable.
COMPRESSION_PROGRAM=xz
COMPRESSION_LEVEL=3
## SQL Dump compression should be done on remote side but can also be done locally to lower remote system usage (will take more bandwidth, check for ssh compression)
COMPRESSION_REMOTE=yes
## ---------- FILES BACKUP OPTIONS
## Directories backup list. List of semicolon separated directories that will be backed up recursively. Every directory will be processed as one backup task.
DIRECTORIES_SIMPLE_LIST="/var/named;/var/lib"
## There's a special backup schema in Obackup called 'backup task division' which creates one backup task per level 1 subdirectory of a directory.
## This is VERY usefull to backup multiple virtualhosts as separate tasks without having to specifiy each one separately.
## This may also be usefull dividing big data directories in subdirectories tasks.
## Directories backup task division backup: Semicolon separated directories of which every level 1 subdirectory will be backed up recursively as a spearate backup task.
## Example: "/home;/var" will create tasks "/home/dir1", "/home/dir2", ... "/home/dirN", "/var/log", "/var/lib"... "/var/whatever"
DIRECTORIES_RECURSE_LIST="/home"
## You may optionally exclude subdirectories from task division. On the above example you could exclude /home/dir2 by adding it to DIRECTORIES_RECURSE_EXCLUDE_LIST
DIRECTORIES_RECURSE_EXCLUDE_LIST="/home/backupuser;/home/lost+found"
## Rsync exclude patterns, used by simple and division lists
RSYNC_EXCLUDE_PATTERN="*/tmp;*/ftp/www/cache/cachefs;*/sessions"
## List separator char. You may set an alternative seperator char for your directories lists above.
PATH_SEPARATOR_CHAR=";"
## Preserve ACLS. Make sure source and target FS can hold same ACLs or you'll get loads of errors.
PRESERVE_ACL=no
## Preserve Xattr. MAke sure source and target FS can hold same Xattr or you'll get loads of errors.
PRESERVE_XATTR=no
## Let RSYNC compress file transfers. Do not use this on local-local backup schemes. Also, this is not usefull if SSH compression is enabled.
RSYNC_COMPRESS=no
## Max execution time per file backup task. Soft is warning only. Hard is warning, stopping backup and processing next one one file list. Tilme is specified in seconds
SOFT_MAX_EXEC_TIME_FILE_TASK=3600
HARD_MAX_EXEC_TIME_FILE_TASK=7200
## ---------- ALERT OPTIONS
## Alert email adresses separated by a space character
DESTINATION_MAILS="your@mail.address"
## Windows (MSYS environment) only mail options (used by sendemail.exe)
SENDER_MAIL="alert@your.system"
SMTP_SERVER=smtp.your.isp.com
SMTP_USER=
SMTP_PASSWORD=
## ---------- GENERAL BACKUP OPTIONS
## Max execution time of whole backup process. Soft max exec time generates a warning only.
## Hard max exec time generates a warning and stops the whole backup execution.
SOFT_MAX_EXEC_TIME_TOTAL=30000
HARD_MAX_EXEC_TIME_TOTAL=36000
## Backup Rotation. You may rotate backups if you don't use snapshots on your backup server.
ROTATE_BACKUPS=no
ROTATE_COPIES=7
## ---------- EXECUTION HOOKS
## Commands can will be run before and / or after backup execution (remote execution will only happen if REMOTE_BACKUP is set).
## This is usefull to make a snapshot before backing up data, or even handle snapshots of backed up data.
LOCAL_RUN_BEFORE_CMD=""
LOCAL_RUN_AFTER_CMD=""
REMOTE_RUN_BEFORE_CMD=""
REMOTE_RUN_AFTER_CMD=""
## Max execution time of commands before they get force killed. Leave 0 if you don't wan't this to happen. Time is specified in seconds.
MAX_EXEC_TIME_PER_CMD_BEFORE=0
MAX_EXEC_TIME_PER_CMD_AFTER=0
## Stops whole backup execution if one of the above commands fail
STOP_ON_CMD_ERROR=no

208
host_backup.conf.example Normal file
View File

@@ -0,0 +1,208 @@
#!/usr/bin/env bash
###### obackup - Local or Remote, push or pull backup script for files & mysql databases
###### (C) 2013-2016 by Orsiris de Jong (www.netpower.fr)
###### obackup v2.x config file rev 2016052501
###### GENERAL BACKUP OPTIONS
## Backup identification string.
INSTANCE_ID="test-backup"
## Log file location. Leaving this empty will create log file at /var/log/obackup.INSTANCE_ID.log (or current directory if /var/log doesn't exist).
LOGFILE=""
## Elements to backup
SQL_BACKUP=yes
FILE_BACKUP=yes
## Backups can be done local, pulled from another server or pushed to a backup server. Available options are [local,pull,push].
## Pulled backups are the safest option, as the backup server contains the RSA key and cannot be compromised by another server.
BACKUP_TYPE=local
###### BACKUP STORAGE
## Storage paths of the backups (absolute paths of the local or remote system)
SQL_STORAGE="/home/storage/backup/sql"
FILE_STORAGE="/home/storage/backup/files"
## Backup encryption using GPG and duplicity. Feature not ready yet.
ENCRYPTION=no
## Create backup directories if they do not exist
CREATE_DIRS=yes
## Keep absolute source path in your backup, eg: /your/backup/storage/the/remote/server/files
## You should leave this enabled if you intend to use 'backup task division' functionality of oBackup, or everything will end up in the same directory.
KEEP_ABSOLUTE_PATHS=yes
## Generate an alert if backup size is lower than given value in Kb (this can also help identifying empty mount dirs).
BACKUP_SIZE_MINIMUM=1024
## Check backup size before proceeding
GET_BACKUP_SIZE=yes
## Generate an alert if storage free space is lower than given value in Kb.
## Keep in mind that disabling backup file size test will only test min space against SQL backup size.
SQL_WARN_MIN_SPACE=1048576
FILE_WARN_MIN_SPACE=1048576
###### REMOTE ONLY OPTIONS
## In case of pulled or pushed backups, remote system URI needs to be supplied.
REMOTE_SYSTEM_URI="ssh://backupuser@remote.system.tld:22/"
## You can specify a RSA key (please use full path). If not defined, the default ~/.ssh/id_rsa will be used. See documentation for further information.
SSH_RSA_PRIVATE_KEY="/root/.ssh/id_rsa"
## ssh compression should be used unless your remote connection is good enough (LAN)
SSH_COMPRESSION=yes
## Ignore ssh known hosts verification. DANGER WILL ROBINSON DANGER: This can lead to security risks. Only enable if you know what you're doing.
SSH_IGNORE_KNOWN_HOSTS=no
## Remote rsync executable path. Leave this empty in most cases
RSYNC_REMOTE_PATH=""
## Check for connectivity to remote host before launching remote backup tasks. Be sure the hosts responds to ping. Failing to ping will skip current task.
REMOTE_HOST_PING=yes
## Check for internet access by pinging one or more 3rd party hosts before remote backup tasks. Leave empty if you don't want this check to be be performed. Failing to ping will skip current task.
REMOTE_3RD_PARTY_HOSTS="www.kernel.org www.google.com"
## If enabled, commands will be executed as superuser on remote side. See documentation for /etc/sudoers configuration ("find", "du", "tee" and "rsync" need to be allowed). Requiretty needs to be disabled.
SUDO_EXEC=no
###### DATABASE SPECIFIC OPTIONS
## Database backup user
SQL_USER=backupuser
## Enabling the following option will save all databases on local or remote given SQL instance except the ones specified in the exclude list.
## Every found database will be backed up as separate backup task.
DATABASES_ALL=yes
DATABASES_ALL_EXCLUDE_LIST="test"
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
#DATABASES_LIST="somedatabase"
## Max backup execution time per Database task. Soft max exec time generates a warning only. Hard max exec time generates a warning and stops current backup task.
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
SOFT_MAX_EXEC_TIME_DB_TASK=3600
HARD_MAX_EXEC_TIME_DB_TASK=7200
## Preferred SQL dump compression. Compression methods can be xz, lzma, pigz or gzip (will fallback from xz to gzip depending if available)
## Generally, level 5 is a good compromise between cpu, memory hunger and compress ratio. Gzipped files are set to be rsyncable.
COMPRESSION_LEVEL=3
###### FILES SPECIFIC OPTIONS
## File backups are divided in tasks. Every directory in DIRECTORY_LIST will be processed as a unique task.
## Every subdirectory of each directory in RECURSIVE_DIRECTORY_LIST will be processed as a unique task.
## Example: RECURSIVE_DIRECTORY_LIST="/home;/var" will create backup tasks tasks "/home/dir1, "/home/dir2", ... "/home/dirN", "/var/log", "/var/lib"... "/var/something".
## You can exclude directories from the avove backup task creation, ex: avoid backing up "/home/dir2" by adding it to RECURSIVE_EXCLUDE_LIST.
## Directories backup list. List of semicolon separated directories that will be backed up.
DIRECTORY_LIST="/var/named"
RECURSIVE_DIRECTORY_LIST="/home"
RECURSIVE_EXCLUDE_LIST="/home/backupuser;/home/lost+found"
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
RSYNC_PATTERN_FIRST=include
## List of files / directories to incldue / exclude from sync on both sides (see rsync patterns, wildcards work).
## Paths are relative to sync dirs. List elements are separated by a semicolon.
RSYNC_INCLUDE_PATTERN=""
RSYNC_EXCLUDE_PATTERN=""
#RSYNC_EXCLUDE_PATTERN="tmp;archives"
## Files that contains lists of files / directories to include / exclude from sync on both sides. Leave this empty if you don't want to use an exclusion file.
## This file has to be in the same directory as the config file
## Paths are relative to sync dirs. One element per line.
RSYNC_INCLUDE_FROM=""
RSYNC_EXCLUDE_FROM=""
#RSYNC_EXCLUDE_FROM="exclude.list"
## List separator char. You may set an alternative separator char for your directories lists above.
PATH_SEPARATOR_CHAR=";"
## Preserve ACLS. Make sure source and target FS can hold same ACLs or you'll get loads of errors.
PRESERVE_ACL=no
## Preserve Xattr. MAke sure source and target FS can hold same Xattr or you'll get loads of errors.
PRESERVE_XATTR=no
## Transforms symlinks into referent files/dirs
COPY_SYMLINKS=yes
## Treat symlinked dirs as dirs. CAUTION: This also follows symlinks outside of the replica root.
KEEP_DIRLINKS=yes
## Preserve hard links. Make sure source and target FS can manage hard links or you will lose them.
PRESERVE_HARDLINKS=no
## Let RSYNC compress file transfers. Do not use this on local-local backup schemes. Also, this is not useful if SSH compression is enabled.
RSYNC_COMPRESS=no
## Max execution time per file backup task. Soft is warning only. Hard is warning, stopping backup and processing next one one file list. Tilme is specified in seconds
SOFT_MAX_EXEC_TIME_FILE_TASK=3600
HARD_MAX_EXEC_TIME_FILE_TASK=7200
## Keep partial uploads that can be resumed on next run, experimental feature
PARTIAL=no
## Delete files on destination that vanished from source. Do not turn this on unless you enabled backup rotation or a snapshotting FS like zfs to keep those vanished files on the destination.
DELETE_VANISHED_FILES=no
## Use delta copy algortithm (usefull when local paths are network drives), defaults to yes
DELTA_COPIES=yes
## Bandwidth limit Kbytes / second for file backups. Leave 0 to disable limitation.
BANDWIDTH=0
## Paranoia option. Don't change this unless you read the documentation.
RSYNC_EXECUTABLE=rsync
###### ALERT OPTIONS
## Alert email addresses separated by a space character
DESTINATION_MAILS="your@mail.address"
## Windows specific (msys / cygwin environment) only mail options (used with mailsend.exe from muquit, http://github.com/muquit/mailsend or from sendemail.exe from Brandon Zehm, http://caspian.dotconf.net/menu/Software/SendEmail/
SENDER_MAIL="alert@your.system.tld"
SMTP_SERVER=smtp.your.isp.tld
SMTP_PORT=25
# encryption can be tls, ssl or none
SMTP_ENCRYPTION=none
SMTP_USER=
SMTP_PASSWORD=
###### GENERAL BACKUP OPTIONS
## Max execution time of whole backup process. Soft max exec time generates a warning only.
## Hard max exec time generates a warning and stops the whole backup execution.
SOFT_MAX_EXEC_TIME_TOTAL=30000
HARD_MAX_EXEC_TIME_TOTAL=36000
## Backup Rotation. You may rotate backups if you don't use snapshots on your backup server.
ROTATE_SQL_BACKUPS=no
ROTATE_SQL_COPIES=7
ROTATE_FILE_BACKUPS=no
ROTATE_FILE_COPIES=7
###### EXECUTION HOOKS
## Commands can will be run before and / or after backup execution (remote execution will only happen if REMOTE_BACKUP is set).
## This is useful to make a snapshot before backing up data, or even handle snapshots of backed up data.
LOCAL_RUN_BEFORE_CMD=""
LOCAL_RUN_AFTER_CMD=""
REMOTE_RUN_BEFORE_CMD=""
REMOTE_RUN_AFTER_CMD=""
## Max execution time of commands before they get force killed. Leave 0 if you don't want this to happen. Time is specified in seconds.
MAX_EXEC_TIME_PER_CMD_BEFORE=0
MAX_EXEC_TIME_PER_CMD_AFTER=0
## Stops whole backup execution if one of the above commands fail
STOP_ON_CMD_ERROR=no
## Run local and remote after backup cmd's even on failure
RUN_AFTER_CMD_ON_ERROR=no

311
install.sh Executable file
View File

@@ -0,0 +1,311 @@
#!/usr/bin/env bash
PROGRAM=obackup
PROGRAM_VERSION=2.0.1
PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2016052601
## osync / obackup / pmocr / zsnap install script
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10
## Please adapt this to fit your distro needs
#TODO: silent mode and no stats mode
CONF_DIR=/etc/$PROGRAM
BIN_DIR=/usr/local/bin
SERVICE_DIR_INIT=/etc/init.d
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
SERVICE_DIR_SYSTEMD_SYSTEM=/lib/systemd/system
SERVICE_DIR_SYSTEMD_USER=/etc/systemd/user
## osync specific code
OSYNC_SERVICE_FILE_INIT="osync-srv"
OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM="osync-srv@.service"
OSYNC_SERVICE_FILE_SYSTEMD_USER="osync-srv@.service.user"
## pmocr specfic code
PMOCR_SERVICE_FILE_INIT="pmocr-srv"
PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM="pmocr-srv.service"
## Generic code
## Default log file
if [ -w /var/log ]; then
LOG_FILE="/var/log/$PROGRAM-install.log"
elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then
LOG_FILE="$HOME/$PROGRAM-install.log"
else
LOG_FILE="./$PROGRAM-install.log"
fi
# Generic quick logging function
function _QuickLogger {
local value="${1}"
local destination="${2}" # Destination: stdout, log, both
if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then
echo -e "$(date) - $value" >> "$LOG_FILE"
elif ([ "$destination" == "stdout" ] || [ "$destination" == "both" ]); then
echo -e "$value"
fi
}
function QuickLogger {
local value="${1}"
if [ "$_SILENT" -eq 1 ]; then
_QuickLogger "$value" "log"
else
_QuickLogger "$value" "stdout"
fi
}
function urlencode() {
# urlencode <string>
local LANG=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
}
function SetOSSettings {
USER=root
local local_os_var
local_os_var="$(uname -spio 2>&1)"
if [ $? != 0 ]; then
local_os_var="$(uname -v 2>&1)"
if [ $? != 0 ]; then
local_os_var="$(uname)"
fi
fi
case $local_os_var in
*"BSD"*)
GROUP=wheel
;;
*"Darwin"*)
GROUP=admin
;;
*)
GROUP=root
;;
*"MINGW32"*|*"CYGWIN"*)
USER=""
GROUP=""
;;
esac
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ]); then
QuickLogger "Must be run as $USER."
exit 1
fi
OS=$(urlencode "$local_os_var")
}
function GetInit {
if [ -f /sbin/init ]; then
if file /sbin/init | grep systemd > /dev/null; then
init="systemd"
else
init="initV"
fi
else
QuickLogger "Can't detect initV or systemd. Service files won't be installed. You can still run $PROGRAM manually or via cron."
init="none"
fi
}
function CreateConfDir {
if [ ! -d "$CONF_DIR" ]; then
mkdir "$CONF_DIR"
if [ $? == 0 ]; then
QuickLogger "Created directory [$CONF_DIR]."
else
QuickLogger "Cannot create directory [$CONF_DIR]."
exit 1
fi
else
QuickLogger "Config directory [$CONF_DIR] exists."
fi
}
function CopyExampleFiles {
if [ -f "./sync.conf.example" ]; then
cp "./sync.conf.example" "/etc/$PROGRAM/sync.conf.example"
fi
if [ -f "./host_backup.conf.example" ]; then
cp "./host_backup.conf.example" "/etc/$PROGRAM/host_backup.conf.example"
fi
if [ -f "./exlude.list.example" ]; then
cp "./exclude.list.example" "/etc/$PROGRAM"
fi
if [ -f "./snapshot.conf.example" ]; then
cp "./snapshot.conf.example" "/etc/$PROGRAM/snapshot.conf.example"
fi
}
function CopyProgram {
cp "./$PROGRAM_BINARY" "$BIN_DIR"
if [ $? != 0 ]; then
QuickLogger "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]. Make sure to run install script in the directory containing all other files."
QuickLogger "Also make sure you have permissions to write to [$BIN_DIR]."
exit 1
else
chmod 755 "$BIN_DIR/$PROGRAM_BINARY"
QuickLogger "Copied $PROGRAM_BINARY to [$BIN_DIR]."
fi
if [ -f "./$PROGRAM_BATCH" ]; then
cp "./$PROGRAM_BATCH" "$BIN_DIR"
if [ $? != 0 ]; then
QuickLogger "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]."
else
chmod 755 "$BIN_DIR/$PROGRAM_BATCH"
QuickLogger "Copied $PROGRAM_BATCH to [$BIN_DIR]."
fi
fi
if [ -f "./ssh_filter.sh" ]; then
cp "./ssh_filter.sh" "$BIN_DIR"
if [ $? != 0 ]; then
QuickLogger "Cannot copy ssh_filter.sh to [$BIN_DIR]."
else
chmod 755 "$BIN_DIR/ssh_filter.sh"
if ([ "$USER" != "" ] && [ "$GROUP" != "" ]); then
chown $USER:$GROUP "$BIN_DIR/ssh_filter.sh"
fi
QuickLogger "Copied ssh_filter.sh to [$BIN_DIR]."
fi
fi
}
function CopyServiceFiles {
# OSYNC SPECIFIC
if ([ "$init" == "systemd" ] && [ -f "./$OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM" ]); then
cp "./$OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_SYSTEM" && cp "./$OSYNC_SERVICE_FILE_SYSTEMD_USER" "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_SYSTEM"
if [ $? != 0 ]; then
QuickLogger "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]."
else
QuickLogger "Created osync-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
QuickLogger "Can be activated with [systemctl start osync-srv@instance.conf] where instance.conf is the name of the config file in /etc/osync."
QuickLogger "Can be enabled on boot with [systemctl enable osync-srv@instance.conf]."
QuickLogger "In userland, active with [systemctl --user start osync-srv@instance.conf]."
fi
elif ([ "$init" == "initV" ] && [ -f "./$OSYNC_SERVICE_FILE_INIT" ]); then
cp "./$OSYNC_SERVICE_FILE_INIT" "$SERVICE_DIR_INIT"
if [ $? != 0 ]; then
QuickLogger "Cannot copy osync-srv to [$SERVICE_DIR_INIT]."
else
chmod 755 "$SERVICE_DIR_INIT/$OSYNC_SERVICE_FILE_INIT"
QuickLogger "Created osync-srv service in [$SERVICE_DIR_INIT]."
QuickLogger "Can be activated with [service $OSYNC_SERVICE_FILE_INIT start]."
QuickLogger "Can be enabled on boot with [chkconfig $OSYNC_SERVICE_FILE_INIT on]."
fi
fi
# PMOCR SPECIFIC
if ([ "$init" == "systemd" ] && [ -f "./$PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM" ]); then
cp "./$PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_SYSTEM"
if [ $? != 0 ]; then
QuickLogger "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]."
else
QuickLogger "Created pmocr-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
QuickLogger "Can be activated with [systemctl start pmocr-srv] after configuring file options in [$BIN_DIR/$PROGRAM]."
QuickLogger "Can be enabled on boot with [systemctl enable pmocr-srv]."
fi
elif ([ "$init" == "initV" ] && [ -f "./$PMOCR_SERVICE_FILE_INIT" ]); then
cp "./$PMOCR_SERVICE_FILE_INIT" "$SERVICE_DIR_INIT"
if [ $? != 0 ]; then
QuickLogger "Cannot copy pmoct-srv to [$SERVICE_DIR_INIT]."
else
chmod 755 "$SERVICE_DIR_INIT/$PMOCR_SERVICE_FILE_INIT"
QuickLogger "Created osync-srv service in [$SERVICE_DIR_INIT]."
QuickLogger "Can be activated with [service $PMOCR_SERVICE_FILE_INIT start]."
QuickLogger "Can be enabled on boot with [chkconfig $PMOCR_SERVICE_FILE_INIT on]."
fi
fi
}
function Statistics {
if type wget > /dev/null; then
wget -qO- "$STATS_LINK" > /dev/null 2>&1
if [ $? == 0 ]; then
return 0
fi
fi
if type curl > /dev/null; then
curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1
if [ $? == 0 ]; then
return 0
fi
fi
QuickLogger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please."
return 1
}
function Usage {
echo "Installs $PROGRAM into $BIN_DIR"
echo "options:"
echo "--silent Will log and bypass user interaction."
echo "--no-stats Used with --silent in order to refuse sending anonymous install stats."
exit 127
}
_SILENT=0
_STATS=1
for i in "$@"
do
case $i in
--silent)
_SILENT=1
;;
--no-stats)
_STATS=0
;;
--help|-h|-?)
Usage
esac
done
SetOSSettings
CreateConfDir
CopyExampleFiles
CopyProgram
GetInit
CopyServiceFiles
STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$OS"
QuickLogger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM"
if [ $_STATS -eq 1 ]; then
if [ $_SILENT -eq 1 ]; then
Statistics
else
QuickLogger "In order to make install statistics, the script would like to connect to $STATS_LINK"
read -r -p "No data except those in the url will be send. Allow [Y/n]" response
case $response in
[nN])
exit
;;
*)
Statistics
exit $?
;;
esac
fi
fi

172
obackup-batch.sh Executable file
View File

@@ -0,0 +1,172 @@
#!/usr/bin/env bash
SUBPROGRAM=obackup
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
PROGRAM_BUILD=2016052501
## Runs an osync /obackup instance for every conf file found
## If an instance fails, run it again if time permits
## Configuration file path. The path where all the osync / obackup conf files are, usually /etc/osync or /etc/obackup
CONF_FILE_PATH=/etc/$SUBPROGRAM
## If maximum execution time is not reached, failed instances will be rerun. Max exec time is in seconds. Example is set to 10 hours.
MAX_EXECUTION_TIME=36000
## Specifies the number of reruns an instance may get
MAX_RERUNS=3
## Log file path
if [ -w /var/log ]; then
LOG_FILE=/var/log/$SUBPROGRAM-batch.log
else
LOG_FILE=./$SUBPROGRAM-batch.log
fi
# No need to edit under this line ##############################################################
function _logger {
local value="${1}" # What to log
echo -e "$value" >> "$LOG_FILE"
}
function Logger {
local value="${1}" # What to log
local level="${2}" # Log level: DEBUG, NOTICE, WARN, ERROR, CRITIAL
prefix="$(date) - "
if [ "$level" == "CRITICAL" ]; then
_logger "$prefix\e[41m$value\e[0m"
elif [ "$level" == "ERROR" ]; then
_logger "$prefix\e[91m$value\e[0m"
elif [ "$level" == "WARN" ]; then
_logger "$prefix\e[93m$value\e[0m"
elif [ "$level" == "NOTICE" ]; then
_logger "$prefix$value"
elif [ "$level" == "DEBUG" ]; then
if [ "$DEBUG" == "yes" ]; then
_logger "$prefix$value"
fi
else
_logger "\e[41mLogger function called without proper loglevel.\e[0m"
_logger "$prefix$value"
fi
}
function CheckEnvironment {
## osync / obackup executable full path can be set here if it cannot be found on the system
if ! type $SUBPROGRAM.sh > /dev/null 2>&1
then
if [ -f /usr/local/bin/$SUBPROGRAM.sh ]
then
SUBPROGRAM_EXECUTABLE=/usr/local/bin/$SUBPROGRAM.sh
else
Logger "Could not find $SUBPROGRAM.sh" "CRITICAL"
exit 1
fi
else
SUBPROGRAM_EXECUTABLE=$(type -p $SUBPROGRAM.sh)
fi
## Check for CONF_FILE_PATH
if [ ! -d "$CONF_FILE_PATH" ]; then
Logger "Cannot find conf file path $CONF_FILE_PATH" "CRITICAL"
Usage
fi
}
function Batch {
## Get list of .conf files
for i in $CONF_FILE_PATH/*.conf
do
if [ "$RUN" == "" ]; then
RUN="$i"
else
RUN=$RUN" $i"
fi
done
RERUNS=0
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$RUN" != "" ] && [ $MAX_RERUNS -gt $RERUNS ]
do
Logger "$SUBPROGRAM instances will be run for: $RUN" "NOTICE"
for i in $RUN
do
$SUBPROGRAM_EXECUTABLE "$i" $opts &
wait $!
if [ $? != 0 ]; then
Logger "Run instance $(basename $i) failed" "ERROR"
if [ "$RUN_AGAIN" == "" ]; then
RUN_AGAIN="$i"
else
RUN_AGAIN=$RUN_AGAIN" $i"
fi
else
Logger "Run instance $(basename $i) succeed." "NOTICE"
fi
done
RUN="$RUN_AGAIN"
RUN_AGAIN=""
RERUNS=$(($RERUNS + 1))
done
}
function Usage {
echo "$PROGRAM $PROGRAM_BUILD"
echo $AUTHOR
echo $CONTACT
echo ""
echo "Batch script to sequentially run osync or obackup instances and rerun failed ones."
echo "Usage: $SUBPROGRAM-batch.sh [OPTIONS]"
echo ""
echo "[OPTIONS]"
echo "--path=/path/to/conf Path to osync / obackup conf files, defaults to /etc/osync or /etc/obackup"
echo "--max-reruns=X Number of runs max for failed instances, (defaults to 3)"
echo "--max-exec-time=X Retry failed instances only if max execution time not reached (defaults to 36000 seconds). Set to 0 to bypass execution time check."
echo "--no-maxtime Run osync / obackup without honoring conf file defined timeouts"
echo "--dry Will run osync / obackup without actually doing anything; just testing"
echo "--silent Will run osync / obackup without any output to stdout, used for cron jobs"
echo "--verbose Increases output"
exit 128
}
opts=""
for i in "$@"
do
case $i in
--silent)
opts=$opts" --silent"
;;
--dry)
opts=$opts" --dry"
;;
--verbose)
opts=$opts" --verbose"
;;
--no-maxtime)
opts=$opts" --no-maxtime"
;;
--path=*)
CONF_FILE_PATH=${i##*=}
;;
--max-reruns=*)
MAX_RERUNS=${i##*=}
;;
--max-exec-time=*)
MAX_EXECUTION_TIME=${i##*=}
;;
--help|-h|-?)
Usage
;;
*)
Logger "Unknown param '$i'" "CRITICAL"
Usage
;;
esac
done
CheckEnvironment
Logger "$(date) $SUBPROGRAM batch run" "NOTICE"
Batch

3374
obackup.sh

File diff suppressed because it is too large Load Diff

View File

@@ -1,79 +1,106 @@
#!/bin/bash
#!/usr/bin/env bash
##### Obackup / Osync ssh command filter build 2306201301
##### This script should be located in /usr/local/bin in the remote system that will be backed up / synced
##### osync / obackup ssh command filter
##### This script should be located in /usr/local/bin in the remote system to sync / backup
##### It will filter the commands that can be run remotely via ssh.
##### Please chmod 755 and chown root:root this file
##### Obackup needed commands: rsync find du mysql mysqldump (sudo)
##### Osync needed commands: rsync find du echo mkdir rm if df (sudo)
SCRIPT_BUILD=2016031401
## If enabled, execution of "sudo" command will be allowed.
SUDO_EXEC=yes
## Paranoia option. Don't change this unless you read the documentation and still feel concerned about security issues.
RSYNC_EXECUTABLE=rsync
## Enable other commands, useful for remote execution hooks like remotely creating snapshots.
CMD1=
CMD2=
CMD3=
CMD1=""
CMD2=""
CMD3=""
LOG_FILE=~/.ssh/ssh_filter.log
function Log
{
function Log {
DATE=$(date)
echo "$DATE - $1" >> $LOG_FILE
}
function Go
{
eval $SSH_ORIGINAL_COMMAND
function Go {
eval "$SSH_ORIGINAL_COMMAND"
}
case ${SSH_ORIGINAL_COMMAND%% *} in
"$RSYNC_EXECUTABLE")
Go ;;
"mysqldump")
Go ;;
"mysql")
Go ;;
"echo")
Go ;;
"find")
Go ;;
"du")
Go ;;
"mkdir")
Go ;;
"rm")
Go ;;
"df")
Go ;;
"mv")
Go ;;
"$CMD1")
Go ;;
if [ "$CMD1" != "" ]; then
Go
fi
;;
"$CMD2")
Go ;;
if [ "$CMD2" != "" ]; then
Go
fi
;;
"$CMD3")
Go ;;
if [ "$CMD3" != "" ]; then
Go
fi
;;
"sudo")
if [ "$SUDO_EXEC" == "yes" ]
then
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]
then
if [ "$SUDO_EXEC" == "yes" ]; then
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo du"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo du"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then
if [ "$CMD1" != "" ]; then
Go
fi
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]; then
if [ "$CMD2" != "" ]; then
Go
fi
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]; then
if [ "$CMD3" != "" ]; then
Go
fi
else
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
exit 1
fi
else
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed. sudo not enabled."
exit 1
fi
;;
*)
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
exit 1
esac

202
upgrade-v1.x-2.x.sh Executable file
View File

@@ -0,0 +1,202 @@
#!/usr/bin/env bash
PROGRAM="obackup config file upgrade script"
SUBPROGRAM="obackup"
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=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"
echo $AUTHOR
echo $CONTACT
echo ""
echo "This script migrates $SUBPROGRAM $OLD_PROGRAM_VERSION config files to $NEW_PROGRAM_VERSION."
echo ""
echo "Usage: $0 /path/to/config_file.conf"
echo "Please make sure the config file is writable."
exit 128
}
function LoadConfigFile {
local config_file="${1}"
if [ ! -f "$config_file" ]; then
echo "Cannot load configuration file [$config_file]. Sync cannot start."
exit 1
elif [[ "$1" != *".conf" ]]; then
echo "Wrong configuration file supplied [$config_file]. Sync cannot start."
exit 1
else
egrep '^#|^[^ ]*=[^;&]*' "$config_file" > "./$SUBPROGRAM.$FUNCNAME.$$"
source "./$SUBPROGRAM.$FUNCNAME.$$"
rm -f "./$SUBPROGRAM.$FUNCNAME.$$"
fi
}
function RewriteConfigFiles {
local config_file="${1}"
if ((! grep "BACKUP_ID=" $config_file > /dev/null) && ( ! grep "INSTANCE_ID=" $config_file > /dev/null)); then
echo "File [$config_file] does not seem to be a obackup config file."
exit 1
fi
echo "Backing up [$config_file] as [$config_file.save]"
cp -p "$config_file" "$config_file.save"
if [ $? != 0 ]; then
echo "Cannot backup config file."
exit 1
fi
echo "Rewriting config file $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
REMOTE_USER=$(cat $config_file | grep "REMOTE_USER=")
REMOTE_USER=${REMOTE_USER#*=}
REMOTE_HOST=$(cat $config_file | grep "REMOTE_HOST=")
REMOTE_HOST=${REMOTE_HOST#*=}
REMOTE_PORT=$(cat $config_file | grep "REMOTE_PORT=")
REMOTE_PORT=${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' '/^REMOTE_USER=*/d' "$config_file"
sed -i'.tmp' '/^REMOTE_HOST=*/d' "$config_file"
sed -i'.tmp' '/^REMOTE_PORT=*/d' "$config_file"
sed -i'.tmp' '/^INSTANCE_ID=*/a\'$'\n''BACKUP_TYPE=pull\'$'\n''' "$config_file"
else
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'.tmp' '/^FILE_STORAGE=*/a\'$'\n''ENCRYPTION=no\'$'\n''' "$config_file"
fi
if ! grep "^CREATE_DIRS=" "$config_file" > /dev/null; then
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'.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'.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'.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'.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'.tmp' '/^PRESERVE_XATTR=*/a\'$'\n''COPY_SYMLINKS=yes\'$'\n''' "$config_file"
fi
if ! grep "^KEEP_DIRLINKS=" "$config_file" > /dev/null; then
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'.tmp' '/^KEEP_DIRLINKS=*/a\'$'\n''PRESERVE_HARDLINKS=no\'$'\n''' "$config_file"
fi
if ! grep "^RSYNC_PATTERN_FIRST=" "$config_file" > /dev/null; then
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'.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'.tmp' '/^RSYNC_EXCLUDE_FROM=*/a\'$'\n''RSYNC_INCLUDE_FROM=""\'$'\n''' "$config_file"
fi
if ! grep "^PARTIAL=" "$config_file" > /dev/null; then
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'.tmp' '/^PARTIAL=*/a\'$'\n''DELETE_VANISHED_FILES=no\'$'\n''' "$config_file"
fi
if ! grep "^DELTA_COPIES=" "$config_file" > /dev/null; then
sed -i'.tmp' '/^PARTIAL=*/a\'$'\n''DELTA_COPIES=yes\'$'\n''' "$config_file"
fi
if ! grep "^BANDWIDTH=" "$config_file" > /dev/null; then
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'.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'.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
CONF_FILE="$1"
# Make sure there is no ending slash
CONF_FILE="${CONF_FILE%/}"
LoadConfigFile "$CONF_FILE"
RewriteConfigFiles "$CONF_FILE"
else
Usage
fi