Borg 增量备份方案

一、为什么选择 BorgBackup

Borg Backup 是目前最受欢迎,用户量最大的一个备份支持程序,支持去重和压缩,同时也支持认证加密。其主要目的是提供一个高效而且安全的方法用于数据备份。数据的去重技术用于每日增量备份。它支持Linux、MacOS和BSD,并遵循BSD许可协议

BorgBackup 的主要优势:

  • 高效:BorgBackup 会将文件按数据块去重,只有改动的数据块才会被备份。一个 25 GiB 的虚拟机磁盘文件,只改动了 1 GiB,那就只会新增备份这 1 GiB 的数据;
  • 高速:核心算法使用 C 编译,使用缓存快速跳过未改动过的文件以加快备份速度;
  • 加密:数据默认是 AES-256 加密并且 HMAC-SHA256 校验的;
  • 压缩:支持多种压缩算法,可自动检测数据是否属于可被压缩的类型;
  • 异地备份:原生支持 SSH 备份到异地服务器,也可使用 NFS 等网络存储;
  • 可挂载:可以直接用 FUSE 挂载一个备份存档读取里面的数据;
  • 跨平台:支持 Linux, macOS, BSD, Windows (Cygwin / WSL) 等多种平台;
  • 开源:安全可审计,易于修改。

官网

https://www.borgbackup.org/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
 
# Setting this, so the repo does not need to be given on the commandline:
export BORG_REPO=ssh://username@example.com:2022/~/backup/main
 
# See the section "Passphrase notes" for more infos.
export BORG_PASSPHRASE='XYZl0ngandsecurepa_55_phrasea&&123'
 
# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
 
info "Starting backup"
 
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
 
borg create                         \
    --verbose                       \
    --filter AME                    \
    --list                          \
    --stats                         \
    --show-rc                       \
    --compression lz4               \
    --exclude-caches                \
    --exclude 'home/*/.cache/*'     \
    --exclude 'var/tmp/*'           \
                                    \
    ::'{hostname}-{now}'            \
    /etc                            \
    /home                           \
    /root                           \
    /var                            \
 
backup_exit=$?
 
info "Pruning repository"
 
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-' prefix is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:
 
borg prune                          \
    --list                          \
    --prefix '{hostname}-'          \
    --show-rc                       \
    --keep-daily    7               \
    --keep-weekly   4               \
    --keep-monthly  6               \
 
prune_exit=$?
 
# actually free repo disk space by compacting segments
 
info "Compacting repository"
 
borg compact
 
compact_exit=$?
 
# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit ))
 
if [ ${global_exit} -eq 0 ]; then
    info "Backup, Prune, and Compact finished successfully"
elif [ ${global_exit} -eq 1 ]; then
    info "Backup, Prune, and/or Compact finished with warnings"
else
    info "Backup, Prune, and/or Compact finished with errors"
fi
 
exit ${global_exit}

  

posted @   凡人半睁眼  阅读(878)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
历史上的今天:
2020-09-28 Linux清理入侵痕迹

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示