Rewrite Readme and man page

This commit is contained in:
Victor LABORIE 2017-01-13 20:29:36 +01:00
parent e7d3d7cdca
commit 2fa0842224
6 changed files with 305 additions and 249 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*.swp
debian/*
!debian/changelog
!debian/compat

80
README.md Normal file
View file

@ -0,0 +1,80 @@
Bkctld (aka evobackup)
=========
Bkctld is a shell script to create and manage a backup server which will
handle the backup of many servers (clients). Licence is AGPLv3.
The main principle uses SSH chroot (called "jails" in the FreeBSD
world) for each client to backup. Each client will upload his data every day
using rsync in his chroot (using root account).
Incrementals are stored outside of the chroot using hard links or btrfs snapshots.
(So incrementals are not available for clients). Using this method we can keep tens
of backup of each client securely and not using too much space.
Backup server
************
Server 1 ------ SSH/rsync -------> * tcp/2222 *
* *
Server 2 ------ SSH/rsync -------> * tcp/2223 *
************
This method uses standard tools (ssh, rsync, cp -al, btrfs subvolume). EvoBackup
is used for many years by Evolix for back up each day hundreds of servers which
uses many terabytes of data.
bkctld was test on Debian Jessie. It can be compatible with other Debian version
or derivated distribution like Ubuntu or Debian Wheezy.
A big size volume must be mount on /backup, we recommend usage of **btrfs** for
subvolume and snapshot fonctionnality.
This volume can be encrypted by **luks** for security reason.
## Install
A Debian package is available in Evolix repository
~~~
echo "http://pub.evolix.net" >> /etc/apt/sources.list
apt update
apt install bkctld
~~~
#### Install cron for incremental backup
Edit root crontab
~~~
crontab -e
~~~
Add this ligne
~~~
30 10 * * * /usr/sbin/bkctld inc && /usr/sbin/bkctld rm
~~~
> **Notes :**
> If you want mutiples backups in a day (1 by hour maximum) you can run `bkctld inc` multiples times
> If you want keep incremental backup **for ever**, you just need don't run `bkctld rm`
## Usage
~~~
man bkctld
~~~
#### Client configuration
You can save various systems on evobackup jail : Linux, BSD, Windows, MacOSX. Only prequisites is rsync command.
~~~
rsync -av -e "ssh -p SSH_PORT" /home/ root@SERVER_NAME:/var/backup/home/
~~~
An example script is present in docs/zzz_evobackup, clone evobackup repo and read **CLIENT CONFIGURATION** section of the manual.
~~~
git clone https://vlaborie@forge.evolix.org/evobackup.git
cd evobackup
man ./docs/bkctld.8
~~~

View file

@ -1,25 +0,0 @@
EvoBackup
=========
EvoBackup is a bunch of shell scripts to create a backup server which will
handle the backup of many servers (clients). Licence is GPLv2.
The main principle uses SSH chroot (called "jails" in the FreeBSD
world) for each client to backup. Each client will upload his data every day
using rsync in his chroot (using root account).
Incrementals are stored outside of the chroot using hard links. (So incrementals
are not available for clients). Using this method we can keep tens of backup of
each client securely and not using too much space.
Backup server
************
Server 1 ------ SSH/rsync -------> * tcp/2222 *
* *
Server 2 ------ SSH/rsync -------> * tcp/2223 *
************
This method uses standard tools (ssh, rsync, cp -al). EvoBackup is used for
many years by Evolix for back up each day hundreds of servers which uses many
terabytes of data.
More documentation TODO…

View file

@ -1,205 +0,0 @@
Présentation d'EvoBackup
===
**EvoBackup** est un ensemble de scripts permettant de mettre en place
un service de backups gérant les sauvegardes de plusieurs machines.
Le principe est d'installer des prisons/chroot contenant un service
SSH écoutant sur un port différent dans chaque prison. Chaque serveur
peut ainsi envoyer ses données quotidiennement en "root" via rsync
dans sa propre prison. Les prisons sont ensuite copiées en dehors des
prisons (donc inaccessible par les serveurs) de façon incrémentale
grâce à des "hard links". On peut ainsi conserver des dizaines de
sauvegardes de chaque serveur de façon sécurisé et avec peu de place.
**************************
Serveur 1 ------SSH/rsync ------->* tcp/2222 Serveur *
* de *
Serveur 2 ------SSH/rsync ------->* tcp/2223 Sauvegardes *
**************************
Cette technique de sauvegarde s'appuient sur des technologies
standards. Elle est utilisée depuis plusieurs années par Evolix
pour sauvegarder chaque jour des centaines de serveurs représentant
plusieurs To de données incrémentales.
Evobackup a été testé pour les serveurs sous Debian (Wheezy/Jessie).
Cela peut fonctionner pour d'autres distributions tel Ubuntu.
La documentation se concentre sur une mise en place pour Debian Jessie.
> **Logiciels nécessaires :**
> - OpenSSH
> - Rsync (le daemon rsync n'est pas nécessaire)
> - Le paquet makedev (plus nécessaire depuis Squeeze)
> - Commande "mail" (ou un équivalent) capable d'envoyer
des messages à l'extérieur.
Un volume d'une taille importante doit être monté sur /backup
Pour des raisons de sécurité on pourra chiffrer ce volume.
On créera ensuite les répertoires suivants :
- /backup/jails : pour les prisons
- /backup/incs : pour les copies incrémentales des prisons
- /etc/evobackup : config des fréquences des copies incrémentales
On peut sauvegarder différents systèmes : Linux, BSD, Windows, MacOSX.
L'un des seuls réels prérequis est d'avoir rsync.
Installation EvoBackup côté serveur
===
On récupère les sources via https://forge.evolix.org/projects/evobackup/repository et on mets en place les scripts nécessaires.
```
# git clone https://forge.evolix.org/evobackup.git
# cd evobackup
# ./install.sh
```
> **Notes :**
> - Si l'on veut plusieurs backups dans la journée (1 par heure maximum),
on pourra lancer `bkctld inc` à plusieurs reprises…
Ce qui fonctionnera sous réserve qu'entre temps les données ont bien changés !
> - Si l'on ne veut **jamais** supprimer les backups incrémentaux, on pourra se contenter
de ne jamais lancer la coomande `bkctld rm`.
Si le noyau du serveur est patché avec *GRSEC*, on évitera pas mal
de warnings en positionnant les paramètres Sysctl suivants :
```
# sysctl kernel.grsecurity.chroot_deny_chmod=0
# sysctl kernel.grsecurity.chroot_deny_mknod=0
```
--- **À vérifier** --- Plus nécessaire avec un noyau récent a priori.
Créer une prison
---
Créer la prison :
# bkctld init <hostname>
Changer le port d'écoute (defaut: 2222) :
# bkctld port <hostname> <port>
Autoriser une clé publique :
# bkctld key <hostname> <pubkeyfile>
Lancer la prison :
# bkctld start <hostname>
Vérifier que tout est OK :
# bkctld status <hostname>
− Gestion des sauvegardes incrémentales :
Pour activer les gestions des copies incrémentales,
créer le fichier `/etc/evobackup/$JAIL` contenant par
exemple :
+%Y-%m-%d.-0day
+%Y-%m-%d.-1day
+%Y-%m-%d.-2day
+%Y-%m-%d.-3day
+%Y-%m-01.-0month
+%Y-%m-01.-1month
> **Quelques explications sur cette syntaxe particulière.**
> - Par exemple, la ligne ci-dessous signifie "garder la sauvegarde du
jour actuel" (à toujours mettre sur la première ligne a priori) :
> > `+%Y-%m-%d.-0day`
> - La ligne ci-dessous signifie "garder la sauvegarde d'hier" :
> > `+%Y-%m-%d.-1day`
> - La ligne ci-dessous signifie "garder la sauvegarde du 1er jour du
mois courant" :
> > `+%Y-%m-01.-0month`
>- Toujours le même principe, on peut garder celle du 1er jours du
mois dernier :
> > `+%Y-%m-01.-1month`
Et bien sûr, on peut garder aussi le 15e jour (pour avoir une sauvegarde
toutes les 15 jours, le 1er janvier de chaque année, etc.)
Attention, la création de ce fichier est **obligatoire** pour activer
les copies incrémentales. Si l'on veut garder des copies *advitam aeternam*
sans jamais les supprimer, on se contentera de ne pas lancer le script
`bkctld rm`.
− Copier une prison sur un second serveur :
Dans le cas où l'on dispose de plusieurs serveurs de sauvegarde configurés en
mode nœuds, il est recommandé de créer la prison sur un nœud puis la copier sur l'autre nœud.
On utilisera rsync pour faire ceci.
```
# rsync -av --exclude='var/backup/**' --exclude='proc/**' --exclude='dev/**' \
/backup/jails/$JAIL/ ${AutreNÅ“ud}:/backup/jails/$JAIL/
# rsync -av /etc/evobackup/$JAIL ${AutreNÅ“ud}:/etc/evobackup/
```
Ainsi le second nœud aura exactement la même prison (et même empreinte SSH).
Installation EvoBackup côté client
===
− On récupère les sources via https://forge.evolix.org/projects/evobackup/repository
```
# git clone https://forge.evolix.org/evobackup.git
# cd evobackup
```
− Générer une clé SSH pour l'utilisateur "root" :
# ssh-keygen
> **Notes :**
> - Ne pas la protéger par une passphrase, sauf si un humain
va l'entrer manuellement à chaque sauvegarde effectuée.
> - La clé générée doit être de type RSA et non DSA !!
> **Notes pour les machines sous Windows :**
> - Téléchargez et installer CygWin : http://cygwin.com/setup-x86.exe
> - Choisissez le mirroir http://mirrors.kernel.org
choisissez les paquets "rsync" et "openssh" grâce à la recherche,
ils sont dans la catégorie "Net", vous devez les cocher.
> - Ouvrez CygWin. Dans le terminal, tapez : `ssh-keygen.exe`.
> - La clé générée se trouve dans `C:\cygwin\home\USER\.ssh\`.
− Envoyer le fichier `id_rsa.pub` au responsable du serveur de
sauvegarde, ainsi que l'adresse IP de la machine.
Ou bien reportez-vous à la création d'une prison sur le serveur de sauvegarde.
− Éditer le script de sauvegarde `zzz_evobackup`.
> - `SSH_PORT` Port de la prison SSH correspondante ;
> - `SYSTEME` Linux ou BSD ;
> - `MAIL` Adresse e-mail pour les rapports ;
> - `NODE` Technique utilisée pour « calculer » sur quel nœud faire une sauvegarde.
Utilisée seulement quand on a plusieurs serveurs de sauvegardes.
La valeur par défaut permet de sauvegarder sur le nœud 0 les jours pairs, et
sur le nœud 1 les jours impairs ;
> - Dé-commenter / Ajuster / Ajouter la partie qui sauvegarde les applicatifs MySQL / LDAP / … ;
> - Ajouter ou enlever des exclusions avec `--exclude`.
`$REP` contient les répertoires systèmes ;
> - `root@node$NODE.backup.example.com:/var/backup/` Indiquer l'adresse de votre
serveur de backup.
− Ajouter à la crontab le fichier `zzz_evobackup` pour Linux / BSD :
Pour une sauvegarde quotidienne (conseillé), utilisez le répertoire
`/etc/cron.daily/` (sous Linux) ou `/etc/periodic/daily` (sous FreeBSD).
```
# install -v -m700 zzz_evobackup /etc/cron.daily/
## OU
# install -v -m700 zzz_evobackup /etc/periodic/daily/
```
> **Note :**
> Pour les serveurs sous Windows, vous devrez créer une tâche planifiée avec une
commande "rsync" installé via CygWin.
− Une fois que tout en place au niveau du serveur de sauvegardes,
on doit initier la première connexion et valider l'empreinte SSH du serveur :
# ssh -p <port> <serveur de sauvegardes>

View file

@ -2,85 +2,288 @@
.\" Contact vlaborie@evolix.fr to correct errors or typos.
.TH man 8 "11 Janvier 2017" "1.0" "bkctld man page"
.SH NAME
bkctld \- Tool to manage rsync jail for backup
bkctld - tool to manage evobackup jail
.SH SYNOPSIS
bkctld <command> [<args>]
.SH DESCRIPTION
bkctld is a shell script to create and manage a backup server which will handle the backup of many servers (clients).
.PP
The main principle uses SSH chroot (called "jails" in the FreeBSD world) for each client to backup. Each client will upload his data every day using rsync in his chroot (using root account).
.PP
Incrementals are stored outside of the chroot using hard links or btrfs snapshots.
(So incrementals are not available for clients). Using this method we can keep tens
of backup of each client securely and not using too much space.
.PP
A big size volume must be mount on /backup, we recommend usage of **btrfs** for
subvolume and snapshot fonctionnality.
This volume can be encrypted by **luks** for security reason.
.PP
.SH BKCTLD COMMANDS
bkctld init <jailname>
.RS 4
Init jail <jailname>
Create an evobackup jail.
.RE
.PP
bkctld update <jailname>|all
.RS 4
Update jail <jailname>
Update an evobackup jail or all.
.RE
.PP
bkctld remove <jailname>|all
.RS 4
Remove jail <jailname> or all
Remove an evobackup jail or all.
.RE
.PP
bkctld start <jailname>|all
.RS 4
Start jail <jailname> or all
Start an evobackup jail or all.
.RE
.PP
bkctld stop <jailname>|all
.RS 4
Stop jail <jailname> or all
Stop an evobackup jail or all.
.RE
.PP
bkctld reload <jailname>|all
.RS 4
Reload jail <jailname> or all
Reload an evobackup jail or all.
.RE
.PP
bkctld restart <jailname>|all
.RS 4
Restart jail <jailname> or all
Restart an evobackup jail or all.
.RE
.PP
bkctld sync <jailname>|all
.RS 4
Sync jail <jailname> with $NODE defined in /etc/default/bkctld
Sync an evobackup jail or all.
.RE
.RS 4
Second server was defined by $NODE var in /etc/default/bkctld.
.RE
.PP
bkctld status [<jailname>]
.RS 4
Print status of jail <jailname> or all jails
Print status of all evobackup jail or one jail.
.RE
.PP
bkctld key <jailname> [<keyfile>]
.RS 4
Print or set SSH public key of jail <jailname>
Print or set SSH public key of an evobackup jail.
.RE
.PP
bkctld port <jailname> [<ssh_port>|auto]
.RS 4
Print or set SSH port of jail <jailname>. Auto for user last port + 1
Print or set SSH port of an evobackup jail.
.RE
.RS 4
Auto for use last port + 1.
.RE
.PP
bkctld ip <jailname> [<ip>|all]
.RS 4
Print or set allowed IP of jail <jailname>. All for no IP restriction
Print or set allowed IP of an evobackup jail.
.RE
.RS 4
All for no IP restriction (default).
.RE
.PP
bkctld inc
.RS 4
Make inc of jail <jailname>
Make inc of an evobackup jail.
.RE
.PP
bkctld rm
.RS 4
Remove old inc of jail <jailname>
Remove old inc of an evobackup jail.
.RE
.PP
.SH CONFIGURATION VARS
bkctld configuration was done in /etc/default/bkctld.
.SH REQUIREDS VARS
Requireds vars has default value set in bkctld script. Surcharge them for change default value.
.RE
.PP
CONFDIR
.RS 4
Dir where incremental backup was configured. See INCS CONFIGURATION section for details.
.RE
.RS 4
default : /etc/evobackup
.RE
.PP
JAILDIR
.RS 4
Dir for root dir of jail. BTRFS recommended.
.RE
.RS 4
default : /backup/jails
.RE
.PP
INCDIR
.RS 4
Dir where incremental backup was stocked. BTRFS recommended.
default : /backups/incs
.RE
.PP
TPLDIR
.RS 4
Dir where template file for create jail was stocked.
.RE
.RS 4
default : /usr/share/bkctld
.RE
.PP
LOG_DIR
.RS 4
Emplacement of log directory.
.RE
.RS 4
default : /var/log
.RE
.PP
.SH OPTIONALS VARS
Optionnals vars are no default value. No set them desactivate correspondant fonctionnality.
.RE
.PP
MAIL
.RS 4
Mail address were notification mail will be set.
.RE
.RS 4
Default : no mail notification
.RE
.PP
FIREWALL_RULES
.RS 4
Configuration file were firewall was configured to allow jail access. This file must be sourced by your firewall configuration tool.
.RE
.RS 4
Default : no firewall auto configuration
.SH INCS CONFIGURATION
Incremental backups was configured in $CONFDIR/<jailname>. Some example of syntax.
.RE
.PP
Keep the incrememtal backup of today
.RS 4
+%Y-%m-%d.-0day
.RE
.PP
Keep the incremental backup of yesterday
.RS 4
+%Y-%m-%d.-1day
.RE
.PP
Keep the incremental backup of the first day of this month
.RS 4
+%Y-%m-01.-0month
.RE
.PP
Keep the incremental backup of the first day of last month
.RS 4
+%Y-%m-01.-1month
.RE
.PP
Keep the incremental backup of every 15 days
.RS 4
+%Y-%m-01.-1month
.RE
.RS 4
+%Y-%m-15.-1month
.RE
.PP
Keep the incremental backup of the first january
.RS 4
+%Y-01-01.-1month
.RE
.PP
.PP
Default value : keep incremental of last 4 days and last 2 months. Change default in $TPLDIR/inc.tpl.
+%Y-%m-%d.-0day
+%Y-%m-%d.-1day
+%Y-%m-%d.-2day
+%Y-%m-%d.-3day
+%Y-%m-01.-0month
+%Y-%m-01.-1month
.SH CLIENT CONFIGURATION
You can save various systems on evobackup jail : Linux, BSD, Windows, MacOSX. Only prequisites is rsync command.
.PP
.RS 4
rsync -av -e "ssh -p SSH_PORT" /home/ root@SERVER_NAME:/var/backup/home/
.PP
.RE
You can simply create a shell script which use rsync for backup your's servers. An example script is available in docs/zzz_evobackup for quickstart.
.RE
.PP
This documentation explain how to use this example script.
.PP
Install example script in crontab :
.PP
.RS 4
# For Linux
.RE
.RS 4
install -v -m700 zzz_evobackup /etc/cron.daily/
.PP
# For FreeBSD
.RE
.RS 4
install -v -m700 zzz_evobackup /etc/periodic/daily/
.PP
.RE
Generate an SSH key for root account with no passphrase :
.PP
.RS 4
ssh-keygen
.RE
.PP
Sent /root/.ssh/id_rsa.pub to backup server administrator or read BKCTLD COMMANDS section.
.PP
Edit zzz_evobackup script and update this variables :
.PP
.RS 4
SSH_PORT
.RS 4
Port of corespondant evobackup jail.
.RE
.PP
SYSTEME
.RS 4
Linux or BSD.
.RE
.PP
MAIL
.RS 4
Email address for notification.
.RE
.PP
NODE
.RS 4
Use for alternate between mutiple backup servers.
.RE
.RS 4
Default value permit to save on node0 on pair day and on node1 on impair day.
.RE
.PP
SRV
.RS 4
Adress of your backup serveur.
.RE
.RE
.PP
Uncomment service dump, ex Mysql / LDAP / PostgreQL / ...
.PP
Itiniate SSH connection and validate fingerprint :
.PP
.RS 4
ssh -p SSH_PORT SERVER_NAME
.RE
.PP
Your daily evobackup is in place !
.PP
.SH SEE ALSO
sshd(8), rsync(1), chroot(8)
.SH BUGS
No known bugs.
rsync(1), sshd(8), chroot(8)
.SH AUTHOR
Victor Laborie (vlaborie@evolix.fr)

View file

@ -38,6 +38,8 @@ MAIL=jdoe@example.com
# Variable to choose different backup server with date
NODE=$(expr `date +%d` % 2)
# serveur address for rsync
SRV="node$NODE.backup.example.com"
## We use /home/backup : feel free to use your own dir
mkdir -p -m 700 /home/backup
@ -206,7 +208,7 @@ rsync -avzh --stats --delete --delete-excluded --force --ignore-errors --partial
/home \
/srv \
-e "ssh -p $SSH_PORT" \
root@node$NODE.backup.example.com:/var/backup/ \
root@$SRV:/var/backup/ \
| tail -30 >> /var/log/evobackup.log
FIN=$(/bin/date +"%d-%m-%Y ; %H:%M")