mirror of
https://0xacab.org/liberate/backupninja.git
synced 2024-11-09 12:22:40 +01:00
moved all to trunk
This commit is contained in:
commit
ef78e14b29
147
README
Normal file
147
README
Normal file
@ -0,0 +1,147 @@
|
||||
|
||||
|\_
|
||||
B A C K U P N I N J A /()/
|
||||
`\|
|
||||
|
||||
a silent flower blossom death strike to lost data.
|
||||
|
||||
Backupninja allows you to coordinate system backup by dropping a few
|
||||
simple configuration files into /etc/backup.d/. Most programs you
|
||||
might use for making backups don't have their own configuration file
|
||||
format. Backupninja provides a centralized way to configure and
|
||||
coordinate many different backup utilities.
|
||||
|
||||
Features:
|
||||
- easy to read ini style configuration files.
|
||||
- secure, remote, incremental filesytem backup (via rdiff-backup).
|
||||
incremental data is compressed. permissions are retained even
|
||||
with an unpriviledged backup user.
|
||||
- backup of mysql databases (via mysqlhotcopy and mysqldump).
|
||||
- backup of ldap databases (via slapcat and ldapsearch).
|
||||
- passwords are never sent via the command line to helper programs.
|
||||
- you can drop in scripts to handle new types of backups.
|
||||
|
||||
The following options are available:
|
||||
-h This help message
|
||||
-d Run in debug mode, where all log messages are output
|
||||
to the current shell.
|
||||
-f <file> Use <file> for the main configuration instead of
|
||||
/etc/backupninja.conf
|
||||
|
||||
CONFIGURATION FILES
|
||||
===================
|
||||
|
||||
The general configuration file is /etc/backupninja.conf. In this file
|
||||
you can set the log level and change the default directory locations.
|
||||
You can force a different general configuration file with "backupninja
|
||||
-f /path/to/conf".
|
||||
|
||||
To preform the actual backup, backupninja processes each configuration
|
||||
file in /etc/backup.d according to the file's suffix:
|
||||
|
||||
.sh -- run this file as a shell script.
|
||||
.rdiff -- this is a configuration for rdiff-backup
|
||||
.maildir -- this is a configuration to backup maildirs
|
||||
.mysql -- mysql backup configuration
|
||||
.ldap -- ldap backup configuration
|
||||
|
||||
Support for additional configuration types can be added by dropping
|
||||
bash scripts with the name of the suffix into /usr/share/backupninja.
|
||||
|
||||
The configuration files are processed in alphabetical order. However,
|
||||
it is suggested that you name the config files in "sysvinit style."
|
||||
|
||||
For example:
|
||||
00-disabled.ldap
|
||||
10-runthisfirst.sh
|
||||
20-runthisnext.mysql
|
||||
90-runthislast.rdiff
|
||||
|
||||
Typically, you will put a '.rdiff' config file last, so that any
|
||||
database dumps you make are included in the filesystem backup.
|
||||
Configurations files which begin with 0 (zero) are skipped.
|
||||
|
||||
Unless otherwise specified, the config file format is "ini style."
|
||||
|
||||
For example:
|
||||
|
||||
# this is a comment
|
||||
|
||||
[fishes]
|
||||
fish = red
|
||||
fish = blue
|
||||
|
||||
[fruit]
|
||||
apple = yes
|
||||
pear = no thanks \
|
||||
i will not have a pear.
|
||||
|
||||
REAL WORLD USAGE
|
||||
================
|
||||
|
||||
Backupninja can be used to impliment whatever backup strategy you
|
||||
choose. It is intended, however, to be used like so:
|
||||
|
||||
(1) First, databases are safely copied or exported to /var/backups.
|
||||
Typically, you cannot make a file backup of a database while it
|
||||
is in use, hence the need to use special tools to make a safe copy
|
||||
or export into /var/backups.
|
||||
|
||||
(2) Then, vital parts of the file system, including /var/backups, are
|
||||
nightly pushed to a remote, off-site, hard disk (using
|
||||
rdiff-backup). The local user is root, but the remote user is not
|
||||
priviledged. Hopefully, the remote filesystem is encrypted.
|
||||
|
||||
There are many different backup strategies out there, including "pull
|
||||
style", magnetic tape, rsync + hard links, etc. We believe that the
|
||||
strategy outlined above is the way to go because: (1) hard disks are
|
||||
very cheap these days, (2) pull style backups are no good, because then
|
||||
the backup server must have root on the production server, and (3)
|
||||
rdiff-backup is more space efficient and featureful than using rsync +
|
||||
hard links.
|
||||
|
||||
SSH KEYS
|
||||
========
|
||||
|
||||
In order for rdiff-backup to sync files over ssh unattended, you must
|
||||
create ssh keys on the source server and copy the public key to the
|
||||
remote user's authorized keys file. For example:
|
||||
|
||||
root@srchost# ssh-keygen -t dsa
|
||||
root@srchost# ssh-copy-id -i /root/.ssh/id_dsa.pub backup@desthost
|
||||
|
||||
Now, you should be able to ssh from user 'root' on srchost to
|
||||
user 'backup' on desthost without specifying a password.
|
||||
|
||||
Note: when prompted for a password by ssh-keygen, just leave it
|
||||
blank by hitting return.
|
||||
|
||||
INSTALLATION
|
||||
============
|
||||
|
||||
Requirements:
|
||||
apt-get install bash gawk
|
||||
|
||||
Suggested:
|
||||
apt-get install rdiff-backup gzip
|
||||
|
||||
Files:
|
||||
/usr/sbin/backupninja -- main script
|
||||
/etc/cron.d/backupninja -- runs main script nightly
|
||||
/etc/logrotate.d/backupninja -- rotates backupninja.log
|
||||
/etc/backup.d/ -- directory for configuration files
|
||||
/etc/backupninja.conf -- general options
|
||||
/usr/share/backupninja -- handler scripts which do the actual work
|
||||
|
||||
Installation:
|
||||
There is no install script, but you just need to move files to the
|
||||
correct locations. All files should be owned by root.
|
||||
|
||||
# tar xvzf backupninja.tar.gz
|
||||
# cd backupninja
|
||||
# mv backupninja /usr/sbin/backupninja
|
||||
# mv etc/logrotate.d/backupninja /etc/logrotate.d/backupninja
|
||||
# mv etc/cron.d/backupninja /etc/cron.d/backupninja
|
||||
# mkdir /etc/backup.d/
|
||||
# mv etc/backupninja.conf /etc/backupninja.conf
|
||||
# mv handlers /usr/share/backupninja
|
271
backupninja
Executable file
271
backupninja
Executable file
@ -0,0 +1,271 @@
|
||||
#!/bin/bash
|
||||
# |\_
|
||||
# B A C K U P N I N J A /()/
|
||||
# `\|
|
||||
#
|
||||
# Copyright (C) 2004 riseup.net -- property is theft.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
|
||||
#####################################################
|
||||
## DEFAULTS
|
||||
|
||||
DEBUG=${DEBUG:=0}
|
||||
CONFFILE="/etc/backupninja.conf"
|
||||
USECOLOURS=1
|
||||
|
||||
#####################################################
|
||||
## FUNCTIONS
|
||||
|
||||
function setupcolors() {
|
||||
if [ "$USECOLOURS" == 1 ]
|
||||
then
|
||||
BLUE="\033[34;01m"
|
||||
GREEN="\033[32;01m"
|
||||
YELLOW="\033[33;01m"
|
||||
PURPLE="\033[35;01m"
|
||||
RED="\033[31;01m"
|
||||
OFF="\033[0m"
|
||||
CYAN="\033[36;01m"
|
||||
fi
|
||||
}
|
||||
|
||||
function run() {
|
||||
RUNERROR=0
|
||||
debug 0 "$@"
|
||||
returnstring=`$@ 2>&1`
|
||||
RUNERROR=$?
|
||||
RUNERRORS=$[RUNERRORS+RUNERROR]
|
||||
if [ "$RUNERROR" != 0 ]; then
|
||||
debug 3 "Exitcode $RUNERROR returned when running: $@"
|
||||
debug 3 "$returnstring"
|
||||
else
|
||||
debug 0 "$returnstring"
|
||||
fi
|
||||
return $RUNERROR
|
||||
}
|
||||
|
||||
# We have the following debug levels:
|
||||
# 0 - debug - blue
|
||||
# 1 - normal messages - green
|
||||
# 2 - warnings - yellow
|
||||
# 3 - errors - orange
|
||||
# 4 - fatal - red
|
||||
# First variable passed is the error level, all others are printed
|
||||
|
||||
# if 1, echo out all warnings, errors, or fatal
|
||||
# used to capture output from handlers
|
||||
echo_debug_msg=0
|
||||
|
||||
function debug() {
|
||||
|
||||
[ ${#@} -gt 1 ] || return
|
||||
|
||||
TYPES=(Debug Info Warning Error Fatal)
|
||||
COLOURS=($BLUE $GREEN $YELLOW $RED $PURPLE)
|
||||
type=$1
|
||||
colour=${COLOURS[$type]}
|
||||
shift
|
||||
print=$[4-type]
|
||||
if [ "$print" -lt "$loglevel" -o "$DEBUG" == 1 ]; then
|
||||
if [ -z "$logfile" ]; then
|
||||
echo -e "${colour}${TYPES[$type]}: $@${OFF}" >&2
|
||||
else
|
||||
if [ "$DEBUG" == 1 -o "$type" == 4 ]; then
|
||||
echo -e "${colour}${TYPES[$type]}: $@${OFF}" >&2
|
||||
fi
|
||||
echo -e "${colour}${TYPES[$type]}: $@${OFF}" >> $logfile
|
||||
fi
|
||||
fi
|
||||
if [ "$echo_debug_msg" != "0" -a "$type" -gt "1" ]; then
|
||||
echo -e "${TYPES[$type]}: $@"
|
||||
fi
|
||||
}
|
||||
|
||||
function fatal() {
|
||||
debug 4 "$@"
|
||||
exit 2
|
||||
}
|
||||
|
||||
msgcount=0
|
||||
function msg {
|
||||
messages[$msgcount]=$1
|
||||
let "msgcount += 1"
|
||||
}
|
||||
|
||||
function setfile() {
|
||||
CURRENT_CONF_FILE=$1
|
||||
}
|
||||
|
||||
function setsection() {
|
||||
CURRENT_SECTION=$1
|
||||
}
|
||||
|
||||
#
|
||||
# sets a global var with name equal to $1
|
||||
# to the value of the configuration parameter $1
|
||||
# $2 is the default.
|
||||
#
|
||||
|
||||
function getconf() {
|
||||
CURRENT_PARAM=$1
|
||||
ret=`awk -f $scriptdir/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE`
|
||||
# if nothing is returned, set the default
|
||||
if [ "$ret" == "" -a "$2" != "" ]; then
|
||||
ret="$2"
|
||||
fi
|
||||
|
||||
# replace * with %, so that it is not globbed.
|
||||
ret="${ret//\\*/__star__}"
|
||||
|
||||
# this is weird, but single quotes are needed to
|
||||
# allow for returned values with spaces. $ret is still expanded
|
||||
# because it is in an 'eval' statement.
|
||||
eval $1='$ret'
|
||||
}
|
||||
|
||||
|
||||
#####################################################
|
||||
## MAIN
|
||||
|
||||
## process command line options
|
||||
|
||||
if [ "$1" == "--help" ]; then
|
||||
HELP=1;DEBUG=1;loglevel=4
|
||||
else
|
||||
while getopts h,f:,d,t option
|
||||
do
|
||||
case "$option" in
|
||||
h) HELP=1;DEBUG=1;loglevel=4;;
|
||||
d) DEBUG=1;loglevel=4;;
|
||||
f) CONFFILE="$OPTARG";;
|
||||
t) test=1;DEBUG=1;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
setupcolors
|
||||
|
||||
## Print help
|
||||
|
||||
if [ "$HELP" == 1 ]; then
|
||||
cat << EOF
|
||||
$0 usage:
|
||||
This script allows you to coordinate system backup by dropping a few
|
||||
simple configuration files into /etc/backup.d/. In general, this script
|
||||
is run from a cron job late at night.
|
||||
|
||||
The following options are available:
|
||||
-h This help message
|
||||
-d Run in debug mode, where all log messages are output to the current shell.
|
||||
-f <file> Use <file> for the main configuration instead of /etc/backupninja.conf
|
||||
-t Run in test mode, no actions are actually taken.
|
||||
|
||||
When using colored output, there are:
|
||||
EOF
|
||||
debug 0 "Debugging info (when run with -d)"
|
||||
debug 1 "Informational messages (verbosity level 4)"
|
||||
debug 2 "Warnings (verbosity level 3 and up)"
|
||||
debug 3 "Errors (verbosity level 2 and up)"
|
||||
debug 4 "Fatal, halting errors (always shown)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
## Load and confirm basic configuration values
|
||||
|
||||
# bootstrap
|
||||
[ -r "$CONFFILE" ] || fatal "Configuration file $CONFFILE not found."
|
||||
scriptdir=`grep scriptdirectory $CONFFILE | awk '{print $3}'`
|
||||
[ -n "$scriptdir" ] || fatal "Cound not find entry 'scriptdirectory' in $CONFFILE."
|
||||
[ -d "$scriptdir" ] || fatal "Script directory $scriptdir not found."
|
||||
setfile $CONFFILE
|
||||
|
||||
# get global config options (second param is the default)
|
||||
getconf configdirectory /etc/backup.d
|
||||
getconf reportemail
|
||||
getconf loglevel 3
|
||||
getconf logfile /var/log/backupninja.log
|
||||
getconf SLAPCAT /usr/sbin/slapcat
|
||||
getconf RDIFFBACKUP /usr/bin/rdiff-backup
|
||||
getconf MYSQL /usr/bin/mysql
|
||||
getconf MYSQLHOTCOPY /usr/bin/mysqlhotcopy
|
||||
getconf MYSQLDUMP /usr/bin/mysqldump
|
||||
getconf GZIP /bin/gzip
|
||||
|
||||
[ -d "$configdirectory" ] || fatal "Configuration directory '$configdirectory' not found."
|
||||
[ `id -u` == "0" ] || fatal "Can only be run as root"
|
||||
|
||||
## Process each configuration file
|
||||
|
||||
debug 1 "====== starting at "`date`" ======"
|
||||
|
||||
# by default, don't make files which are world or group readable.
|
||||
umask 077
|
||||
|
||||
for file in $configdirectory/*; do
|
||||
perms=`ls -ld $file`
|
||||
perms=${perms:4:6}
|
||||
if [ "$perms" != "------" ]; then
|
||||
fatal "Configuration files must not be group or world readable! Dying on file $file"
|
||||
fi
|
||||
if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then
|
||||
fatal "Configuration files must be owned by root! Dying on file $file"
|
||||
fi
|
||||
suffix="${file##*.}"
|
||||
base=`basename $file`
|
||||
if [ "${base:0:1}" == "0" ]; then
|
||||
debug 1 "Skipping $file"
|
||||
continue
|
||||
else
|
||||
debug 1 "Processing $file"
|
||||
fi
|
||||
|
||||
if [ -e "$scriptdir/$suffix" ]; then
|
||||
setfile $file
|
||||
echo_debug_msg=1
|
||||
ret=`( . $scriptdir/$suffix $file )`
|
||||
retcode="$?"
|
||||
warnings=`echo $ret | grep -e "^Warning: " | wc -l`
|
||||
errors=`echo $ret | grep -e "^Error: \|^Fatal: " | wc -l`
|
||||
if [ $errors != 0 ]; then
|
||||
msg "*failed* -- $file"
|
||||
error="$error\n== errors from $file ==\n\n$ret\n"
|
||||
elif [ $warnings != 0 ]; then
|
||||
msg "*warning* -- $file"
|
||||
error="$error\n== warnings from $file ==\n\n$ret\n"
|
||||
elif [ $retcode == 0 ]; then
|
||||
msg "success -- $file"
|
||||
else
|
||||
msg "unknown -- $file"
|
||||
fi
|
||||
echo_debug_msg=0
|
||||
else
|
||||
debug 3 "Can't process file '$file': no handler script for suffix '$suffix'"
|
||||
msg "*missing handler* -- $file"
|
||||
fi
|
||||
done
|
||||
|
||||
## mail the messages to the report address
|
||||
|
||||
if [ "$reportemail" != "" ]; then
|
||||
hostname=`hostname`
|
||||
{
|
||||
for ((i=0; i < ${#messages[@]} ; i++)); do
|
||||
echo ${messages[$i]}
|
||||
done
|
||||
echo -e "$error"
|
||||
} | mail $reportemail -s "backupninja: $hostname"
|
||||
fi
|
||||
|
||||
debug 1 "====== finished at "`date`" ======"
|
||||
|
||||
############################################################
|
38
changelog
Normal file
38
changelog
Normal file
@ -0,0 +1,38 @@
|
||||
version 0.3.4
|
||||
fixed numerical variable quoting compatibility with older wc
|
||||
|
||||
version 0.3.3
|
||||
'*' (asterisk) works now in rdiff config files
|
||||
works now with gawk as well as mawk
|
||||
many bug fixes to ldap handler
|
||||
paths to helper scripts can be configured in global config
|
||||
does not require /usr/bin/stat
|
||||
|
||||
version 0.3.2
|
||||
handler scripts are no longer executable (to comply with debian policy)
|
||||
handler error and warning messages are sent with the notify email
|
||||
|
||||
version 0.3.1
|
||||
added ldap handler
|
||||
moved sh support to a handler script
|
||||
add test mode, where no action is taken.
|
||||
added --help
|
||||
force only root can read /etc/backup.d/*
|
||||
fixed missing equals symbols in example.rdiff
|
||||
changed backupninja executable to be /usr/sbin rather than /usr/bin
|
||||
|
||||
version 0.3
|
||||
** IMPORTANT ** all config files are now ini style, not apache style
|
||||
rewrote all scripts in bash for portability
|
||||
added drop-in backupninja lib directory (/usr/share/backupninja)
|
||||
all scripts are now run as root
|
||||
|
||||
version 0.2
|
||||
move distribution folder ./cron.d to ./etc/cron.d
|
||||
fixed bug: removed printr of excludes (!)
|
||||
added support for changing the user/group in rdiff sources.
|
||||
added support for .mysql config files.
|
||||
|
||||
version 0.1
|
||||
initial release Fri Oct 8 17:25:00 PDT 2004
|
||||
|
20
etc/backup.d/example.ldap
Normal file
20
etc/backup.d/example.ldap
Normal file
@ -0,0 +1,20 @@
|
||||
##
|
||||
## configuration file for openldap backups
|
||||
##
|
||||
## The LDIFs generated are suitable for use with slapadd. As the
|
||||
## entries are in database order, not superior first order, they
|
||||
## cannot be loaded with ldapadd without being reordered.
|
||||
##
|
||||
|
||||
## backupdir (default /var/backups/ldap): the destination for the backups
|
||||
# backupdir = /var/backups/ldap
|
||||
|
||||
## conf (default /etc/ldap/slapd.conf): the location of the slapd.conf file.
|
||||
# conf = /etc/ldap/slapd.conf
|
||||
|
||||
## databases (default all): either a space separated list of database
|
||||
## numbers or prefixes, or the keyword 'all'.
|
||||
# databases = all
|
||||
|
||||
## compress (default yes): if set to yes, ldif exports are gzipped.
|
||||
# compress = yes
|
47
etc/backup.d/example.mysql
Normal file
47
etc/backup.d/example.mysql
Normal file
@ -0,0 +1,47 @@
|
||||
dbusername = root
|
||||
dbpassword = test
|
||||
dbhost = localhost
|
||||
databases = all
|
||||
backupdir = /var/backups/mysql
|
||||
hotcopy = yes
|
||||
sqldump = yes
|
||||
compress = yes
|
||||
|
||||
#
|
||||
# user = <user>
|
||||
# Run mysql commands as 'user'. A valid .my.cnf must exist with a
|
||||
# database username and password in the user's home directory.
|
||||
# If this option is not set, use dbusername and dbpassword instead.
|
||||
#
|
||||
# dbusername = <dbuser>
|
||||
# The user must have access to the databases specified later.
|
||||
# Use this option if not using the 'user' option.
|
||||
#
|
||||
# dbpassword = <dbpass>
|
||||
# The password. this password will NOT be passed on the command line
|
||||
# and is not readable using "ps aux". make sure that this file is not
|
||||
# world readable. Use this to specify the password in this config file
|
||||
# instead of ~user/.my.cnf.
|
||||
#
|
||||
# dbhost = <host>
|
||||
# only localhost works right now.
|
||||
#
|
||||
# databases = < all | db1 db2 db3 >
|
||||
# which databases to backup. should either be the word 'all' or a
|
||||
# comma seperated list of database names.
|
||||
#
|
||||
# backupdir = < path/to/destination >
|
||||
# where to dump the backups. hotcopy backups will be in a subdirectory 'hotcopy' and
|
||||
# sqldump backups will be in a subdirectory 'sqldump'
|
||||
#
|
||||
# hotcopy = < yes | no >
|
||||
# make a backup of the actual database binary files using mysqlhotcopy.
|
||||
#
|
||||
# sqldump = < yes | no >
|
||||
# make a backup using mysqldump. this creates text files with sql commands
|
||||
# sufficient to recontruct the database.
|
||||
#
|
||||
# compress = < yes | no >
|
||||
# if yes, compress the sqldump output.
|
||||
#
|
||||
|
52
etc/backup.d/example.rdiff
Normal file
52
etc/backup.d/example.rdiff
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
######################################################
|
||||
## source section
|
||||
## (where the files to be backed up are coming from)
|
||||
|
||||
[source]
|
||||
|
||||
# an optional subdirectory below 'directory' (see [dest])
|
||||
label = thishostname
|
||||
|
||||
# only local type is currently supported
|
||||
type = local
|
||||
|
||||
# how many days of data to keep
|
||||
keep = 185
|
||||
|
||||
# files to include in the backup
|
||||
# (supports globbing with '*')
|
||||
include = /var/spool/cron/crontabs
|
||||
include = /var/backups
|
||||
include = /etc
|
||||
include = /root
|
||||
include = /home
|
||||
include = /usr/local/bin
|
||||
include = /usr/local/sbin
|
||||
include = /var/lib/dpkg/status
|
||||
include = /var/lib/dpkg/status-old
|
||||
|
||||
# files to exclude from the backup
|
||||
# (supports globbing with '*')
|
||||
#exclude = /home/*/.gnupg
|
||||
|
||||
######################################################
|
||||
## destination section
|
||||
## (where the files are copied to)
|
||||
|
||||
[dest]
|
||||
|
||||
# only remote type is currently supported
|
||||
type = remote
|
||||
|
||||
# the machine which will receive the backups
|
||||
host = backuphost
|
||||
|
||||
# put the backups under this directory
|
||||
directory = /backups
|
||||
|
||||
# make the files owned by this user
|
||||
# note: you must be able to ssh backupuser@backhost
|
||||
# without specifying a password
|
||||
user = backupuser
|
||||
|
2
etc/backup.d/example.sh
Normal file
2
etc/backup.d/example.sh
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
dpkg --get-selections > /var/backups/dpkg-selections.txt
|
30
etc/backupninja.conf
Normal file
30
etc/backupninja.conf
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# |\_
|
||||
# B A C K U P N I N J A /()/
|
||||
# `\|
|
||||
# main configuration file
|
||||
#
|
||||
|
||||
# how verbose to make the logs
|
||||
# 5 -- Debugging messages (and below)
|
||||
# 4 -- Informational messages (and below)
|
||||
# 3 -- Warnings (and below)
|
||||
# 2 -- Errors (and below)
|
||||
# 1 -- Fatal errors (only)
|
||||
loglevel = 4
|
||||
|
||||
# send a summary of backup status to this email address
|
||||
# reportemail = root
|
||||
|
||||
#######################################################
|
||||
# for most installations, the defaults below are good #
|
||||
#######################################################
|
||||
|
||||
# where to log:
|
||||
logfile = /var/log/backupninja.log
|
||||
|
||||
# directory where all the backup configuration files live
|
||||
configdirectory = /etc/backup.d
|
||||
|
||||
# where backupninja helper scripts are found
|
||||
scriptdirectory = /usr/share/backupninja
|
2
etc/cron.d/backupninja
Normal file
2
etc/cron.d/backupninja
Normal file
@ -0,0 +1,2 @@
|
||||
# cron job for backupninja (once a day)
|
||||
00 01 * * * root if [ -x /usr/sbin/backupninja -a -f /etc/backupninja.conf ]; then /usr/sbin/backupninja; fi
|
6
etc/logrotate.d/backupninja
Normal file
6
etc/logrotate.d/backupninja
Normal file
@ -0,0 +1,6 @@
|
||||
/var/log/backupninja.log {
|
||||
rotate 6
|
||||
monthly
|
||||
compress
|
||||
missingok
|
||||
}
|
340
gpl.txt
Normal file
340
gpl.txt
Normal file
@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
69
handlers/ldap
Normal file
69
handlers/ldap
Normal file
@ -0,0 +1,69 @@
|
||||
#
|
||||
# openldap backup handler script for backupninja
|
||||
#
|
||||
|
||||
getconf backupdir /var/backups/ldap
|
||||
getconf conf /etc/ldap/slapd.conf
|
||||
getconf databases all
|
||||
getconf compress yes
|
||||
getconf ldif yes
|
||||
getconf hotcopy no
|
||||
|
||||
# hot copy is not yet supported
|
||||
|
||||
status="ok"
|
||||
|
||||
[ -f $conf ] || fatal "slapd config file ($conf) not found"
|
||||
[ -d $backupdir ] || mkdir -p $backupdir
|
||||
[ -d $backupdir ] || fatal "Backup directory '$backupdir'"
|
||||
|
||||
dbsuffixes=(`awk 'BEGIN {OFS=":"} /[:space:]*^database[:space:]*\w*/ {db=$2}; /^[:space:]*suffix[:space:]*\w*/ {if (db=="bdb"||db=="ldbm") print db,$2}' $conf|sed -e 's/[" ]//g'`)
|
||||
|
||||
## LDIF DUMP
|
||||
|
||||
if [ "$ldif" == "yes" ]; then
|
||||
dumpdir="$backupdir"
|
||||
[ -d $dumpdir ] || mkdir -p $dumpdir
|
||||
|
||||
if [ "$databases" == 'all' ]; then
|
||||
dbcount=`grep '^database' $conf | wc -l`
|
||||
let "dbcount = dbcount - 1"
|
||||
databases=`seq 0 $dbcount`;
|
||||
fi
|
||||
|
||||
for db in $databases; do
|
||||
if [ `expr index "$dbnum" "="` == "0" ]; then
|
||||
# db is a number, get the suffix.
|
||||
dbsuffix=${dbsuffixes[$db]/*:/}
|
||||
else
|
||||
dbsuffix=$db
|
||||
fi
|
||||
# some databases don't have suffix (like monitor), skip these
|
||||
if [ "$dbsuffix" == "" ]; then
|
||||
continue;
|
||||
fi
|
||||
touch $dumpdir/$dbsuffix.ldif
|
||||
if [ ! -f $dumpdir/$dbsuffix.ldif ]; then
|
||||
fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif"
|
||||
fi
|
||||
execstr="$SLAPCAT -f $conf -b $dbsuffix -l $dumpdir/$dbsuffix.ldif"
|
||||
debug 0 "$execstr"
|
||||
if [ ! $test ]; then
|
||||
output=`$execstr`
|
||||
code=$?
|
||||
if [ "$code" == "0" ]; then
|
||||
debug 0 $output
|
||||
debug 1 "Successfully finished ldif export of $dbsuffix"
|
||||
else
|
||||
debug 2 $output
|
||||
debug 2 "Failed ldif export of $dbsuffix"
|
||||
fi
|
||||
if [ "$compress" == "yes" ]; then
|
||||
output=`$GZIP -f "$dumpdir/$dbsuffix.ldif" 2>&1`
|
||||
debug 0 $output
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
return 0
|
133
handlers/mysql
Normal file
133
handlers/mysql
Normal file
@ -0,0 +1,133 @@
|
||||
#
|
||||
# mysql handler script for backupninja
|
||||
#
|
||||
|
||||
getconf backupdir /var/backups/mysql
|
||||
getconf databases all
|
||||
getconf compress yes
|
||||
getconf dbusername
|
||||
getconf dbpassword
|
||||
getconf dbhost localhost
|
||||
getconf hotcopy no
|
||||
getconf sqldump no
|
||||
getconf user root
|
||||
|
||||
# create backup dirs
|
||||
|
||||
[ -d $backupdir ] || mkdir -p $backupdir
|
||||
[ -d $backupdir ] || fatal "Backup directory '$backupdir'"
|
||||
hotdir="$backupdir/hotcopy"
|
||||
dumpdir="$backupdir/sqldump"
|
||||
[ "$sqldump" == "no" -o -d $dumpdir ] || mkdir -p $dumpdir
|
||||
[ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
|
||||
|
||||
# create .my.cnf
|
||||
# (we do this because we don't want to have to specify the password on the command line
|
||||
# because then anyone would be able to see it with a 'ps aux'. instead, we create a
|
||||
# temporary ~/.my.cnf in root's home directory).
|
||||
|
||||
if [ "$dbusername" != "" ]; then
|
||||
home=`grep '^root' /etc/passwd | awk -F: '{print $6}'`
|
||||
[ -d $home ] || fatal "Can't find root's home directory ($home)."
|
||||
mycnf="$home/.my.cnf"
|
||||
if [ -f $mycnf ]; then
|
||||
# rename temporarily
|
||||
tmpcnf="$home/my.cnf.disable"
|
||||
debug 0 "mv $mycnf $tmpcnf"
|
||||
mv $mycnf $tmpcnf
|
||||
fi
|
||||
oldmask=`umask`
|
||||
umask 077
|
||||
cat > $mycnf <<EOF
|
||||
# auto generated backupninja mysql conf
|
||||
[mysql]
|
||||
user=$dbusername
|
||||
password=$dbpassword
|
||||
|
||||
[mysqldump]
|
||||
user=$dbusername
|
||||
password=$dbpassword
|
||||
|
||||
[mysqlhotcopy]
|
||||
user=$dbusername
|
||||
password=$dbpassword
|
||||
EOF
|
||||
umask $oldmask
|
||||
fi
|
||||
|
||||
## HOT COPY
|
||||
|
||||
if [ "$hotcopy" == "yes" ]; then
|
||||
if [ "$databases" == "all" ]; then
|
||||
execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
||||
debug 0 "su $user -c '$execstr'"
|
||||
if [ ! $test ]; then
|
||||
output=`su $user -c "$execstr" 2>&1`
|
||||
code=$?
|
||||
if [ "$code" == "0" ]; then
|
||||
debug 0 $output
|
||||
debug 1 "Successfully finished hotcopy of all mysql databases"
|
||||
else
|
||||
debug 2 $output
|
||||
debug 2 "Failed to hotcopy all mysql databases"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
for db in $databases; do
|
||||
execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
|
||||
debug 0 "su $user -c '$execstr'"
|
||||
if [ ! $test ]; then
|
||||
output=`su $user -c "$execstr" 2>&1`
|
||||
code=$?
|
||||
if [ "$code" == "0" ]; then
|
||||
debug 0 $output
|
||||
debug 1 "Successfully finished hotcopy of mysql database $db"
|
||||
else
|
||||
debug 2 $output
|
||||
debug 2 "Failed to hotcopy mysql database $db"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
## SQL DUMP
|
||||
|
||||
if [ "$sqldump" == "yes" ]; then
|
||||
if [ "$databases" == "all" ]; then
|
||||
databases=`echo 'show databases' | su $user -c "$MYSQL" | grep -v Database`
|
||||
fi
|
||||
|
||||
for db in $databases; do
|
||||
execstr="$MYSQLDUMP --lock-tables --complete-insert --add-drop-table --quick --quote-names $db > $dumpdir/${db}.sql"
|
||||
debug 0 "su $user -c '$execstr'"
|
||||
if [ ! $test ]; then
|
||||
output=`su $user -c "$execstr" 2>&1`
|
||||
code=$?
|
||||
if [ "$code" == "0" ]; then
|
||||
debug 0 $output
|
||||
debug 1 "Successfully finished dump of mysql database $db"
|
||||
else
|
||||
debug 2 $output
|
||||
debug 2 "Failed to dump mysql databases $db"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$compress" == "yes" ]; then
|
||||
output=`$GZIP -f $dumpdir/*.sql 2>&1`
|
||||
debug 0 $output
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$dbusername" != "" ]; then
|
||||
## clean up tmp config file
|
||||
debug 0 "rm $mycnf"
|
||||
rm $mycnf
|
||||
if [ -f "$tmpcnf" ]; then
|
||||
debug 0 "mv $tmpcnf $mycnf"
|
||||
mv $tmpcnf $mycnf
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
130
handlers/parseini
Normal file
130
handlers/parseini
Normal file
@ -0,0 +1,130 @@
|
||||
#
|
||||
# parseini --- parses 'ini' style configuration files.
|
||||
#
|
||||
# Usage:
|
||||
# awk -f parseini S=<section> P=<param> <ini file>
|
||||
#
|
||||
# if section is an empty string, then we use the default section
|
||||
#
|
||||
# example ini file:
|
||||
#
|
||||
# fruit = apple
|
||||
# fruit = pear
|
||||
# multiline = this is a multiline \
|
||||
# parameter
|
||||
#
|
||||
# # this is a comment
|
||||
#
|
||||
# [colors]
|
||||
# red = yes
|
||||
# green = no
|
||||
# blue = maybe
|
||||
#
|
||||
# [ocean]
|
||||
# fish = red
|
||||
# fish = blue
|
||||
#
|
||||
# example usage:
|
||||
# > awk -f parseini S=ocean P=fish testfile.ini
|
||||
# would return:
|
||||
# red
|
||||
# blue
|
||||
#
|
||||
|
||||
BEGIN {
|
||||
readlines = 1
|
||||
implied = 1
|
||||
}
|
||||
|
||||
# remove lines starting with #, but not #!
|
||||
/^#[^!]/ {next}
|
||||
|
||||
# skip blank
|
||||
/^[ \r\t]*$/ {next}
|
||||
|
||||
# we want to read the lines of the matched section
|
||||
# and disable for other sections
|
||||
/^\[.+\][ \r\t]*$/ {
|
||||
continueline = 0
|
||||
if (S && implied) {
|
||||
nline = 0
|
||||
implied = 0
|
||||
}
|
||||
if (S && match($0, "^\\[" S "\\][ \n]*")) {
|
||||
# we found the section, so start reading.
|
||||
readlines = 1
|
||||
}
|
||||
else {
|
||||
# no section, so stop reading lines
|
||||
if (readlines) readlines = 0
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
# when reading, store lines.
|
||||
|
||||
{
|
||||
if (!readlines) next
|
||||
line[nline++] = $0
|
||||
if ($0 ~ /\\[ \r\t]*$/)
|
||||
continueline = 1
|
||||
else
|
||||
continueline = 0
|
||||
}
|
||||
|
||||
# process the read lines lines, matching parameters
|
||||
|
||||
END {
|
||||
# if section is set but implied is still true
|
||||
# then we never found the section, so use everything
|
||||
if (S && implied) {
|
||||
nline = 0
|
||||
}
|
||||
|
||||
# if have P then find P in read lines and get values
|
||||
if (P) {
|
||||
MATCH = "^[ \r\t]*" P "[ \r\t]*="
|
||||
continueline = 0
|
||||
for (x = 0; x < nline; ++x) {
|
||||
v = line[x]
|
||||
if (continueline) {
|
||||
sub(/[ \r\t]+$/, "", v)
|
||||
if (v ~ /\\$/) {
|
||||
v = substr(v, 1, length(v)-1)
|
||||
sub(/[ \r\t]+$/, "", v)
|
||||
}
|
||||
if (v) value[nvalue++] = v
|
||||
}
|
||||
else if (v ~ MATCH) {
|
||||
sub(MATCH, "", v)
|
||||
sub(/^[ \r\t]+/, "", v)
|
||||
sub(/[ \r\t]+$/, "", v)
|
||||
if (v ~ /\\$/) {
|
||||
continueline = 1
|
||||
v = substr(v, 1, length(v)-1)
|
||||
sub(/[ \r\t]+$/, "", v)
|
||||
}
|
||||
if (v) value[nvalue++] = v
|
||||
}
|
||||
}
|
||||
# copy parameter definition to output array
|
||||
nline = nvalue
|
||||
for (x = 0; x < nvalue; ++x)
|
||||
line[x] = value[x]
|
||||
}
|
||||
|
||||
# trim all leading & trailing whitespace;
|
||||
# except for leading whitespace in continuation lines,
|
||||
|
||||
for (x = 0; x < nline; ++x) {
|
||||
sub(/^[ \r\t]+/, "", line[x])
|
||||
sub(/[ \r\t]+$/, "", line[x])
|
||||
}
|
||||
|
||||
# output the final result
|
||||
for (x = 0; x < nline; ++x)
|
||||
print line[x]
|
||||
|
||||
if (nline) exit 0
|
||||
else exit 1
|
||||
}
|
116
handlers/rdiff
Normal file
116
handlers/rdiff
Normal file
@ -0,0 +1,116 @@
|
||||
#
|
||||
# rdiff-backup handler script for backupninja
|
||||
# requires rdiff-backup
|
||||
#
|
||||
|
||||
setsection source
|
||||
getconf type; sourcetype=$type
|
||||
getconf label
|
||||
getconf user; sourceuser=$user
|
||||
getconf keep
|
||||
getconf include
|
||||
getconf exclude
|
||||
|
||||
### DESTINATION ###
|
||||
|
||||
setsection dest
|
||||
getconf directory; destdir=$directory
|
||||
# strip trailing /
|
||||
destdir=${destdir%/}
|
||||
getconf type; desttype=$type
|
||||
getconf user; destuser=$user
|
||||
getconf host; desthost=$host
|
||||
|
||||
[ "$destdir" != "" ] || fatal "Destination directory not set"
|
||||
[ "$desttype" == "remote" ] || fatal "Only remote destinations are supported"
|
||||
|
||||
# see if we can login
|
||||
debug 0 "su $sourceuser -c \"ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'\""
|
||||
if [ ! $test ]; then
|
||||
result=`su $sourceuser -c "ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'" 2>&1`
|
||||
if [ "$result" != "1" ]; then
|
||||
fatal "Can't connect to $desthost as $destuser."
|
||||
fi
|
||||
fi
|
||||
|
||||
# see that rdiff-backup has the same version as here
|
||||
debug 0 "su $sourceuser -c \"ssh $desthost -l $destuser '$RDIFFBACKUP -V'\""
|
||||
if [ ! $test ]; then
|
||||
remoteversion=`su $sourceuser -c "ssh $desthost -l $destuser '$RDIFFBACKUP -V'" 2>&1`
|
||||
localversion=`$RDIFFBACKUP -V`
|
||||
if [ "$remoteversion" != "$localversion" ]; then
|
||||
fatal "rdiff-backup does not have the same version on this computer and the backup server."
|
||||
fi
|
||||
fi
|
||||
|
||||
execstr_serverpart="$destuser@$desthost::$destdir/$label"
|
||||
|
||||
### SOURCE ###
|
||||
|
||||
[ "$label" != "" ] || fatal "Source missing label"
|
||||
[ "$sourcetype" == "local" ] || fatal "Only local source type supported"
|
||||
[ "$include" != "" ] || fatal "No source includes specified"
|
||||
|
||||
execstr_clientpart="/"
|
||||
|
||||
## REMOVE OLD BACKUPS
|
||||
|
||||
if [ "$keep" -gt "0" ]; then
|
||||
removestr="rdiff-backup --force --remove-older-than ${keep}D "
|
||||
if [ "$desttype" == "remote" ]; then
|
||||
removestr="${removestr}${destuser}@${desthost}::"
|
||||
fi
|
||||
removestr="${removestr}${destdir}/${label}";
|
||||
|
||||
debug 0 "su $sourceuser -c '$removestr'"
|
||||
if [ ! $test ]; then
|
||||
output=`su $sourceuser -c "$removestr" 2>&1`
|
||||
code=$?
|
||||
if [ "$code" == "0" ]; then
|
||||
debug 0 $output
|
||||
debug 1 "Removing backups older than $keep days succeeded."
|
||||
else
|
||||
debug 2 $output
|
||||
debug 2 "Failed removing backups older than $keep."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
## EXECUTE ##
|
||||
|
||||
execstr="$RDIFFBACKUP --print-statistics "
|
||||
|
||||
# TODO: order the includes and excludes
|
||||
|
||||
# excludes
|
||||
for i in $exclude; do
|
||||
str="${i//__star__/*}"
|
||||
execstr="${execstr}--exclude '$str' "
|
||||
done
|
||||
|
||||
# includes
|
||||
for i in $include; do
|
||||
str="${i//__star__/*}"
|
||||
execstr="${execstr}--include '$str' "
|
||||
done
|
||||
|
||||
# exclude everything else
|
||||
execstr="${execstr}--exclude '/*' "
|
||||
|
||||
# include client-part and server-part
|
||||
execstr="${execstr}$execstr_clientpart $execstr_serverpart"
|
||||
|
||||
debug 0 "su $sourceuser -c '$execstr'"
|
||||
if [ ! $test ]; then
|
||||
output=`su $sourceuser -c "$execstr" 2>&1`
|
||||
code=$?
|
||||
if [ "$code" == "0" ]; then
|
||||
debug 0 $output
|
||||
debug 1 "Successfully finished backing up source '$label'"
|
||||
else
|
||||
debug 2 $output
|
||||
debug 2 "Failed backup up source '$label'"
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
6
handlers/sh
Normal file
6
handlers/sh
Normal file
@ -0,0 +1,6 @@
|
||||
#
|
||||
# shell script handler for backupninja
|
||||
# runs the file /etc/backup.d/scriptname.sh
|
||||
#
|
||||
|
||||
[ $test ] || ( . $1 )
|
Loading…
Reference in New Issue
Block a user