butterbackup/README.md

107 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2019-01-17 10:18:10 +01:00
# butterbackup
2019-01-17 12:48:04 +01:00
A backup solution. A server at your office behind your firewall that pulls data from public servers and saves snapshots.
# On your backup server
Create a partition from free space
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
cfdisk /dev/sda
apt-get install parted
partprobe
apt-get install btrfs-tools
mkfs.btrfs /dev/sdaX
mkdir /backups
mount /dev/sdaX /backups
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
## Mount the partition on boot
Find the UUID of the new partition
2019-01-17 12:50:51 +01:00
`blkid`
2019-01-17 12:48:04 +01:00
Edit /etc/fstab
2019-01-17 12:50:51 +01:00
`UUID=7ef18851-xxxx-yyyy-zzzz-53f7b88b6119 /backups btrfs defaults 0 0`
2019-01-17 12:48:04 +01:00
## Setup butterbackup
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
apt-get install git
cd /opt
2021-06-26 10:00:52 +02:00
git clone https://forja.laloka.org/buttle/ButterBackup.git
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
Instalar python3 en un entorno virtual
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
apt-get install virtualenv
cd /opt/butterbackup
virtualenv venv --python=python3
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
# Setup users
2019-03-13 20:12:23 +01:00
butterbackup runs on the backserver as root. root connects to the public server as user keeper.
2019-01-17 12:48:04 +01:00
We create a user on the public server and copy root@backup_server public key to keeper@public_server authorized_keys
2019-03-13 20:12:23 +01:00
2019-01-17 12:48:04 +01:00
On the public_server
2019-03-13 20:12:23 +01:00
## Create dummy user on public server
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
adduser --disabled-password keeper
mkdir /home/keeper/.ssh
touch /home/keeper/.ssh/authorized_keys
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
## Create root@backup_server ssh keys on the backup_server
2019-01-17 12:50:51 +01:00
`ssh-keygen -t ecdsa -b 521`
2019-01-17 12:48:04 +01:00
And add the new public key to keeper@public_server /home/keeper/.ssh/authorized_keys
Test to see if you can open a session on the public_server
2019-01-17 12:50:51 +01:00
`ssh keeper@public_server`
2019-01-17 12:48:04 +01:00
## Permissions
Perhaps keeper@public_server does not have permission to read everything you want to backup.
2019-03-13 20:12:23 +01:00
Let's say you want to backup /var/www on the public server. You can add the keeper to the www-data group
2019-01-17 12:48:04 +01:00
# Create a config file
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
cd /opt/butterbackup/config
cp example.com my_server_domain_name.com
2019-01-17 12:50:51 +01:00
```
2019-01-17 12:48:04 +01:00
Edit the new config file.
# Make the first copy
You can run butterbackup manually
2019-01-17 12:50:51 +01:00
`/opt/butterbackup/venv/bin/python3 /opt/butterbackup/butterbackup.py my_server_domain_name.com`
# Add an entry to root's crontab
`crontab -e`
2019-01-17 12:48:04 +01:00
2019-01-17 13:03:47 +01:00
You cronjobs might look like this. Where each server has a corresponding `/opt/butterbackup/config` file
```
0 2 * * * /opt/butterbackup/venv/bin/python3 /opt/butterbackup/butterbackup.py server_1.com
0 3 * * * /opt/butterbackup/venv/bin/python3 /opt/butterbackup/butterbackup.py server_2.com
15 3 * * * /opt/butterbackup/venv/bin/python3 /opt/butterbackup/butterbackup.py server_3.com
45 3 * * 1,4 /opt/butterbackup/venv/bin/python3 /opt/butterbackup/butterbackup.py server_4.com
```
2019-01-17 12:48:04 +01:00
# Inspect backups
2019-01-17 12:50:51 +01:00
`cd /backups/my_server_domain_name.com`