mirror of
https://github.com/deajan/obackup.git
synced 2026-02-12 01:50:55 +01:00
Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
41
CHANGELOG.md
41
CHANGELOG.md
@@ -1,9 +1,3 @@
|
|||||||
SHORT FUTURE IMPROVEMENTS
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
- Rewrite rsync exclude patterns using \"pattern\" instead of escaped chars
|
|
||||||
- Clean most of recursive task creation code
|
|
||||||
|
|
||||||
KNOWN ISSUES
|
KNOWN ISSUES
|
||||||
------------
|
------------
|
||||||
|
|
||||||
@@ -11,16 +5,35 @@ KNOWN ISSUES
|
|||||||
- 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
|
||||||
|
|
||||||
UNDER WORK
|
|
||||||
----------
|
|
||||||
|
|
||||||
- Commands like cp should have their stderr redirected to log file
|
|
||||||
- Mysqldump must be checked for not telling success if a table is damaged (also check for event table error)
|
|
||||||
- Mysqldump commands error msg must be logged
|
|
||||||
|
|
||||||
|
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
README: FreeBSD execution needs mailer (not found), sudo missing, bash needed, sed missing (see if StripQuotes mandatory)
|
||||||
|
|
||||||
|
! XX Mar 2016: obackup v2.0 released
|
||||||
|
- 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
|
- New function to kill child processes
|
||||||
- Fixed no_maxtime not honored
|
- Fixed no_maxtime not honored
|
||||||
- Improved some logging, also added highlighting to stdout errors
|
- Improved some logging, also added highlighting to stdout errors
|
||||||
|
|||||||
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
|
||||||
2585
dev/debug_obackup.sh
Executable file
2585
dev/debug_obackup.sh
Executable file
File diff suppressed because it is too large
Load Diff
53
dev/merge.sh
Executable file
53
dev/merge.sh
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
## Merges ofunctions.sh and n_osync.sh into osync.sh
|
||||||
|
|
||||||
|
PROGRAM=obackup
|
||||||
|
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
|
||||||
|
VERSION=${VERSION#*=}
|
||||||
|
FUNC_PATH=/home/git/common
|
||||||
|
|
||||||
|
PARANOIA_DEBUG_LINE="__WITH_PARANOIA_DEBUG"
|
||||||
|
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
|
||||||
|
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
|
||||||
|
|
||||||
|
function Unexpand {
|
||||||
|
unexpand n_$PROGRAM.sh > tmp_$PROGRAM.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
function Merge {
|
||||||
|
|
||||||
|
sed "/source \"\.\/ofunctions.sh\"/r /home/git/common/ofunctions.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' > debug_$PROGRAM.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" /home/git/common/common_install.sh > ../tmp_install.sh
|
||||||
|
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
|
||||||
|
sed "s/\[prgname\]/$PROGRAM/g" /home/git/common/common_batch.sh > ../$PROGRAM-batch.sh
|
||||||
|
chmod +x ../install.sh
|
||||||
|
chmod +x ../obackup-batch.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
Unexpand
|
||||||
|
Merge
|
||||||
|
CleanDebug
|
||||||
|
rm -f tmp_$PROGRAM.sh
|
||||||
|
rm -f ../tmp_install.sh
|
||||||
|
CopyCommons
|
||||||
1392
dev/n_obackup.sh
Executable file
1392
dev/n_obackup.sh
Executable file
File diff suppressed because it is too large
Load Diff
1194
dev/ofunctions.sh
Normal file
1194
dev/ofunctions.sh
Normal file
File diff suppressed because it is too large
Load Diff
153
host_backup.conf → host_backup.conf.example
Executable file → Normal file
153
host_backup.conf → host_backup.conf.example
Executable file → Normal file
@@ -1,73 +1,79 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
###### Remote (or local) backup script for files & databases
|
###### obackup - Local or Remote, push or pull backup script for files & mysql databases
|
||||||
###### (L) 2013 by Ozy de Jong (www.netpower.fr)
|
###### (C) 2013-2016 by Orsiris de Jong (www.netpower.fr)
|
||||||
###### Config file rev 2015090801
|
###### obackup v2.x config file rev 2016052501
|
||||||
|
|
||||||
## ---------- GENERAL BACKUP OPTIONS
|
###### GENERAL BACKUP OPTIONS
|
||||||
|
|
||||||
## Backup identification name.
|
## Backup identification string.
|
||||||
BACKUP_ID="your backup name"
|
INSTANCE_ID="test-backup"
|
||||||
|
|
||||||
## 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)
|
## 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=""
|
LOGFILE=""
|
||||||
|
|
||||||
## Backup databases
|
## Elements to backup
|
||||||
BACKUP_SQL=no
|
SQL_BACKUP=yes
|
||||||
## Backup files
|
FILE_BACKUP=yes
|
||||||
BACKUP_FILES=yes
|
|
||||||
|
|
||||||
## ---------- LOCAL BACKUP STORAGE OPTIONS
|
## 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
|
||||||
|
|
||||||
## Local storage paths where to put backups
|
###### BACKUP STORAGE
|
||||||
LOCAL_SQL_STORAGE="/home/storage/backup/sql"
|
|
||||||
LOCAL_FILE_STORAGE="/home/storage/backup/files"
|
## 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 backup directories if they do not exist
|
||||||
CREATE_DIRS=yes
|
CREATE_DIRS=yes
|
||||||
|
|
||||||
## Keep absolute source path in your backup, eg: /your/backup/storage/the/remote/server/files
|
## 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.
|
## 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
|
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)
|
## 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
|
BACKUP_SIZE_MINIMUM=1024
|
||||||
## You may disable testing backup size
|
|
||||||
DISABLE_GET_BACKUP_FILE_SIZE=no
|
|
||||||
|
|
||||||
## Generate an alert if local 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.
|
## Check backup size before proceeding
|
||||||
LOCAL_STORAGE_WARN_MIN_SPACE=1048576
|
GET_BACKUP_SIZE=yes
|
||||||
|
|
||||||
## ---------- MISC OPTIONS
|
## 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
|
||||||
|
|
||||||
## Bandwidth limit Kbytes / second for file backups. Leave 0 to disable limitation.
|
###### REMOTE ONLY OPTIONS
|
||||||
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.
|
## In case of pulled or pushed backups, remote system URI needs to be supplied.
|
||||||
SUDO_EXEC=no
|
REMOTE_SYSTEM_URI="ssh://backupuser@remote.system.tld:22/"
|
||||||
## Paranoia option. Don't change this unless you read the documentation.
|
|
||||||
RSYNC_EXECUTABLE=rsync
|
|
||||||
|
|
||||||
## ---------- REMOTE BACKUP OPTIONS
|
## 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"
|
||||||
|
|
||||||
## 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 should be used unless your remote connection is good enough (LAN)
|
||||||
SSH_COMPRESSION=yes
|
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
|
## Remote rsync executable path. Leave this empty in most cases
|
||||||
RSYNC_REMOTE_PATH=""
|
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.
|
## 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
|
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.
|
## 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"
|
REMOTE_3RD_PARTY_HOSTS="www.kernel.org www.google.com"
|
||||||
|
|
||||||
## ---------- DATABASE BACKUP OPTIONS
|
## 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
|
## Database backup user
|
||||||
SQL_USER=backupuser
|
SQL_USER=backupuser
|
||||||
@@ -75,9 +81,9 @@ 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.
|
## 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.
|
## Every found database will be backed up as separate backup task.
|
||||||
DATABASES_ALL=yes
|
DATABASES_ALL=yes
|
||||||
DATABASES_ALL_EXCLUDE_LIST="test;mysql"
|
DATABASES_ALL_EXCLUDE_LIST="test"
|
||||||
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
## Alternatively, if DATABASES_ALL=no, you can specify a list of databases to backup separated by spaces.
|
||||||
DATABASES_LIST=""
|
#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.
|
## 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.
|
## If a task gets stopped, next one in the task list gets executed. Time is specified in seconds.
|
||||||
@@ -88,30 +94,31 @@ HARD_MAX_EXEC_TIME_DB_TASK=7200
|
|||||||
## Generally, level 5 is a good compromise between cpu, memory hunger and compress ratio. Gzipped files are set to be rsyncable.
|
## Generally, level 5 is a good compromise between cpu, memory hunger and compress ratio. Gzipped files are set to be rsyncable.
|
||||||
COMPRESSION_LEVEL=3
|
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)
|
###### FILES SPECIFIC OPTIONS
|
||||||
COMPRESSION_REMOTE=yes
|
|
||||||
|
|
||||||
## ---------- FILES BACKUP 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 recursively. Every directory will be processed as one backup task.
|
## Directories backup list. List of semicolon separated directories that will be backed up.
|
||||||
DIRECTORIES_SIMPLE_LIST="/var/named;/var/lib"
|
DIRECTORY_LIST="/var/named"
|
||||||
|
RECURSIVE_DIRECTORY_LIST="/home"
|
||||||
|
RECURSIVE_EXCLUDE_LIST="/home/backupuser;/home/lost+found"
|
||||||
|
|
||||||
## There's a special backup schema in Obackup called 'backup task division' which creates one backup task per level 1 subdirectory of a directory.
|
## Rsync exclude / include order (the option set here will be set first, eg: include will make include then exclude patterns)
|
||||||
## This is VERY useful to backup multiple virtualhosts as separate tasks without having to specify each one separately.
|
RSYNC_PATTERN_FIRST=include
|
||||||
## This may also be useful 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 separate backup task.
|
## List of files / directories to incldue / exclude from sync on both sides (see rsync patterns, wildcards work).
|
||||||
## Example: "/home;/var" will create tasks "/home/dir1", "/home/dir2", ... "/home/dirN", "/var/log", "/var/lib"... "/var/whatever"
|
## Paths are relative to sync dirs. List elements are separated by a semicolon.
|
||||||
DIRECTORIES_RECURSE_LIST="/home"
|
RSYNC_INCLUDE_PATTERN=""
|
||||||
## 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
|
RSYNC_EXCLUDE_PATTERN=""
|
||||||
DIRECTORIES_RECURSE_EXCLUDE_LIST="/home/backupuser;/home/lost+found"
|
#RSYNC_EXCLUDE_PATTERN="tmp;archives"
|
||||||
|
|
||||||
## Rsync exclude patterns, used by simple and division lists
|
## 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.
|
||||||
RSYNC_EXCLUDE_PATTERN="*/tmp;*/ftp/www/cache/cachefs;*/sessions"
|
|
||||||
|
|
||||||
## File that contains the list of directories or files to 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
|
## This file has to be in the same directory as the config file
|
||||||
## Paths are relative to sync dirs. One element per line.
|
## Paths are relative to sync dirs. One element per line.
|
||||||
|
RSYNC_INCLUDE_FROM=""
|
||||||
RSYNC_EXCLUDE_FROM=""
|
RSYNC_EXCLUDE_FROM=""
|
||||||
#RSYNC_EXCLUDE_FROM="exclude.list"
|
#RSYNC_EXCLUDE_FROM="exclude.list"
|
||||||
|
|
||||||
@@ -147,18 +154,27 @@ DELETE_VANISHED_FILES=no
|
|||||||
## Use delta copy algortithm (usefull when local paths are network drives), defaults to yes
|
## Use delta copy algortithm (usefull when local paths are network drives), defaults to yes
|
||||||
DELTA_COPIES=yes
|
DELTA_COPIES=yes
|
||||||
|
|
||||||
## ---------- ALERT OPTIONS
|
## 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
|
## Alert email addresses separated by a space character
|
||||||
DESTINATION_MAILS="your@mail.address"
|
DESTINATION_MAILS="your@mail.address"
|
||||||
|
|
||||||
## Windows (MSYS environment) only mail options (used by sendemail.exe)
|
## 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"
|
SENDER_MAIL="alert@your.system.tld"
|
||||||
SMTP_SERVER=smtp.your.isp.com
|
SMTP_SERVER=smtp.your.isp.tld
|
||||||
|
SMTP_PORT=25
|
||||||
|
# encryption can be tls, ssl or none
|
||||||
|
SMTP_ENCRYPTION=none
|
||||||
SMTP_USER=
|
SMTP_USER=
|
||||||
SMTP_PASSWORD=
|
SMTP_PASSWORD=
|
||||||
|
|
||||||
## ---------- GENERAL BACKUP OPTIONS
|
###### GENERAL BACKUP OPTIONS
|
||||||
|
|
||||||
## Max execution time of whole backup process. Soft max exec time generates a warning only.
|
## 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.
|
## Hard max exec time generates a warning and stops the whole backup execution.
|
||||||
@@ -166,10 +182,12 @@ SOFT_MAX_EXEC_TIME_TOTAL=30000
|
|||||||
HARD_MAX_EXEC_TIME_TOTAL=36000
|
HARD_MAX_EXEC_TIME_TOTAL=36000
|
||||||
|
|
||||||
## Backup Rotation. You may rotate backups if you don't use snapshots on your backup server.
|
## Backup Rotation. You may rotate backups if you don't use snapshots on your backup server.
|
||||||
ROTATE_BACKUPS=no
|
ROTATE_SQL_BACKUPS=no
|
||||||
ROTATE_COPIES=7
|
ROTATE_SQL_COPIES=7
|
||||||
|
ROTATE_FILE_BACKUPS=no
|
||||||
|
ROTATE_FILE_COPIES=7
|
||||||
|
|
||||||
## ---------- EXECUTION HOOKS
|
###### EXECUTION HOOKS
|
||||||
|
|
||||||
## Commands can will be run before and / or after backup execution (remote execution will only happen if REMOTE_BACKUP is set).
|
## 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.
|
## This is useful to make a snapshot before backing up data, or even handle snapshots of backed up data.
|
||||||
@@ -185,3 +203,6 @@ MAX_EXEC_TIME_PER_CMD_AFTER=0
|
|||||||
|
|
||||||
## Stops whole backup execution if one of the above commands fail
|
## Stops whole backup execution if one of the above commands fail
|
||||||
STOP_ON_CMD_ERROR=no
|
STOP_ON_CMD_ERROR=no
|
||||||
|
|
||||||
|
## Run local and remote after backup cmd's even on failure
|
||||||
|
RUN_AFTER_CMD_ON_ERROR=no
|
||||||
218
install.sh
218
install.sh
@@ -1,25 +1,211 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
SCRIPT_BUILD=2015082501
|
PROGRAM=obackup
|
||||||
|
PROGRAM_VERSION=2.0-RC1
|
||||||
|
PROGRAM_BINARY=$PROGRAM".sh"
|
||||||
|
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
||||||
|
SCRIPT_BUILD=2016052501
|
||||||
|
|
||||||
## Obackup install script
|
## osync / obackup / pmocr / zsnap install script
|
||||||
## Tested on RHEL / CentOS 6 & 7
|
## 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
|
## Please adapt this to fit your distro needs
|
||||||
|
|
||||||
if [ "$(whoami)" != "root" ]
|
CONF_DIR=/etc/$PROGRAM
|
||||||
then
|
BIN_DIR=/usr/local/bin
|
||||||
echo "Must be run as root."
|
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
|
||||||
|
|
||||||
|
USER=root
|
||||||
|
|
||||||
|
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
|
||||||
|
echo "Must be run as $USER."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir /etc/obackup
|
if [ -f /sbin/init ]; then
|
||||||
cp ./host_backup.conf /etc/obackup/host_backup.conf.example
|
if file /sbin/init | grep systemd > /dev/null; then
|
||||||
cp ./exclude.list.example /etc/obackup
|
init="systemd"
|
||||||
cp ./obackup.sh /usr/local/bin
|
else
|
||||||
cp ./obackup-batch.sh /usr/local/bin
|
init="initV"
|
||||||
cp ./ssh_filter.sh /usr/local/bin
|
fi
|
||||||
chmod 755 /usr/local/bin/obackup.sh
|
else
|
||||||
chmod 755 /usr/local/bin/obackup-batch.sh
|
echo "Can't detect initV or systemd. Service files won't be installed. You can still run $PROGRAM manually or via cron."
|
||||||
chmod 755 /usr/local/bin/ssh_filter.sh
|
init=none
|
||||||
chown root:root /usr/local/bin/ssh_filter.sh
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$CONF_DIR" ]; then
|
||||||
|
mkdir "$CONF_DIR"
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
echo "Created directory [$CONF_DIR]."
|
||||||
|
else
|
||||||
|
echo "Cannot create directory [$CONF_DIR]."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Config directory [$CONF_DIR] exists."
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
cp "./$PROGRAM_BINARY" "$BIN_DIR"
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
echo "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]."
|
||||||
|
else
|
||||||
|
chmod 755 "$BIN_DIR/$PROGRAM_BINARY"
|
||||||
|
echo "Copied $PROGRAM_BINARY to [$BIN_DIR]."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "./$PROGRAM_BATCH" ]; then
|
||||||
|
cp "./$PROGRAM_BATCH" "$BIN_DIR"
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
echo "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]."
|
||||||
|
else
|
||||||
|
chmod 755 "$BIN_DIR/$PROGRAM_BATCH"
|
||||||
|
echo "Copied $PROGRAM_BATCH to [$BIN_DIR]."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "./ssh_filter.sh" ]; then
|
||||||
|
cp "./ssh_filter.sh" "$BIN_DIR"
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
echo "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
|
||||||
|
echo "Copied ssh_filter.sh to [$BIN_DIR]."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
echo "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]."
|
||||||
|
else
|
||||||
|
echo "Created osync-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
|
||||||
|
echo "Can be activated with [systemctl start osync-srv@instance.conf] where instance.conf is the name of the config file in /etc/osync."
|
||||||
|
echo "Can be enabled on boot with [systemctl enable osync-srv@instance.conf]."
|
||||||
|
echo "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
|
||||||
|
echo "Cannot copy osync-srv to [$SERVICE_DIR_INIT]."
|
||||||
|
else
|
||||||
|
chmod 755 "$SERVICE_DIR_INIT/$OSYNC_SERVICE_FILE_INIT"
|
||||||
|
echo "Created osync-srv service in [$SERVICE_DIR_INIT]."
|
||||||
|
echo "Can be activated with [service $OSYNC_SERVICE_FILE_INIT start]."
|
||||||
|
echo "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
|
||||||
|
echo "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]."
|
||||||
|
else
|
||||||
|
echo "Created pmocr-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
|
||||||
|
echo "Can be activated with [systemctl start pmocr-srv] after configuring file options in [$BIN_DIR/$PROGRAM]."
|
||||||
|
echo "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
|
||||||
|
echo "Cannot copy pmoct-srv to [$SERVICE_DIR_INIT]."
|
||||||
|
else
|
||||||
|
chmod 755 "$SERVICE_DIR_INIT/$PMOCR_SERVICE_FILE_INIT"
|
||||||
|
echo "Created osync-srv service in [$SERVICE_DIR_INIT]."
|
||||||
|
echo "Can be activated with [service $PMOCR_SERVICE_FILE_INIT start]."
|
||||||
|
echo "Can be enabled on boot with [chkconfig $PMOCR_SERVICE_FILE_INIT on]."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
function Statistics {
|
||||||
|
|
||||||
|
local link="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$local_os_var"
|
||||||
|
if type wget > /dev/null; then
|
||||||
|
wget -qO- $link > /dev/null 2>&1
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if type curl > /dev/null; then
|
||||||
|
curl -o /dev/null $link > /dev/null 2>&1
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please."
|
||||||
|
retun 1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM"
|
||||||
|
echo ""
|
||||||
|
echo "In order to make install statistics, the script would like to connect to http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION"
|
||||||
|
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
|
||||||
|
|||||||
180
obackup-batch.sh
180
obackup-batch.sh
@@ -1,15 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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
|
||||||
|
|
||||||
PROGRAM="Obackup-batch" # Batch program to run obackup instances sequentially and rerun failed ones
|
## Runs an osync /obackup instance for every conf file found
|
||||||
AUTHOR="(L) 2013-2014 by Orsiris \"Ozy\" de Jong"
|
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
|
||||||
PROGRAM_BUILD=2508201501
|
|
||||||
|
|
||||||
## Runs an obackup instance for every conf file found
|
|
||||||
## If an instance fails, run it again if time permits
|
## If an instance fails, run it again if time permits
|
||||||
|
|
||||||
## Configuration file path. The path where all the obackup conf files are, usually /etc/obackup
|
## Configuration file path. The path where all the osync / obackup conf files are, usually /etc/osync or /etc/obackup
|
||||||
CONF_FILE_PATH=/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.
|
## 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
|
MAX_EXECUTION_TIME=36000
|
||||||
@@ -18,60 +18,70 @@ MAX_EXECUTION_TIME=36000
|
|||||||
MAX_RERUNS=3
|
MAX_RERUNS=3
|
||||||
|
|
||||||
## Log file path
|
## Log file path
|
||||||
if [ -w /var/log ]
|
if [ -w /var/log ]; then
|
||||||
then
|
LOG_FILE=/var/log/$SUBPROGRAM-batch.log
|
||||||
LOG_FILE=/var/log/obackup-batch.log
|
|
||||||
else
|
else
|
||||||
LOG_FILE=./obackup-batch.log
|
LOG_FILE=./$SUBPROGRAM-batch.log
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# No need to edit under this line ##############################################################
|
# No need to edit under this line ##############################################################
|
||||||
|
|
||||||
function Log
|
function _logger {
|
||||||
{
|
local value="${1}" # What to log
|
||||||
prefix="TIME: $SECONDS - "
|
echo -e "$value" >> "$LOG_FILE"
|
||||||
echo -e "$prefix$1" >> "$LOG_FILE"
|
|
||||||
|
|
||||||
if [ $silent -eq 0 ]
|
|
||||||
then
|
|
||||||
echo -e "$prefix$1"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckEnvironment
|
function Logger {
|
||||||
{
|
local value="${1}" # What to log
|
||||||
## Obackup executable full path can be set here if it cannot be found on the system
|
local level="${2}" # Log level: DEBUG, NOTICE, WARN, ERROR, CRITIAL
|
||||||
if ! type -p obackup.sh > /dev/null 2>&1
|
|
||||||
then
|
prefix="$(date) - "
|
||||||
if [ -f /usr/local/bin/obackup.sh ]
|
|
||||||
then
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
OBACKUP_EXECUTABLE=/usr/local/bin/obackup.sh
|
_logger "$prefix\e[41m$value\e[0m"
|
||||||
elif [ -f ./obackup.sh ]
|
elif [ "$level" == "ERROR" ]; then
|
||||||
then
|
_logger "$prefix\e[91m$value\e[0m"
|
||||||
OBACKUP_EXECUTABLE=./obackup.sh
|
elif [ "$level" == "WARN" ]; then
|
||||||
else
|
_logger "$prefix\e[93m$value\e[0m"
|
||||||
Log "Could not find obackup.sh"
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
exit 1
|
_logger "$prefix$value"
|
||||||
fi
|
elif [ "$level" == "DEBUG" ]; then
|
||||||
else
|
if [ "$DEBUG" == "yes" ]; then
|
||||||
OBACKUP_EXECUTABLE=$(type -p obackup.sh)
|
_logger "$prefix$value"
|
||||||
fi
|
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
|
## Check for CONF_FILE_PATH
|
||||||
if [ ! -d "$CONF_FILE_PATH" ]
|
if [ ! -d "$CONF_FILE_PATH" ]; then
|
||||||
then
|
Logger "Cannot find conf file path $CONF_FILE_PATH" "CRITICAL"
|
||||||
Log "Cannot find conf file path $CONF_FILE_PATH"
|
Usage
|
||||||
Usage
|
fi
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Batch
|
function Batch {
|
||||||
{
|
|
||||||
## Get list of .conf files
|
## Get list of .conf files
|
||||||
for i in $(ls $CONF_FILE_PATH/*.conf)
|
for i in $CONF_FILE_PATH/*.conf
|
||||||
do
|
do
|
||||||
if [ "$RUN" == "" ]
|
if [ "$RUN" == "" ]; then
|
||||||
then
|
|
||||||
RUN="$i"
|
RUN="$i"
|
||||||
else
|
else
|
||||||
RUN=$RUN" $i"
|
RUN=$RUN" $i"
|
||||||
@@ -81,21 +91,20 @@ function Batch
|
|||||||
RERUNS=0
|
RERUNS=0
|
||||||
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$RUN" != "" ] && [ $MAX_RERUNS -gt $RERUNS ]
|
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$RUN" != "" ] && [ $MAX_RERUNS -gt $RERUNS ]
|
||||||
do
|
do
|
||||||
Log "Obackup instances will be run for: $RUN"
|
Logger "$SUBPROGRAM instances will be run for: $RUN" "NOTICE"
|
||||||
for i in $RUN
|
for i in $RUN
|
||||||
do
|
do
|
||||||
$OBACKUP_EXECUTABLE "$i" $opts
|
$SUBPROGRAM_EXECUTABLE "$i" $opts &
|
||||||
if [ $? != 0 ]
|
wait $!
|
||||||
then
|
if [ $? != 0 ]; then
|
||||||
Log "Run instance $(basename $i) failed"
|
Logger "Run instance $(basename $i) failed" "ERROR"
|
||||||
if [ "RUN_AGAIN" == "" ]
|
if [ "$RUN_AGAIN" == "" ]; then
|
||||||
then
|
|
||||||
RUN_AGAIN="$i"
|
RUN_AGAIN="$i"
|
||||||
else
|
else
|
||||||
RUN_AGAIN=$RUN_AGAIN" $i"
|
RUN_AGAIN=$RUN_AGAIN" $i"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
Log "Run instance $(basename $i) succeed."
|
Logger "Run instance $(basename $i) succeed." "NOTICE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
RUN="$RUN_AGAIN"
|
RUN="$RUN_AGAIN"
|
||||||
@@ -104,44 +113,37 @@ function Batch
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function Usage
|
function Usage {
|
||||||
{
|
echo "$PROGRAM $PROGRAM_BUILD"
|
||||||
echo "$PROGRAM $PROGRAM_BUILD"
|
echo $AUTHOR
|
||||||
echo $AUTHOR
|
echo $CONTACT
|
||||||
echo $CONTACT
|
echo ""
|
||||||
echo ""
|
echo "Batch script to sequentially run osync or obackup instances and rerun failed ones."
|
||||||
echo "Batch script to sequentially run obackup instances and rerun failed ones."
|
echo "Usage: $SUBPROGRAM-batch.sh [OPTIONS]"
|
||||||
echo "Usage: obackup-batch.sh [OPTIONS]"
|
echo ""
|
||||||
echo ""
|
echo "[OPTIONS]"
|
||||||
echo "[OPTIONS]"
|
echo "--path=/path/to/conf Path to osync / obackup conf files, defaults to /etc/osync or /etc/obackup"
|
||||||
echo "--path=/path/to/conf Path to obackup conf files, defaults to /etc/obackup"
|
|
||||||
echo "--max-reruns=X Number of runs max for failed instances, (defaults to 3)"
|
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)"
|
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 obackup without honoring conf file defined timeouts"
|
echo "--no-maxtime Run osync / obackup without honoring conf file defined timeouts"
|
||||||
echo "--dry Will run obackup without actually doing anything; just testing"
|
echo "--dry Will run osync / obackup without actually doing anything; just testing"
|
||||||
echo "--silent Will run obackup without any output to stdout, used for cron jobs"
|
echo "--silent Will run osync / obackup without any output to stdout, used for cron jobs"
|
||||||
echo "--verbose Increases output"
|
echo "--verbose Increases output"
|
||||||
exit 128
|
exit 128
|
||||||
}
|
}
|
||||||
|
|
||||||
silent=0
|
|
||||||
dry=0
|
|
||||||
verbose=0
|
|
||||||
opts=""
|
opts=""
|
||||||
for i in "$@"
|
for i in "$@"
|
||||||
do
|
do
|
||||||
case $i in
|
case $i in
|
||||||
--silent)
|
--silent)
|
||||||
silent=1
|
|
||||||
opts=$opts" --silent"
|
opts=$opts" --silent"
|
||||||
;;
|
;;
|
||||||
--dry)
|
--dry)
|
||||||
dry=1
|
|
||||||
opts=$opts" --dry"
|
opts=$opts" --dry"
|
||||||
;;
|
;;
|
||||||
--verbose)
|
--verbose)
|
||||||
verbose=1
|
opts=$opts" --verbose"
|
||||||
opts=$opts" --verbose"
|
|
||||||
;;
|
;;
|
||||||
--no-maxtime)
|
--no-maxtime)
|
||||||
opts=$opts" --no-maxtime"
|
opts=$opts" --no-maxtime"
|
||||||
@@ -159,12 +161,12 @@ do
|
|||||||
Usage
|
Usage
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
Log "Unknown param '$i'"
|
Logger "Unknown param '$i'" "CRITICAL"
|
||||||
Usage
|
Usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
CheckEnvironment
|
CheckEnvironment
|
||||||
Log "$(date) Obackup batch run"
|
Logger "$(date) $SUBPROGRAM batch run" "NOTICE"
|
||||||
Batch
|
Batch
|
||||||
|
|||||||
3400
obackup.sh
3400
obackup.sh
File diff suppressed because it is too large
Load Diff
@@ -1,95 +1,94 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
##### Osync ssh command filter build 2015070203
|
##### osync / obackup ssh command filter
|
||||||
##### This script should be located in /usr/local/bin in the remote system to sync / backup
|
##### 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)
|
##### Obackup needed commands: rsync find du mysql mysqldump (sudo)
|
||||||
##### Osync needed commands: rsync find du echo mkdir rm if df (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 ;;
|
||||||
|
"echo")
|
||||||
|
Go ;;
|
||||||
"find")
|
"find")
|
||||||
Go ;;
|
Go ;;
|
||||||
"du")
|
"du")
|
||||||
Go ;;
|
Go ;;
|
||||||
"mysql")
|
"mkdir")
|
||||||
Go ;;
|
Go ;;
|
||||||
"mysqldump")
|
"rm")
|
||||||
|
Go ;;
|
||||||
|
"df")
|
||||||
|
Go ;;
|
||||||
|
"mv")
|
||||||
Go ;;
|
Go ;;
|
||||||
"$CMD1")
|
"$CMD1")
|
||||||
if [ "$CMD1" != "" ]
|
if [ "$CMD1" != "" ]; then
|
||||||
then
|
Go
|
||||||
Go ;;
|
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
"$CMD2")
|
"$CMD2")
|
||||||
if [ "$CMD2" != "" ]
|
if [ "$CMD2" != "" ]; then
|
||||||
then
|
Go
|
||||||
Go ;;
|
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
"$CMD3")
|
"$CMD3")
|
||||||
if [ "$CMD3" != "" ]
|
if [ "$CMD3" != "" ]; then
|
||||||
then
|
Go
|
||||||
Go ;;
|
|
||||||
fi
|
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 mysql"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]; then
|
||||||
then
|
Go
|
||||||
Go
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]; then
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mysqldump"* ]]
|
Go
|
||||||
then
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]; then
|
||||||
Go
|
Go
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]]; then
|
||||||
then
|
Go
|
||||||
if [ "$CMD1" != "" ]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]; then
|
||||||
then
|
Go
|
||||||
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then
|
||||||
|
if [ "$CMD1" != "" ]; then
|
||||||
Go
|
Go
|
||||||
fi
|
fi
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]; then
|
||||||
then
|
if [ "$CMD2" != "" ]; then
|
||||||
if [ "$CMD2" != "" ]
|
|
||||||
then
|
|
||||||
Go
|
Go
|
||||||
fi
|
fi
|
||||||
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]
|
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]; then
|
||||||
then
|
if [ "$CMD3" != "" ]; then
|
||||||
if [ "$CMD3" != "" ]
|
|
||||||
then
|
|
||||||
Go
|
Go
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
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