136 lines
5.5 KiB
Ruby
136 lines
5.5 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/b8/f6/ab3ab90ab10bec6e0b24d59966bcc11fd07c2e05b48a8f4e5953cc527800/borgmatic-1.5.12.tar.gz"
|
|
sha256 "5cb6c126f351987f16f529ce8c5ef351b6b3458142316e9210edb028dff65536"
|
|
license "GPL-3.0-or-later"
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_big_sur: "a053876cc2c25aeb2923ed88b7c367cf1587287bb4ecab816ac30d0101717c97"
|
|
sha256 cellar: :any, big_sur: "875035ec5d79c0641ef5a86ad7f41d79b9e965a90a2a9a822881cce3c318b14c"
|
|
sha256 cellar: :any, catalina: "23676967eec18bcf94d54357eef710b94274b2b988a576eb933c2823da418bcc"
|
|
sha256 cellar: :any, mojave: "61eb64ccf14eca1e09de11aa94adfa64190354fb58b1f66eebcca0f71661bedf"
|
|
end
|
|
|
|
depends_on "libyaml"
|
|
depends_on "python@3.9"
|
|
|
|
resource "certifi" do
|
|
url "https://files.pythonhosted.org/packages/e6/de/879cf857ae6f890dfa23c3d6239814c5471936b618c8fb0c8732ad5da885/certifi-2020.11.8.tar.gz"
|
|
sha256 "f05def092c44fbf25834a51509ef6e631dc19765ab8a57b4e7ab85531f0a9cf4"
|
|
end
|
|
|
|
resource "chardet" do
|
|
url "https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz"
|
|
sha256 "84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"
|
|
end
|
|
|
|
resource "colorama" do
|
|
url "https://files.pythonhosted.org/packages/1f/bb/5d3246097ab77fa083a61bd8d3d527b7ae063c7d8e8671b1cf8c4ec10cbe/colorama-0.4.4.tar.gz"
|
|
sha256 "5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"
|
|
end
|
|
|
|
resource "docopt" do
|
|
url "https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-0.6.2.tar.gz"
|
|
sha256 "49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"
|
|
end
|
|
|
|
resource "idna" do
|
|
url "https://files.pythonhosted.org/packages/ea/b7/e0e3c1c467636186c39925827be42f16fee389dc404ac29e930e9136be70/idna-2.10.tar.gz"
|
|
sha256 "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"
|
|
end
|
|
|
|
resource "pykwalify" do
|
|
url "https://files.pythonhosted.org/packages/53/6a/c7394df238816085de6a630f1817805639e844ea7980108f19261cd44c12/pykwalify-1.7.0.tar.gz"
|
|
sha256 "7e8b39c5a3a10bc176682b3bd9a7422c39ca247482df198b402e8015defcceb2"
|
|
end
|
|
|
|
resource "python-dateutil" do
|
|
url "https://files.pythonhosted.org/packages/be/ed/5bbc91f03fa4c839c4c7360375da77f9659af5f7086b7a7bdda65771c8e0/python-dateutil-2.8.1.tar.gz"
|
|
sha256 "73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"
|
|
end
|
|
|
|
resource "PyYAML" do
|
|
url "https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz"
|
|
sha256 "b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d"
|
|
end
|
|
|
|
resource "requests" do
|
|
url "https://files.pythonhosted.org/packages/9f/14/4a6542a078773957aa83101336375c9597e6fe5889d20abda9c38f9f3ff2/requests-2.25.0.tar.gz"
|
|
sha256 "7f1a0b932f4a60a1a65caa4263921bb7d9ee911957e0ae4a23a6dd08185ad5f8"
|
|
end
|
|
|
|
resource "ruamel.yaml" do
|
|
url "https://files.pythonhosted.org/packages/17/2f/f38332bf6ba751d1c8124ea70681d2b2326d69126d9058fbd9b4c434d268/ruamel.yaml-0.16.12.tar.gz"
|
|
sha256 "076cc0bc34f1966d920a49f18b52b6ad559fbe656a0748e3535cf7b3f29ebf9e"
|
|
end
|
|
|
|
resource "six" do
|
|
url "https://files.pythonhosted.org/packages/6b/34/415834bfdafca3c5f451532e8a8d9ba89a21c9743a0c59fbd0205c7f9426/six-1.15.0.tar.gz"
|
|
sha256 "30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"
|
|
end
|
|
|
|
resource "urllib3" do
|
|
url "https://files.pythonhosted.org/packages/29/e6/d1a1d78c439cad688757b70f26c50a53332167c364edb0134cadd280e234/urllib3-1.26.2.tar.gz"
|
|
sha256 "19188f96923873c92ccb987120ec4acaa12f0461fa9ce5d3d0772bc965a39e08"
|
|
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*", "")
|
|
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
|