使用 Borgbackup 备份重要数据

发布于 2020-03-29 23:12:19

先看完其他人写的教程和相关文档

在线Borg存储提供商

安装 borgbackup 和 borgmatic

备份到本地然后rsync到远程存储

borg init -e repokey-blake2 <repo-name>
borg create <repo-name>::<archive-name> <dir-to-bakcup> [<dir-to-backup2> ...]
borg info <repo-name>
borg list <repo-name>
rsync -avz <repo-name> <remote-matchine>

备份到远程repo

borg init --encryption=repokey-blake2 xxx@xxx.repo.borgbase.com:repo
borg create xxx@xxx.repo.borgbase.com:repo::<my-snapshot> <local-dir>

使用 borgmatic 自动化备份

# borgmatic -c backup-vultr.yaml --verbosity 1
xxxx@xxxx.repo.borgbase.com:repo: Pruning archives
Enter passphrase for key ssh://xxxx@xxxx.repo.borgbase.com/./repo:
xxxx@xxxx.repo.borgbase.com:repo: Creating archive
Enter passphrase for key ssh://xxxx@xxxx.repo.borgbase.com/./repo:
Creating archive at "xxxx@xxxx.repo.borgbase.com:repo::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}"
Remote: Storage quota: 103.33 MB out of 3.00 GB used.
Remote: Storage quota: 103.51 MB out of 3.00 GB used.
xxxx@xxxx.repo.borgbase.com:repo: Running consistency checks
Remote: Starting repository check
Remote: Starting repository index check
Remote: Index object count match.
Remote: Completed repository check, no problems found.
Starting archive consistency check...
Enter passphrase for key ssh://xxxx@xxxx.repo.borgbase.com/./repo:
Analyzing archive v-2020-03-29T23:43:53.951346 (1/1)
Orphaned objects check skipped (needs all archives checked).
Archive consistency check complete, no problems found.

summary:
backup-vultr.yaml: Successfully ran configuration file

# borgmatic -c backup-vultr.yaml --list
xxxx@xxxx.repo.borgbase.com:repo: Listing archives
Enter passphrase for key ssh://xxxx@xxxx.repo.borgbase.com/./repo:
home-data                            Sun, 2020-03-29 23:02:16 [0f01c49a9e10e03994414d9a0d8558124ff134f9e64d6f90c663fb88ab2d951f]
root-data                            Sun, 2020-03-29 23:02:38 [b0f8293b9c8d0f476fcdb8c34c5a8e6360051bafacd1b0b097b6809921c53f36]
v-2020-03-29T23:43:53.951346         Sun, 2020-03-29 23:44:03 [ba96263581906371d988ddc06aa7295732a2a18f3b734b2fe47c07b89e6e84d0]

备份完成!

我是如何设计备份的

  • 需要备份的数据
    • 本地电子设备数据
      • 操作系统数据
        • MacBookPro 使用 TimeMachine 备份(排除了 ~/Downloads 目录)
        • iPhone 和 iPad 使用 iMazing 备份
      • ~/Downloads
        • ~/Downloads/Canon
        • ~/Downloads/archived
        • ~/Downloads/Music
        • ~/Downloads/BingWallpapers
        • ~/Downloads/Books
    • VPS 上的数据
      • 数据库数据文件夹 ~/data,包括 postgres、redis 等
      • 配置文件数据
  • 备份位置
    • 本地电子设备数据
      • TimeMachine 和 iMazing 数据直接放置在移动硬盘,也就是说每次备份的时候要连接移动硬盘到 MacBookPro
      • 其他数据
        • 放在 ~/Downloads/backup-download.borg 目录底下(写在 backup-download.yaml 配置文件里)
        • rsync.net 远端存储放置一份(写在 backup-download.yaml 配置文件里)
        • 并使用 rsync 备份到移动硬盘(有空的时候连接移动硬盘并同步)
    • VPS 上的数据
      • 直接利用国际间良好的网络,使用 borgbackup 备份到 borgbase.com,速度非常快

borgmatic 的配置文件 backup-download.yaml 内容:

location:
    # List of source directories to backup (required). Globs and tildes are expanded.
    source_directories:
        - ~/Downloads/Canon
        - ~/Downloads/archived
        - ~/Downloads/Music
        - ~/Downloads/BingWallpapers
        - ~/Downloads/Books

    # Paths to local or remote repositories (required). Tildes are expanded. Multiple
    # repositories are backed up to in sequence. See ssh_command for SSH options like
    # identity file or port.
    repositories:
        - ~/Downloads/backup-download.borg
        - hk-rsync:backup-download.borg

# Retention policy for how many backups to keep in each category. See
# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-prune for details.
# At least one of the "keep" options is required for pruning to work. See
# https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/
# if you'd like to skip pruning entirely.
retention:
    # Keep all archives within this time interval.
    # keep_within: 3H

    # Number of secondly archives to keep.
    # keep_secondly: 60

    # Number of minutely archives to keep.
    # keep_minutely: 60

    # Number of hourly archives to keep.
    # keep_hourly: 24

    # Number of daily archives to keep.
    keep_daily: 7

    # Number of weekly archives to keep.
    # keep_weekly: 4

    # Number of monthly archives to keep.
    keep_monthly: 3

    # Number of yearly archives to keep.
    keep_yearly: 5

    # When pruning, only consider archive names starting with this prefix.
    # Borg placeholders can be used. See the output of "borg help placeholders" for
    # details. Defaults to "{hostname}-". Use an empty value to disable the default.
    # prefix: sourcehostname

关于 repokey 模式是否需要自己单独保存 KEY

IMPORTANT: you will need both KEY AND PASSPHRASE to access this repo!
Use "borg key export" to export the key, optionally in printable format.
Write down the passphrase. Store both at safe place(s).

不要受字面意思误导,自己引申出需要单独保存repokey模式下的key的意思。 访问数据的条件和存储位置是单独的两件事情,不应该混淆。

其他注意事项

恢复数据

TODO