README.md 2.37 KB
Newer Older
Nils Knappmeier's avatar
docs  
Nils Knappmeier committed
1 2
# Hot-Backup for Hetzner-Servers with LVM-snapshots

3
This setup utilizes LVM-snapshots to get a consistent live-backup from a [Hetzner](https:// hetzner.com) server.
Nils Knappmeier's avatar
docs  
Nils Knappmeier committed
4

Nils Knappmeier's avatar
Nils Knappmeier committed
5

6 7 8 9 10 11 12
Requirements

* This setup is in use on Ubuntu. Not tested on CentOS.
* The `cifs-utils`-package needs to be installed

## fstab

Nils Knappmeier's avatar
Nils Knappmeier committed
13 14 15 16 17 18 19 20 21 22 23 24

```fstab
proc /proc proc defaults 0 0
/dev/md/0 none swap sw 0 0
/dev/md/1 /boot ext3 defaults 0 0
/dev/vgmain/lvmain / ext4 defaults 0 0
//<username>.your-backup.de/backup /mnt/backup-server       cifs    iocharset=utf8,rw,credentials=/etc/backup-credentials.txt,uid=0,gid=0,file_mode=0660,dir_mode=0770 0       0

```

`dev/vgmain/lvmain` is the partition of which the backup is created. There should be space available for a snapshot in the volume group.

25 26 27 28 29 30 31 32

The backup-medium is mount via CIFS (see [the documentation at hetzner.com](https://wiki.hetzner.de/index.php/Backup/en#SAMBA.2FCIFS)). The file `/etc/backup-credentials.txt` must have mode `0600` and the contents

```
username=...
password=...
```

Nils Knappmeier's avatar
docs  
Nils Knappmeier committed
33 34 35 36 37
## Going from plain SoftRAID-1 (mdadm) to SoftRAID-1 with LVM on the root partition.

The [Hetzner](hetzner.com) system I started with did not have lvm enabled by default. I am not sure if that was my decision or just the template 
Have a look at ["Setting up LVM on a system with only a RAID1"](raid1-to-lvm.md)

Nils Knappmeier's avatar
Nils Knappmeier committed
38 39 40 41 42 43 44
## Setup 

* Install backup2l and the cifs-utils.
  `sudo apt-get install -y backup2l cifs-utils`
* Make sure the fstab-line of the `/mnt/backup-server` (see above) is part of your fstab.
* The file `/etc/backup-credentials.txt` should contain username and passwort of the backup-store (see https://wiki.hetzner.de/index.php/Backup/en#SAMBA.2FCIFS for details) and have `0600`-permissions.
* Copy the file [backup2l.conf](backup2l.conf) to `/etc/backup2l.conf`
45
* Copy the file [run-backup.sh](run-backup.sh) to `/etc/cron.daily/zz-run-backup`
Nils Knappmeier's avatar
Nils Knappmeier committed
46 47 48 49 50 51 52 53 54 55 56

## Process

The following actions will be executed by `run-backup.sh`

* Create a new LVM snapshot of `/dev/vgmain/lvmain`
* Mount this snapshot on `/media/lvmain-snapshot`
* **Create a backup** by running `backup2l` chrooted to `media/lvmain-snapshot`
* Remove all mounts below (or equal) `/media/lvmain-snapshot`
* Remove the LVM snapshot

Nils Knappmeier's avatar
docs  
Nils Knappmeier committed
57 58
The last two steps are implemented in a `trap` so that they are also executed, if the backup is aborted. They are also executed before everything else to cleanup left-over snapshot volumes in case of previous failures.

Nils Knappmeier's avatar
Nils Knappmeier committed
59