2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
|\_
|
|
|
|
B A C K U P N I N J A /()/
|
|
|
|
`\|
|
2017-02-17 09:07:24 +01:00
|
|
|
|
2005-10-27 01:05:26 +02:00
|
|
|
a silent flower blossom death strike to lost data.
|
|
|
|
|
|
|
|
Backupninja allows you to coordinate system backup by dropping a few
|
2017-02-17 09:17:16 +01:00
|
|
|
simple configuration files into `/etc/backup.d/`. Most programs you
|
2005-10-27 01:05:26 +02:00
|
|
|
might use for making backups don't have their own configuration file
|
|
|
|
format. Backupninja provides a centralized way to configure and
|
2017-02-17 09:07:24 +01:00
|
|
|
coordinate many different backup utilities.
|
2005-10-27 01:05:26 +02:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
# Features
|
|
|
|
|
2017-02-17 09:22:03 +01:00
|
|
|
- easy to read ini style configuration files
|
|
|
|
- you can drop in scripts to handle new types of backups
|
2005-10-27 01:05:26 +02:00
|
|
|
- backup actions can be scheduled
|
|
|
|
- you can choose when status report emails are mailed to you
|
2017-02-17 09:22:03 +01:00
|
|
|
(always, on warning, on error, never)
|
2005-10-27 01:05:26 +02:00
|
|
|
- console-based wizard (ninjahelper) makes it easy to create
|
2017-02-17 09:22:03 +01:00
|
|
|
backup action configuration files
|
|
|
|
- passwords are never sent via the command line to helper programs
|
2017-02-17 09:17:16 +01:00
|
|
|
- works with [Linux-Vservers](http://linux-vserver.org/)
|
|
|
|
|
|
|
|
# Backup types
|
2017-02-17 09:07:24 +01:00
|
|
|
|
2017-02-17 09:22:03 +01:00
|
|
|
- secure, remote, incremental filesytem backup (via rdiff-backup)
|
2005-10-27 01:05:26 +02:00
|
|
|
incremental data is compressed. permissions are retained even
|
2017-02-17 09:22:03 +01:00
|
|
|
with an unpriviledged backup user
|
|
|
|
- backup of mysql databases (via mysqlhotcopy and mysqldump)
|
2005-10-27 01:05:26 +02:00
|
|
|
- basic system and hardware info
|
2017-02-17 09:22:03 +01:00
|
|
|
- encrypted remote backups (via duplicity)
|
|
|
|
- backup of subversion repositories
|
2005-10-27 01:05:26 +02:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
# Options
|
|
|
|
|
2005-10-27 01:05:26 +02:00
|
|
|
The following options are available:
|
2017-02-17 09:17:16 +01:00
|
|
|
|
|
|
|
- `-h`, `--help`: this usage message
|
|
|
|
- `-d`, `--debug`: run in debug mode, where all log messages are
|
2017-02-17 09:22:03 +01:00
|
|
|
output to the current shell
|
2017-02-17 09:17:16 +01:00
|
|
|
- `-f`, `--conffile FILE`: use FILE for the main configuration
|
|
|
|
instead of `/etc/backupninja.conf`
|
|
|
|
- `-t`, `--test`: test run mode. This will test if the backup could
|
|
|
|
run, without actually preforming any backups. For example, it will
|
|
|
|
attempt to authenticate or test that ssh keys are set correctly.
|
|
|
|
- `-n`, `--now`: perform actions now, instead of when they might
|
|
|
|
be scheduled. No output will be created unless also run with -d.
|
|
|
|
- `--run FILE`: runs the specified action `FILE` (e.g. one of the
|
|
|
|
`/etc/backup.d/` files). Also puts backupninja in debug mode.
|
|
|
|
|
|
|
|
ninjahelper
|
2010-01-27 23:45:21 +01:00
|
|
|
===========
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
ninjahelper is an additional script which will walk you through the process of
|
2010-01-27 23:45:21 +01:00
|
|
|
configuring backupninja. Ninjahelper has a menu driven curses based interface
|
2017-02-17 09:07:24 +01:00
|
|
|
(using dialog).
|
2010-01-27 23:45:21 +01:00
|
|
|
|
|
|
|
To add an additional 'wizard' to ninjahelper, follow these steps:
|
|
|
|
|
2017-02-17 09:22:03 +01:00
|
|
|
1. To add a helper for the handler "blue", create the file
|
2017-02-17 09:17:16 +01:00
|
|
|
`blue.helper` in the directory where the handlers live.
|
|
|
|
(ie `/usr/share/backupninja`).
|
|
|
|
|
2017-02-17 09:22:03 +01:00
|
|
|
2. Next, you need to add your helper to the global `HELPERS` variable
|
2017-02-17 09:17:16 +01:00
|
|
|
and define the main function for your helper (the function name
|
|
|
|
is always `<helper>_wizard`). for example, `blue.helper`:
|
2010-01-27 23:45:21 +01:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
HELPERS="$HELPERS blue:description_of_this_helper"
|
|
|
|
blue_wizard() {
|
|
|
|
... do work here ...
|
|
|
|
}
|
2010-01-27 23:45:21 +01:00
|
|
|
|
2017-02-17 09:22:03 +01:00
|
|
|
3. Look at the existing helpers to see how they are written. Try to re-use
|
2017-02-17 09:17:16 +01:00
|
|
|
functions, such as the dialog functions that are defined in `easydialog.sh`,
|
|
|
|
or the vserver functions defined in `lib/vserver`.
|
2010-01-27 23:45:21 +01:00
|
|
|
|
2017-02-17 09:22:03 +01:00
|
|
|
4. Test, re-test, and test again. Try to break the helper by going backwards,
|
2017-02-17 09:17:16 +01:00
|
|
|
try to think like someone who has no idea how to configure your handler
|
|
|
|
would think, try to make your helper as simple as possible. Walk like a cat,
|
|
|
|
become your shadow, don't let your senses betray you.
|
2010-01-27 23:45:21 +01:00
|
|
|
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Configuration files
|
2005-10-27 01:05:26 +02:00
|
|
|
===================
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
The general configuration file is `/etc/backupninja.conf`. In this file
|
2005-10-27 01:05:26 +02:00
|
|
|
you can set the log level and change the default directory locations.
|
2017-02-17 09:17:16 +01:00
|
|
|
You can force a different general configuration file with `backupninja
|
|
|
|
-f /path/to/conf`.
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
To preform the actual backup, backupninja processes each configuration
|
2017-02-17 09:17:16 +01:00
|
|
|
file in `/etc/backup.d` according to the file's suffix:
|
2017-02-17 09:07:24 +01:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
- `.sh`: run this file as a shell script.
|
|
|
|
- `.rdiff`: filesystem backup (using rdiff-backup)
|
|
|
|
- `.dup`: filesystem backup (using duplicity)
|
|
|
|
- `.mysql`: backup mysql databases
|
|
|
|
- `.pgsql`: backup PostgreSQL databases
|
|
|
|
- `.sys`: general hardware, partition, and system reports.
|
|
|
|
- `.svn`: backup subversion repositories
|
|
|
|
- `.maildir`: incrementally backup maildirs (very specialized)
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
Support for additional configuration types can be added by dropping
|
2017-02-17 09:17:16 +01:00
|
|
|
bash scripts with the name of the suffix into `/usr/share/backupninja`.
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
The configuration files are processed in alphabetical order. However,
|
2017-02-17 09:07:24 +01:00
|
|
|
it is suggested that you name the config files in "sysvinit style."
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
00-disabled.pgsql
|
|
|
|
10-runthisfirst.sh
|
|
|
|
20-runthisnext.mysql
|
|
|
|
90-runthislast.rdiff
|
|
|
|
|
|
|
|
Typically, you will put a `.rdiff` config file last, so that any
|
2005-10-27 01:05:26 +02:00
|
|
|
database dumps you make are included in the filesystem backup.
|
|
|
|
Configurations files with names beginning with 0 (zero) or ending with
|
2017-02-17 09:17:16 +01:00
|
|
|
`.disabled` (preferred method) are skipped.
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
Unless otherwise specified, the config file format is "ini style."
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
# this is a comment
|
|
|
|
|
|
|
|
[fishes]
|
|
|
|
fish = red
|
|
|
|
fish = blue
|
|
|
|
|
|
|
|
[fruit]
|
|
|
|
apple = yes
|
|
|
|
pear = no thanks \
|
|
|
|
i will not have a pear.
|
|
|
|
|
|
|
|
Scheduling
|
2005-10-27 01:05:26 +02:00
|
|
|
==========
|
|
|
|
|
|
|
|
By default, each configuration file is processed everyday at 01:00 (1
|
|
|
|
AM). This can be changed by specifying the 'when' option in a config
|
|
|
|
file.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
when = sundays at 02:00
|
|
|
|
when = 30th at 22
|
|
|
|
when = 30 at 22:00
|
|
|
|
when = everyday at 01 <-- the default
|
|
|
|
when = Tuesday at 05:00
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
A configuration file will be processed at the time(s) specified by the
|
2017-02-17 09:17:16 +01:00
|
|
|
`when` option. If multiple `when` options are present, then they all
|
2005-10-27 01:05:26 +02:00
|
|
|
apply. If two configurations files are scheduled to run in the same
|
|
|
|
hour, then we fall back on the alphabetical ordering specified above.
|
|
|
|
If two configurations files are scheduled close to one another in
|
|
|
|
time, it is possible to have multiple copies of backupninja running if
|
|
|
|
the first instance is not finished before the next one starts.
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Make sure that you put the `when` option before any sections in your
|
2005-10-27 01:05:26 +02:00
|
|
|
configuration file.
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
These values for `when` are equivalent:
|
2005-10-27 01:05:26 +02:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
when = tuesday at 05:30
|
|
|
|
when = TUESDAYS at 05
|
2005-10-27 01:05:26 +02:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
These values for `when` are invalid:
|
2017-02-17 09:07:24 +01:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
when = tuesday at 2am
|
|
|
|
when = tuesday at 2
|
|
|
|
when = tues at 02
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Real world usage
|
2005-10-27 01:05:26 +02:00
|
|
|
================
|
|
|
|
|
|
|
|
Backupninja can be used to implement whatever backup strategy you
|
|
|
|
choose. It is intended, however, to be used like so:
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
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`.
|
2017-02-17 09:07:24 +01:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
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.
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
There are many different backup strategies out there, including "pull
|
|
|
|
style", magnetic tape, rsync + hard links, etc. We believe that the
|
2017-02-17 09:17:16 +01:00
|
|
|
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;
|
|
|
|
3. rdiff-backup is more space efficient and featureful than using
|
|
|
|
rsync + hard links.
|
2005-10-27 01:05:26 +02:00
|
|
|
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
SSH keys
|
2005-10-27 01:05:26 +02:00
|
|
|
========
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
root@srchost# ssh-keygen -t rsa -b 4096
|
|
|
|
root@srchost# ssh-copy-id -i /root/.ssh/id_rsa.pub backup@desthost
|
2005-10-27 01:05:26 +02:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Now, you should be able to ssh from user `root` on `srchost` to
|
|
|
|
user `backup` on `desthost` without specifying a password.
|
2005-10-27 01:05:26 +02:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Note: when prompted for a password by `ssh-keygen`, just leave it
|
2005-10-27 01:05:26 +02:00
|
|
|
blank by hitting return.
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
The included helper program `ninjahelper` will walk you through creating
|
2005-10-27 01:05:26 +02:00
|
|
|
an rdiff-backup configuration, and will set up the ssh keys for you.
|
|
|
|
|
2010-01-09 23:14:17 +01:00
|
|
|
|
|
|
|
Amazon Simple Storage Service (S3)
|
|
|
|
==================================
|
|
|
|
|
|
|
|
Duplicity can store backups on Amazon S3 buckets, taking care of encryption.
|
|
|
|
Since it performs incremental backups it minimizes the number of request per
|
|
|
|
operation therefore reducing the costs. The boto Python interface to Amazon
|
2017-02-17 09:17:16 +01:00
|
|
|
Web Services is needed to use duplicity with S3 (Debian package: `python-boto`).
|
2010-01-09 23:14:17 +01:00
|
|
|
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Vservers
|
2005-10-27 01:05:26 +02:00
|
|
|
========
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
If you are using [Linux-Vservers](http://linux-vserver.org/) there are some
|
2017-02-17 09:07:24 +01:00
|
|
|
special capabilities that different handlers have to make vserver
|
2005-12-25 04:31:36 +01:00
|
|
|
backups easier.
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Set the variable `vservers` to be `yes` in `/etc/backupninja.conf` and see the
|
2005-10-27 01:05:26 +02:00
|
|
|
example configuration files for each handler to configure the vserver specific
|
|
|
|
variables.
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
Additional vserver variables that can be configured in `/etc/backupninja.conf`,
|
2005-12-25 04:31:36 +01:00
|
|
|
but they probably don't need to be changed:
|
2005-10-27 01:05:26 +02:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
- `VSERVERINFO` (default: `/usr/sbin/vserver-info`)
|
|
|
|
- `VSERVER` (default: `/usr/sbin/vserver`)
|
|
|
|
- `VROOTDIR` (default: `$VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'`)
|
2012-02-25 14:18:30 +01:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
.sh configuration files
|
2012-02-25 14:18:30 +01:00
|
|
|
=======================
|
|
|
|
|
|
|
|
Shell jobs may use the following features:
|
|
|
|
|
|
|
|
* logging and control flow functions:
|
2017-02-17 09:17:16 +01:00
|
|
|
`halt`, `fatal`, `error`, `warning`, `info`, `debug`, `passthru`.
|
2012-02-25 14:18:30 +01:00
|
|
|
All such functions take a list of strings a parameters.
|
|
|
|
Those strings are passed to whatever logging mechanism is enabled,
|
|
|
|
and colored if relevant.
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
* Using `exit N` is useless, and has unspecified consequences.
|
2012-02-25 14:18:30 +01:00
|
|
|
Just don't do it.
|
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
* `when=TIME` works as documented above; at may also be written
|
|
|
|
`when = TIME`.
|
2012-02-25 14:18:30 +01:00
|
|
|
|
2017-02-17 09:17:16 +01:00
|
|
|
* The `$BACKUPNINJA_DEBUG` environment variable is set when
|
|
|
|
backupninja is invoked with the `-d` option.
|