128 lines
5.4 KiB
Ruby
128 lines
5.4 KiB
Ruby
class Borgmatic < Formula
|
|
include Language::Python::Virtualenv
|
|
|
|
desc "Simple wrapper script for the Borg backup software"
|
|
homepage "https://torsion.org/borgmatic/"
|
|
url "https://files.pythonhosted.org/packages/a9/45/0a7915ba5e16e13f11c1c7ab941949a8a2d8e73055c20970aefc74f9c6e1/borgmatic-1.5.21.tar.gz"
|
|
sha256 "b8aa9dbf250b95b829827310c9638a17cd52fee160a437283eed23bffcae83cf"
|
|
license "GPL-3.0-or-later"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, arm64_monterey: "4c4fc8bd7ac99da6af9c341f3203a3bc34cc09aa4c0928c00c11fd414f92f522"
|
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "3716d256c69e4ccd79b63af54d88bb70265e2c4e1a8ed1376058e7d864b8c508"
|
|
sha256 cellar: :any_skip_relocation, monterey: "7b3aa8910b98c8c446337013c599e6d69e3bef3334d05d0bdb4eb24691f1099d"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "4be0b5de1e7387bdd3293847d2eca16a8c7be058920361ea805cb156ec6b74a2"
|
|
sha256 cellar: :any_skip_relocation, catalina: "14e359d1b71d6733362084c958fbc13f6294cab539423641a840dcda5569c778"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "441347de44beaaa9139c250d7a6ba0d184aa1634f05d352e70bb30939b4665d7"
|
|
end
|
|
|
|
depends_on "python@3.10"
|
|
|
|
resource "attrs" do
|
|
url "https://files.pythonhosted.org/packages/ed/d6/3ebca4ca65157c12bd08a63e20ac0bdc21ac7f3694040711f9fd073c0ffb/attrs-21.2.0.tar.gz"
|
|
sha256 "ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"
|
|
end
|
|
|
|
resource "certifi" do
|
|
url "https://files.pythonhosted.org/packages/6c/ae/d26450834f0acc9e3d1f74508da6df1551ceab6c2ce0766a593362d6d57f/certifi-2021.10.8.tar.gz"
|
|
sha256 "78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"
|
|
end
|
|
|
|
resource "charset-normalizer" do
|
|
url "https://files.pythonhosted.org/packages/9f/c5/334c019f92c26e59637bb42bd14a190428874b2b2de75a355da394cf16c1/charset-normalizer-2.0.7.tar.gz"
|
|
sha256 "e019de665e2bcf9c2b64e2e5aa025fa991da8720daa3c1138cadd2fd1856aed0"
|
|
end
|
|
|
|
resource "colorama" do
|
|
url "https://files.pythonhosted.org/packages/1f/bb/5d3246097ab77fa083a61bd8d3d527b7ae063c7d8e8671b1cf8c4ec10cbe/colorama-0.4.4.tar.gz"
|
|
sha256 "5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"
|
|
end
|
|
|
|
resource "idna" do
|
|
url "https://files.pythonhosted.org/packages/62/08/e3fc7c8161090f742f504f40b1bccbfc544d4a4e09eb774bf40aafce5436/idna-3.3.tar.gz"
|
|
sha256 "9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"
|
|
end
|
|
|
|
resource "jsonschema" do
|
|
url "https://files.pythonhosted.org/packages/ff/09/fa40d16ddcce69fc79e264c9458ac5ae693586d5f4c552e1e11889bdf971/jsonschema-4.2.1.tar.gz"
|
|
sha256 "390713469ae64b8a58698bb3cbc3859abe6925b565a973f87323ef21b09a27a8"
|
|
end
|
|
|
|
resource "pyrsistent" do
|
|
url "https://files.pythonhosted.org/packages/f4/d7/0fa558c4fb00f15aabc6d42d365fcca7a15fcc1091cd0f5784a14f390b7f/pyrsistent-0.18.0.tar.gz"
|
|
sha256 "773c781216f8c2900b42a7b638d5b517bb134ae1acbebe4d1e8f1f41ea60eb4b"
|
|
end
|
|
|
|
resource "requests" do
|
|
url "https://files.pythonhosted.org/packages/e7/01/3569e0b535fb2e4a6c384bdbed00c55b9d78b5084e0fb7f4d0bf523d7670/requests-2.26.0.tar.gz"
|
|
sha256 "b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"
|
|
end
|
|
|
|
resource "ruamel.yaml" do
|
|
url "https://files.pythonhosted.org/packages/4d/15/7fc04de02ca774342800c9adf1a8239703977c49c5deaadec1689ec85506/ruamel.yaml-0.17.17.tar.gz"
|
|
sha256 "9751de4cbb57d4bfbf8fc394e125ed4a2f170fbff3dc3d78abf50be85924f8be"
|
|
end
|
|
|
|
resource "urllib3" do
|
|
url "https://files.pythonhosted.org/packages/80/be/3ee43b6c5757cabea19e75b8f46eaf05a2f5144107d7db48c7cf3a864f73/urllib3-1.26.7.tar.gz"
|
|
sha256 "4987c65554f7a2dbf30c18fd48778ef124af6fab771a377103da0585e2336ece"
|
|
end
|
|
|
|
def install
|
|
virtualenv_install_with_resources
|
|
end
|
|
|
|
test do
|
|
borg = (testpath/"borg")
|
|
config_path = testpath/"config.yml"
|
|
repo_path = testpath/"repo"
|
|
log_path = testpath/"borg.log"
|
|
|
|
# Create a fake borg executable to log requested commands
|
|
borg.write <<~EOS
|
|
#!/bin/sh
|
|
echo $@ >> #{log_path}
|
|
|
|
# Return error on info so we force an init to occur
|
|
if [ "$1" = "info" ]; then
|
|
exit 2
|
|
fi
|
|
EOS
|
|
borg.chmod 0755
|
|
|
|
# Generate a config
|
|
system bin/"generate-borgmatic-config", "--destination", config_path
|
|
|
|
# Replace defaults values
|
|
config_content = File.read(config_path)
|
|
.gsub(/# ?local_path: borg1/, "local_path: #{borg}")
|
|
.gsub(/user@backupserver:sourcehostname.borg/, repo_path)
|
|
.gsub("- user@backupserver:{fqdn}", "")
|
|
.gsub("- /var/log/syslog*", "")
|
|
.gsub("- /home/user/path with spaces", "")
|
|
File.open(config_path, "w") { |file| file.puts config_content }
|
|
|
|
# Initialize Repo
|
|
system bin/"borgmatic", "-v", "2", "--config", config_path, "--init", "--encryption", "repokey"
|
|
|
|
# Create a backup
|
|
system bin/"borgmatic", "--config", config_path
|
|
|
|
# See if backup was created
|
|
system bin/"borgmatic", "--config", config_path, "--list", "--json"
|
|
|
|
# Read in stored log
|
|
log_content = File.read(log_path)
|
|
|
|
# Assert that the proper borg commands were executed
|
|
assert_equal <<~EOS, log_content
|
|
info --debug #{repo_path}
|
|
init --encryption repokey --debug #{repo_path}
|
|
prune --keep-daily 7 --prefix {hostname}- #{repo_path}
|
|
create #{repo_path}::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f} /etc /home
|
|
check --prefix {hostname}- #{repo_path}
|
|
list --json #{repo_path}
|
|
EOS
|
|
end
|
|
end
|