mirror of
https://github.com/deajan/obackup.git
synced 2026-02-12 01:50:55 +01:00
Compare commits
137 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0ebd12742 | ||
|
|
63b82025ff | ||
|
|
759621c045 | ||
|
|
200b0a8685 | ||
|
|
7f99fd6c67 | ||
|
|
af8e220e33 | ||
|
|
b1c6aeb6fc | ||
|
|
fcab617c0d | ||
|
|
557738a5e5 | ||
|
|
f2d121f38f | ||
|
|
2488f9f654 | ||
|
|
48c178ed6b | ||
|
|
82e1b68398 | ||
|
|
22cc71c9e3 | ||
|
|
7a7a7c08bc | ||
|
|
5808e87057 | ||
|
|
a41fcdd00a | ||
|
|
04a66b2c9c | ||
|
|
92c3b38fff | ||
|
|
1aaf80eff7 | ||
|
|
ba9455d7e9 | ||
|
|
c68e326a45 | ||
|
|
104d7a0dde | ||
|
|
fdc71ceda3 | ||
|
|
e7fb070400 | ||
|
|
2c51055209 | ||
|
|
1913c897f1 | ||
|
|
f5dfc478a2 | ||
|
|
e0e3804e27 | ||
|
|
39de9cdfa5 | ||
|
|
78233a408e | ||
|
|
d0982a6cf6 | ||
|
|
15d3d98164 | ||
|
|
9d057ea95f | ||
|
|
e3c9c5cb18 | ||
|
|
4ad99413f4 | ||
|
|
4e61708b85 | ||
|
|
33570bc3f1 | ||
|
|
79ec8668e4 | ||
|
|
087638c8ae | ||
|
|
d39f6d092d | ||
|
|
b91f80702e | ||
|
|
2d95d4e64b | ||
|
|
38c39360b7 | ||
|
|
91dd9f5104 | ||
|
|
60266c40a6 | ||
|
|
a7e8487df3 | ||
|
|
6d410409a3 | ||
|
|
b9d2b72ac9 | ||
|
|
7eeff3b476 | ||
|
|
a61cb4d7cd | ||
|
|
ac50d769c9 | ||
|
|
6a4c56b939 | ||
|
|
7ed0e71ab4 | ||
|
|
f931227cd2 | ||
|
|
c2675e125d | ||
|
|
234fcd9887 | ||
|
|
5c74224dcd | ||
|
|
e18ebd1115 | ||
|
|
69fc7ac9cd | ||
|
|
0f11faa7c7 | ||
|
|
d2ab111f90 | ||
|
|
d36c77d777 | ||
|
|
b27ee4f8c1 | ||
|
|
192e1d2f65 | ||
|
|
6eea38afdf | ||
|
|
18f530ce0c | ||
|
|
6712fc6cc7 | ||
|
|
42a86c116d | ||
|
|
0096fe81c8 | ||
|
|
56f7c07e56 | ||
|
|
94eee06616 | ||
|
|
5ddec503dc | ||
|
|
d1c5de13de | ||
|
|
d584149e39 | ||
|
|
6cd1815ed9 | ||
|
|
a95c37e67f | ||
|
|
954606b8ba | ||
|
|
61a70b1ba5 | ||
|
|
4b2b99d016 | ||
|
|
896eb0b650 | ||
|
|
cdf6ca15ec | ||
|
|
da043ed3ae | ||
|
|
60b3d4674e | ||
|
|
213b2de002 | ||
|
|
882bfd276e | ||
|
|
013fbdf000 | ||
|
|
541119dda2 | ||
|
|
87dd950199 | ||
|
|
3b17f127cf | ||
|
|
197f3036d1 | ||
|
|
4038cd5c8f | ||
|
|
1fa695e3b0 | ||
|
|
62600fff39 | ||
|
|
6dd92b03f8 | ||
|
|
6326144ee4 | ||
|
|
00cefd010e | ||
|
|
1e13d259cb | ||
|
|
b04891b6c7 | ||
|
|
fb310b1026 | ||
|
|
c00a00525c | ||
|
|
2080da1565 | ||
|
|
48c1ef4140 | ||
|
|
5b7b9b0e28 | ||
|
|
dfeccbdf43 | ||
|
|
d3985716d8 | ||
|
|
ac20502b3e | ||
|
|
4ee08d0814 | ||
|
|
ee5a770e18 | ||
|
|
b687ba0629 | ||
|
|
6f467a05b0 | ||
|
|
37c0f956ea | ||
|
|
a96707d17c | ||
|
|
45633d1362 | ||
|
|
2c87aee183 | ||
|
|
03e0ec4654 | ||
|
|
9b0e673ee0 | ||
|
|
dd9d3dc982 | ||
|
|
7c9f3f4d73 | ||
|
|
c2b64d9479 | ||
|
|
7ee1872718 | ||
|
|
ec7140e963 | ||
|
|
4662627a4a | ||
|
|
6b11e2be69 | ||
|
|
dc784a2671 | ||
|
|
e828519c32 | ||
|
|
f7c896bd53 | ||
|
|
73c0191db6 | ||
|
|
efefe2df19 | ||
|
|
b0e7770df2 | ||
|
|
7bdf7e0939 | ||
|
|
e18a4ad816 | ||
|
|
c317e37601 | ||
|
|
385c45c46f | ||
|
|
bd9664a6ec | ||
|
|
4b212311ff | ||
|
|
d963c02c06 |
99
CHANGELOG.md
99
CHANGELOG.md
@@ -1,24 +1,101 @@
|
|||||||
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
|
KNOWN ISSUES
|
||||||
------------
|
------------
|
||||||
|
|
||||||
- Backup size check does not honor rsync exclude patterns
|
- Backup size check does not honor rsync exclude patterns
|
||||||
- Bandwidth parameter is ignored for SQL backups
|
- Bandwidth parameter is ignored for SQL backups
|
||||||
- Missing symlink support when run from MSYS environment
|
- Missing symlink support when run from MSYS environment
|
||||||
|
- Mysqldump errors aren't taken in account
|
||||||
|
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
README: FreeBSD execution needs mailer (not found), sudo missing, bash needed, sed missing (see if StripQuotes mandatory)
|
||||||
|
|
||||||
|
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
|
- 02 Nov. 2013: v1.84 RC3
|
||||||
- Updated documentation
|
- Updated documentation
|
||||||
- Minor rewrites in recursive backup code
|
- Minor rewrites in recursive backup code
|
||||||
|
|||||||
147
CODING_STYLE.TXT
Normal file
147
CODING_STYLE.TXT
Normal 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.
|
||||||
|
|
||||||
@@ -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.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
34
README.md
34
README.md
@@ -1,12 +1,11 @@
|
|||||||
obackup
|
obackup
|
||||||
=======
|
=======
|
||||||
|
|
||||||
A small robust file & database backup script for local to local or remote to local backups via ssh.
|
A robust file & database backup script that works for local and remote push or pull backups via ssh.
|
||||||
Works especially well for multiple virtualhost backups with 'backup divide task' functionnality.
|
|
||||||
|
|
||||||
## About
|
## 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.
|
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.
|
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.
|
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.
|
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 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.
|
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).
|
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.
|
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.
|
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 FreeBSD and Windows MSYS environment, altough it is not fully tested yet.
|
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
|
## Installation
|
||||||
|
|
||||||
You can download the latest obackup script from authors website.
|
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.
|
You may also clone the following git which will maybe have some more recent builds.
|
||||||
|
|
||||||
$ git clone git://github.com/deajan/obackup.git
|
$ git clone -b "v2.0" git://github.com/deajan/obackup.git
|
||||||
$ chmod +x ./obackup.sh
|
$ 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.
|
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.
|
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,
|
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.
|
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.
|
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
|
## 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.
|
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
|
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,
|
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.
|
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
|
## Author
|
||||||
|
|
||||||
Feel free to mail me for limited support in my free time :)
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2646
dev/debug_obackup.sh
Executable file
2646
dev/debug_obackup.sh
Executable file
File diff suppressed because it is too large
Load Diff
71
dev/merge.sh
Executable file
71
dev/merge.sh
Executable 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
|
||||||
1400
dev/n_obackup.sh
Executable file
1400
dev/n_obackup.sh
Executable file
File diff suppressed because it is too large
Load Diff
1247
dev/ofunctions.sh
Normal file
1247
dev/ofunctions.sh
Normal file
File diff suppressed because it is too large
Load Diff
7
exclude.list.example
Normal file
7
exclude.list.example
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.AppleDouble/
|
||||||
|
._*
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
System Volume Information
|
||||||
|
$Recycle.Bin
|
||||||
|
|
||||||
163
host_backup.conf
163
host_backup.conf
@@ -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
208
host_backup.conf.example
Normal 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
311
install.sh
Executable file
@@ -0,0 +1,311 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
PROGRAM=obackup
|
||||||
|
PROGRAM_VERSION=2.0
|
||||||
|
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
172
obackup-batch.sh
Executable 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
|
||||||
3363
obackup.sh
3363
obackup.sh
File diff suppressed because it is too large
Load Diff
@@ -1,79 +1,106 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
##### Obackup / Osync ssh command filter build 2306201301
|
##### osync / obackup ssh command filter
|
||||||
##### This script should be located in /usr/local/bin in the remote system that will be backed up / synced
|
##### 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.
|
##### It will filter the commands that can be run remotely via ssh.
|
||||||
##### Please chmod 755 and chown root:root this file
|
##### 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.
|
## If enabled, execution of "sudo" command will be allowed.
|
||||||
SUDO_EXEC=yes
|
SUDO_EXEC=yes
|
||||||
## 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.
|
||||||
RSYNC_EXECUTABLE=rsync
|
RSYNC_EXECUTABLE=rsync
|
||||||
## Enable other commands, useful for remote execution hooks like remotely creating snapshots.
|
## Enable other commands, useful for remote execution hooks like remotely creating snapshots.
|
||||||
CMD1=
|
CMD1=""
|
||||||
CMD2=
|
CMD2=""
|
||||||
CMD3=
|
CMD3=""
|
||||||
|
|
||||||
LOG_FILE=~/.ssh/ssh_filter.log
|
LOG_FILE=~/.ssh/ssh_filter.log
|
||||||
|
|
||||||
function Log
|
function Log {
|
||||||
{
|
|
||||||
DATE=$(date)
|
DATE=$(date)
|
||||||
echo "$DATE - $1" >> $LOG_FILE
|
echo "$DATE - $1" >> $LOG_FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
function Go
|
function Go {
|
||||||
{
|
eval "$SSH_ORIGINAL_COMMAND"
|
||||||
eval $SSH_ORIGINAL_COMMAND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case ${SSH_ORIGINAL_COMMAND%% *} in
|
case ${SSH_ORIGINAL_COMMAND%% *} in
|
||||||
"$RSYNC_EXECUTABLE")
|
"$RSYNC_EXECUTABLE")
|
||||||
Go ;;
|
Go ;;
|
||||||
"mysqldump")
|
|
||||||
Go ;;
|
|
||||||
"mysql")
|
|
||||||
Go ;;
|
|
||||||
"echo")
|
"echo")
|
||||||
Go ;;
|
Go ;;
|
||||||
"find")
|
"find")
|
||||||
Go ;;
|
Go ;;
|
||||||
"du")
|
"du")
|
||||||
Go ;;
|
Go ;;
|
||||||
|
"mkdir")
|
||||||
|
Go ;;
|
||||||
|
"rm")
|
||||||
|
Go ;;
|
||||||
|
"df")
|
||||||
|
Go ;;
|
||||||
|
"mv")
|
||||||
|
Go ;;
|
||||||
"$CMD1")
|
"$CMD1")
|
||||||
Go ;;
|
if [ "$CMD1" != "" ]; then
|
||||||
|
Go
|
||||||
|
fi
|
||||||
|
;;
|
||||||
"$CMD2")
|
"$CMD2")
|
||||||
Go ;;
|
if [ "$CMD2" != "" ]; then
|
||||||
|
Go
|
||||||
|
fi
|
||||||
|
;;
|
||||||
"$CMD3")
|
"$CMD3")
|
||||||
Go ;;
|
if [ "$CMD3" != "" ]; then
|
||||||
|
Go
|
||||||
|
fi
|
||||||
|
;;
|
||||||
"sudo")
|
"sudo")
|
||||||
if [ "$SUDO_EXEC" == "yes" ]
|
if [ "$SUDO_EXEC" == "yes" ]; then
|
||||||
then
|
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]; then
|
||||||
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]
|
|
||||||
then
|
|
||||||
Go
|
Go
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo du"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo du"* ]]; then
|
||||||
then
|
|
||||||
Go
|
Go
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then
|
||||||
then
|
|
||||||
Go
|
Go
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]; then
|
||||||
then
|
|
||||||
Go
|
Go
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]; then
|
||||||
then
|
|
||||||
Go
|
Go
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]; then
|
||||||
then
|
|
||||||
Go
|
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
|
else
|
||||||
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
|
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed. sudo not enabled."
|
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed. sudo not enabled."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
|
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
|
||||||
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|||||||
202
upgrade-v1.x-2.x.sh
Executable file
202
upgrade-v1.x-2.x.sh
Executable 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
|
||||||
Reference in New Issue
Block a user