2017-11-10 12:48:41 +01:00
.. include :: global.rst.inc
2017-11-09 21:17:09 +01:00
.. _tutorial:
2017-11-09 20:33:09 +01:00
Tutorial
========
This tutorial shows how zrepl can be used to implement a ZFS-based pull backup.
We assume the following scenario:
2018-10-11 17:46:26 +02:00
* Production server `` prod `` with filesystems to back up:
2017-11-09 20:33:09 +01:00
2017-11-09 21:17:09 +01:00
* `` zroot/var/db ``
* `` zroot/usr/home `` and all its child filesystems
* **except** `` zroot/usr/home/paranoid `` belonging to a user doing backups themselves
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
* Backup server `` backups `` with
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
* Filesystem `` storage/zrepl/pull/prod `` + children dedicated to backups of `` prod ``
2017-11-09 20:33:09 +01:00
Our backup solution should fulfill the following requirements:
2018-10-11 17:46:26 +02:00
* Periodically snapshot the filesystems on `` prod `` *every 10 minutes*
* Incrementally replicate these snapshots to `` storage/zrepl/pull/prod/* `` on `` backups ``
* Keep only very few snapshots on `` prod `` to save disk space
* Keep a fading history (24 hourly, 30 daily, 6 monthly) of snapshots on `` backups ``
2017-11-09 20:33:09 +01:00
Analysis
--------
We can model this situation as two jobs:
2018-10-11 17:46:26 +02:00
* A **source job** on `` prod ``
2017-11-09 20:33:09 +01:00
* Creates the snapshots
2018-10-11 17:46:26 +02:00
* Keeps a short history of snapshots to enable incremental replication to `` backups ``
* Accepts connections from `` backups ``
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
* A **pull job** on `` backups ``
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
* Connects to the `` zrepl daemon `` process on `` prod ``
* Pulls the snapshots to `` storage/zrepl/pull/prod/* ``
* Fades out snapshots in `` storage/zrepl/pull/prod/* `` as they age
2017-11-09 20:33:09 +01:00
Why doesn't the **pull job** create the snapshots before pulling?
2018-10-11 17:46:26 +02:00
As is the case with all distributed systems, the link between `` prod `` and `` backups `` might be down for an hour or two.
2017-11-09 20:33:09 +01:00
We do not want to sacrifice our required backup resolution of 10 minute intervals for a temporary connection outage.
2018-10-11 17:46:26 +02:00
When the link comes up again, `` backups `` will catch up with the snapshots taken by `` prod `` in the meantime, without a gap in our backup history.
2017-11-09 20:33:09 +01:00
Install zrepl
-------------
2017-11-09 21:17:09 +01:00
Follow the :ref: `OS-specific installation instructions <installation>` and come back here.
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
Configure server `` backups ``
----------------------------
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
We define a **pull job** named `` pull_prod `` in `` /etc/zrepl/zrepl.yml `` or `` /usr/local/etc/zrepl/zrepl.yml `` on host `` backups `` : ::
2017-11-09 20:33:09 +01:00
jobs:
2018-10-11 17:46:26 +02:00
- name: pull_prod
2017-11-16 09:14:01 +01:00
type: pull
connect:
2018-10-11 17:46:26 +02:00
type: tcp
address: "192.168.2.20:2342"
root_fs: "storage/zrepl/pull/prod"
2017-11-16 09:14:01 +01:00
interval: 10m
2018-10-11 17:46:26 +02:00
pruning:
keep_sender:
- type: not_replicated
- type: last_n
count: 10
keep_receiver:
- type: grid
grid: 1x1h(keep=all) | 24x1h | 30x1d | 6x30d
regex: "^zrepl_"
interval: 10m
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
The `` connect `` section instructs the zrepl daemon to use plain TCP transport.
Check out the :ref: `transports <transport>` section for alternatives that support encryption.
2018-04-01 14:53:44 +02:00
2018-10-11 17:46:26 +02:00
.. _tutorial-configure-prod:
2018-04-01 14:53:44 +02:00
2018-10-11 17:46:26 +02:00
Configure server `` prod ``
-------------------------
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
We define a corresponding **source job** named `` source_backups `` in `` /etc/zrepl/zrepl.yml `` or `` /usr/local/etc/zrepl/zrepl.yml `` on host `` prod `` : ::
2017-11-09 20:33:09 +01:00
jobs:
2018-10-11 17:46:26 +02:00
- name: source_backups
2017-11-16 09:14:01 +01:00
type: source
serve:
2018-10-11 17:46:26 +02:00
type: tcp
listen: ":2342"
clients: {
"192.168.2.10" : "backups"
}
2017-11-16 09:14:01 +01:00
filesystems: {
2018-10-11 17:46:26 +02:00
"zroot/var/db:": true,
"zroot/usr/home<": true,
"zroot/usr/home/paranoid": false
2017-11-16 09:14:01 +01:00
}
2018-10-11 17:46:26 +02:00
snapshotting:
type: periodic
prefix: zrepl_
interval: 10m
2017-11-09 20:33:09 +01:00
2018-10-11 17:46:26 +02:00
The `` serve `` section whitelists `` backups `` 's IP address `` 192.168.2.10 `` and assigns it the client identity `` backups `` which will show up in the logs.
Again, check the :ref: `docs for encrypted transports <transport>` .
2017-11-09 20:33:09 +01:00
Apply Configuration Changes
---------------------------
2018-10-11 17:46:26 +02:00
We need to restart the zrepl daemon on **both** `` prod `` and `` backups `` .
2017-12-27 18:34:02 +01:00
This is :ref: `OS-specific <usage-zrepl-daemon-restarting>` .
2017-11-09 20:33:09 +01:00
Watch it Work
-------------
2018-10-11 17:46:26 +02:00
Run `` zrepl status `` on `` prod `` to monitor the replication and pruning activity.
2017-12-27 16:38:49 +01:00
Additionally, you can check the detailed structured logs of the `zrepl daemon` process and use GNU *watch* to view the snapshots present on both machines.
2017-11-09 20:33:09 +01:00
2017-11-10 14:30:51 +01:00
If you like tmux, here is a handy script that works on FreeBSD: ::
2017-11-09 20:33:09 +01:00
pkg install gnu-watch tmux
tmux new-window
tmux split-window "tail -f /var/log/zrepl.log"
2018-10-11 17:46:26 +02:00
tmux split-window "gnu-watch 'zfs list -t snapshot -o name,creation -s creation | grep zrepl_'"
2017-11-09 20:33:09 +01:00
tmux select-layout tiled
2017-11-10 14:30:51 +01:00
The Linux equivalent might look like this: ::
2017-11-09 20:33:09 +01:00
# make sure tmux is installed & let's assume you use systemd + journald
tmux new-window
tmux split-window "journalctl -f -u zrepl.service"
2018-10-11 17:46:26 +02:00
tmux split-window "watch 'zfs list -t snapshot -o name,creation -s creation | grep zrepl_'"
2017-11-09 20:33:09 +01:00
tmux select-layout tiled
Summary
-------
Congratulations, you have a working pull backup. Where to go next?
2017-11-09 21:17:09 +01:00
* Read more about :ref: `configuration format, options & job types <configuration_toc>`
2018-04-14 11:24:47 +02:00
* Configure :ref: `logging <logging>` \& :ref: `monitoring <monitoring>` .
2017-11-09 21:17:09 +01:00
* Learn about :ref: `implementation details <implementation_toc>` of zrepl.
2017-11-09 20:33:09 +01:00