介绍
本教程将简要介绍 Borgmatic 以及如何将服务器的完整系统备份到存储设备上。Borgmatic 是一款简单易用的工具,它简化了 BorgBackup 的使用,并扩展了其功能。.
先决条件
- 您想要备份的 Linux 服务器。.
- 一个有足够的可用空间并已设置好 SSH 密钥的存储盒。.
步骤 1 – 安装和配置 Borgmatic
在这一步中,我们将介绍如何安装和配置 Borgmatic。.
步骤 1.1 安装 BorgBackup 和 Borgmatic
Borgmatic 不会自动包含 BorgBackup,因此我们需要手动安装这两个软件包:
apt install borgbackup borgmatic步骤 1.2 – Borgmatic 配置
可以使用 generate 命令创建一个示例配置。
generate-borgmatic-config这是一个包含示例值的配置 /etc/borgmatic/conf.yml 创建。.
本教程可以使用以下设置:
location:
# Here you can specify a list of Storage Boxes as backup target.
repositories:
- [email protected]-storagebox.de:backups
# A list of all directoy which should be included within the backup.
# As we want to create a full system backup "/" is sufficient.
source_directories:
- /
# Exclude the default mount directory and any directories which are created at runtime.
exclude_patterns:
- /dev
- /proc
- /sys
- /var/run
- /run
- /mnt
- /tmp
storage:
# Here you can specify the password which is used to encrypt your backups. This is _not_ your Storage Box password.
# Do not lose this. Otherwise you are not able to restore your backup later.
encryption_passphrase: "<SUPER SECRET PASSWORD>"
# As BorgBackup is running on port 23 on the Storage Boxes, we have to overwrite the default ssh command in order to specify a port.
ssh_command: "ssh -p 23"
# Here you can specify how many backups should be kept at minumim for the specified time frame.
retention:
keep_daily: 7
keep_weekly: 4
keep_monthly: 6
keep_yearly: 1 步骤 1.3 – 设置并创建第一个备份
在创建第一个备份之前,我们需要先初始化备份存储库。.
borgmatic init --encryption repokey --verbosity 1准备工作完成后,我们就可以创建第一个备份了。.
borgmatic --verbosity 1根据服务器规模,首次备份可能需要一些时间。后续备份速度会更快,因为它们只是增量备份。.
步骤 2 – 自动化
从 systemctl status borgmatic.timer borgmatic.service 用于检查服务和定时器是否已存在。.
- 如果出现如下错误
找不到单元 borgmatic.XXX如果您没有收到,可以按照以下说明操作。. - 如果找到了设备并且可以看到设备的状态,则可以跳过此步骤。.
我们将使用系统单元和定时器来实现自动化。下面启动备份的部分位于…… /etc/systemd/system/borgmatic.service 复制。.
[Unit] Description=Borgmatic system backup Requires=network.target After=network.target [Service] Type=oneshot Nice=10 IOSchedulingClass=best-effort IOSchedulingPriority=6 ProtectSystem=full ExecStart=/usr/bin/borgmatic --verbosity -1 --syslog-verbosity 1
以下部分负责定期启动备份。它位于: /etc/systemd/system/borgmatic.timer 复制
[Unit] Description=Daily backup timer [Timer] OnCalendar=*-*-* 16:30:00 Persistent=true [Install] WantedBy=timers.target
现在我们只需要启动计时器:
systemctl enable --now borgmatic.timer
定时器每天下午 4:30 开始备份。.
结果
借助 Borgmatic,我们拥有了一个简单而强大的系统备份工具。我们已经配置好该工具并设置了自动备份,以防止数据丢失。.









