哪个更适合网站备份 - rsync 或 git push

Dav*_*ing 16 backup rsync git

我在不同的提供商处运行 2 个 LAMP Web 服务器以用于灾难恢复目的 - 一个高功率的实时服务器和一个低功率的备份服务器。

目前我每 4 小时将所有数据从实时服务器同步到备份服务器。

这可以正常工作,但是在 rsync 确定哪些文件已更改时会增加系统负载。

由于所有网站都位于 git 存储库中,我想知道 git push 是否是更好的备份技术。

我必须在 git repo 中包含实时上传文件夹;然后备份过程将是:

live$ git add .
live$ git commit -a -m "{data-time} snapshot"
live$ git push backup live_branch
Run Code Online (Sandbox Code Playgroud)

然后在备份服务器上有一个提交后挂钩,以便在每次推送时进行结帐。

每个网站的大小从 50M 到 2GB 不等。我最终会得到大约 50 个单独的 git 存储库。

这是比rsync“更好”的解决方案吗?

  • git 更擅长计算哪些文件发生了变化?
  • git push 比 rsync 更有效吗
  • 我忘记了什么?

谢谢!

---- 一些对比测试的数据 ------

1)52MB文件夹然后添加一个新的500k文件夹(主要是文本文件)

同步

sent 1.47K bytes  received 285.91K bytes  
total size is 44.03M  speedup is 153.22

real    0m0.718s    user    0m0.044s    sys     0m0.084s
Run Code Online (Sandbox Code Playgroud)

混帐

Counting objects: 38, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (37/37), done.
Writing objects: 100% (37/37), 118.47 KiB, done.
Total 37 (delta 3), reused 0 (delta 0)

real    0m0.074s     user   0m0.029s    sys     0m0.045s
Run Code Online (Sandbox Code Playgroud)

2)1.4G文件夹然后添加一个新的18M文件夹(主要是图片)

同步

sent 3.65K bytes  received 18.90M bytes
total size is 1.42G  speedup is 75.17

real    0m5.311s    user    0m0.784s    sys     0m0.328s
Run Code Online (Sandbox Code Playgroud)

混帐

Counting objects: 108, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (106/106), done.
Writing objects: 100% (107/107), 17.34 MiB | 5.21 MiB/s, done.
Total 107 (delta 0), reused 0 (delta 0)

real    0m15.334s    user   0m5.202s    sys     0m1.040s
Run Code Online (Sandbox Code Playgroud)

3)52M文件夹然后添加一个新的18M文件夹(主要是图片)

同步

sent 2.46K bytes  received 18.27M bytes  4.06M bytes/sec
total size is 62.38M  speedup is 3.41

real    0m4.124s    user    0m0.640s    sys     0m0.188s
Run Code Online (Sandbox Code Playgroud)

混帐

Counting objects: 108, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (106/106), done.
Writing objects: 100% (107/107), 17.34 MiB | 5.43 MiB/s, done.
Total 107 (delta 1), reused 0 (delta 0)

real    0m6.990s    user    0m4.868s    sys     0m0.573s
Run Code Online (Sandbox Code Playgroud)

4)1.4G文件夹然后添加一个新的500k文件夹(主要是文字)

同步

sent 2.66K bytes  received 916.04K bytes  612.47K bytes/sec
total size is 1.42G  speedup is 1547.14

real    0m1.191s    user    0m0.180s    sys     0m0.268s
Run Code Online (Sandbox Code Playgroud)

混帐

Counting objects: 49, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (48/48), done.
Writing objects: 100% (48/48), 177.90 KiB, done.
Total 48 (delta 3), reused 0 (delta 0)

real    0m1.776s    user    0m0.390s    sys     0m0.497s
Run Code Online (Sandbox Code Playgroud)

5) 1.4G 文件夹 - 无变化

同步

sent 1.72K bytes  received 716.44K bytes  287.26K bytes/sec
total size is 1.42G  speedup is 1979.18

real    0m1.092s    user    0m0.168s    sys     0m0.272s
Run Code Online (Sandbox Code Playgroud)

混帐

nothing to commit (working directory clean)

real    0m0.636s    user    0m0.268s    sys     0m0.348s
Run Code Online (Sandbox Code Playgroud)

5) 52M 文件夹 - 无变化

同步

sent 528 bytes  received 88.40K bytes  59.29K bytes/sec
total size is 62.38M  speedup is 701.41

real    0m0.779s    user    0m0.044s    sys     0m0.144s
Run Code Online (Sandbox Code Playgroud)

混帐

nothing to commit (working directory clean)

real    0m0.156s    user    0m0.057s    sys     0m0.097s
Run Code Online (Sandbox Code Playgroud)

Adi*_*ari 5

实际上我建议平衡地混合使用两者。你的主备份应该(至少)每晚提交到 git。每周使用 rsync 将其同步一次或两次到距离生产设备较远的另一台机器。

Git 将帮助您立即恢复,并且由于您的备份是版本化的并且具有更改日志,因此它还使数据分析变得更加容易。对数据进行任何重大更改后,您可以手动提交并推送到 git,并将原因放入更改日志中。如果 git 出现问题,rsync 将会前来救援,但请记住,根据 rsync 的频率,您仍然会丢失数据。

经验法则:在备份和灾难恢复方面,没有什么可以保证 100% 恢复。