Project

General

Profile

Backup Setup » History » Version 5

Jon Goldberg, 03/01/2018 08:20 PM

1 1 Jon Goldberg
# Backup Setup
2
3
## Overview
4
5
For a server to be backed up to Megaphone Tech's standards, all of the following must be true:
6
7
-   The backup must happen at least daily.
8
-   The backup must be tested (and testable) to ensure its validity.
9
-   The backup must be encrypted in transit and at rest. 
10
-   If the backup resides on a server outside of our control, the data must be encrypted such that those controlling the server can not read the data.
11
-   At least one copy of the backup must be in a separate geographical location from the original data.
12
-   Databases must be backed up using a database dump tool and stored in a backed-up area of the filesystem.
13
-   The backup should be monitored for both successes and failure.  Alerts should be generated for failed backups, and for backups that don't run.
14
15
To accomplish this, we use a modified copy of [backupninja](https://0xacab.org/riseuplabs/backupninja) to manage the backups.  It reports into our centralized [[Icinga2]] monitoring.
16
The preferred back-end for backups is [borgbackup](https://borgbackup.readthedocs.io/en/stable/), which provides for validity testing and client-side encryption.
17
18 5 Jon Goldberg
## Ansible
19
* Assign the server to a group with the `backupninja` role.
20 1 Jon Goldberg
21 5 Jon Goldberg
## Step-by-step (manual) guide
22 1 Jon Goldberg
23 5 Jon Goldberg
{{collapse
24
25 1 Jon Goldberg
**Note:** This entire guide assumes you're running as *root* on all
26
servers during setup.
27
28
### Icinga Server setup
29
30
-   Get the API User password for the "backupninja" user from `/etc/icinga2/conf.d/api-users.conf`.  This is `ICINGA2_API_PASSWORD`, below.
31
-   Edit the appropriate host conf file (in `/etc/icinga2/conf.d/hosts` to include the line:
32
33
```
34
has_backupninja: true
35
```
36
37
-   Also note the exact name of the `Host` object on line 1 of the file.  This is `ICINGA2_HOSTNAME` below.
38
-   Run `service icinga2 checkconfig && service icinga2 reload` for your change to take effect.
39
40
### Monitored Server setup
41
42
-   Install backupninja and borg.
43
44
```bash
45
#Ubuntu 16.04+
46
apt install backupninja borgbackup
47
#Debian Jessie
48
apt install backupninja
49
apt install -t jessie-backports borgbackup
50
#CentOS 7.3
51
#ensure epel repo is enabled
52
yum install backupninja borgbackup
53
```
54
55
-   If you're using MySQL 5.7+, you can't export the `information_schema` table.  There's a proposed patch for backupninja to exclude it, which you should apply:
56
57
```bash
58
cd /usr/share/backupninja/
59 4 Joseph Lacey
wget -O mysql.patch https://gist.githubusercontent.com/MegaphoneJon/94543829a2dfd6b3ed216b646afb0e8f/raw/abe58456b57eb123a1cf0023adb92ad2fa890cb1/backupninja%2520MySQL%25205.7%2520support
60 1 Jon Goldberg
#Ignore "patch unexpectedly ends in middle of line" warning
61
patch -p0 < mysql.patch
62
rm mysql.patch mysql.orig
63
```
64
65
-   Append this to the end of `/usr/sbin/backupninja`:
66 4 Joseph Lacey
    <https://gist.github.com/MegaphoneJon/322a4fea5707013433d9763972e4d414>
67 1 Jon Goldberg
-   Set up a local borg repo.
68
69
```bash
70
# Generate a password locally with a password generator like pwgen.
71
borg init /opt/borg
72
```
73
74
-   Set up a remote borg repo on rsync.net.
75
76
```bash
77
# Copy the root user's public key to rsync.net's authorized_keys
78
# If no key exists, create one with no passphrase
79
# Source: http://www.rsync.net/resources/howto/ssh_keys.html
80 2 Jon Goldberg
cat ~/.ssh/id_rsa.pub | ssh 8139@usw-s008.rsync.net 'dd of=.ssh/authorized_keys oflag=append conv=notrunc'
81 1 Jon Goldberg
82
# Generate a password locally with a password generator like pwgen.
83
# Replace "lava" with the name of the borg repo you'd like to create.
84 2 Jon Goldberg
borg init 8139@usw-s008.rsync.net:lava --remote-path=/usr/local/bin/borg1/borg1
85 1 Jon Goldberg
```
86
87
-   Put a set of standard configuration files in `/etc/backup.d`.
88
89
```bash
90
cd /etc/backup.d
91 4 Joseph Lacey
wget https://raw.githubusercontent.com/MegaphoneJon/backupninja_configs/master/10-info.sys
92
wget https://raw.githubusercontent.com/MegaphoneJon/backupninja_configs/master/30-databases.mysql
93
wget https://raw.githubusercontent.com/MegaphoneJon/backupninja_configs/master/50-borg-local.sh
94
wget https://raw.githubusercontent.com/MegaphoneJon/backupninja_configs/master/60-borg-remote.sh
95 1 Jon Goldberg
chmod 600 *
96
```
97
98
-   Edit the backupninja config(s) for borg to set the repository name and passphrase.
99 3 Jon Goldberg
    -   e.g. local repository is `/opt/borg` and remote repository is `8139@usw-s008.rsync.net:orange`
100 1 Jon Goldberg
-   Add to /etc/backupninja.conf:
101
102
```bash
103
ICINGA2_API_USER=backupninja
104
ICINGA2_SERVER_ADDRESS=orange.megaphonetech.com
105
ICINGA2_API_PORT=5665
106
ICINGA2_API_PASSWORD=<see above>
107
ICINGA2_HOSTNAME=<see above>
108
```
109
110
### Document
111
112
-   Update the [internal CRM server list](https://crm.megaphonetech.com/server-list) to reflect the correct backup method.
113
-   Record the borg passphrase(s) in the password manager.  This is very important; otherwise the backup is unrecoverable.
114 5 Jon Goldberg
}}