144 lines
5.6 KiB
Ruby
144 lines
5.6 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/3a/ef/de134b945ec2a73eeaea23efc9d8ff4f2c8ab23b14208d6c7b5e2a8b8137/borgmatic-1.5.10.tar.gz"
|
|
sha256 "31459e5573c34b7b9e53ad54012be6d367e2f23c0612fd5a315593ebf23074c5"
|
|
license "GPL-3.0-or-later"
|
|
|
|
livecheck do
|
|
url :stable
|
|
end
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "1779e107b6760355c7fd974356e687d680e0c03d34c39617cca6408f142e0b2f" => :catalina
|
|
sha256 "3f87068d5e4339228793005f4b67f79367e9bc13ac53a57fd5020aebda12cfbe" => :mojave
|
|
sha256 "161c4fde2155faa1949a3fd99321d66ea5be85dc1810558007426494b9de1665" => :high_sierra
|
|
end
|
|
|
|
depends_on "libyaml"
|
|
depends_on "python@3.8"
|
|
|
|
resource "certifi" do
|
|
url "https://files.pythonhosted.org/packages/40/a7/ded59fa294b85ca206082306bba75469a38ea1c7d44ea7e1d64f5443d67a/certifi-2020.6.20.tar.gz"
|
|
sha256 "5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3"
|
|
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/82/75/f2a4c0c94c85e2693c229142eb448840fba0f9230111faa889d1f541d12d/colorama-0.4.3.tar.gz"
|
|
sha256 "e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"
|
|
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/da/67/672b422d9daf07365259958912ba533a0ecab839d4084c487a5fe9a5405f/requests-2.24.0.tar.gz"
|
|
sha256 "b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b"
|
|
end
|
|
|
|
resource "ruamel.yaml" do
|
|
url "https://files.pythonhosted.org/packages/16/8b/54a26c1031595e5edd0e616028b922d78d8ffba8bc775f0a4faeada846cc/ruamel.yaml-0.16.10.tar.gz"
|
|
sha256 "099c644a778bf72ffa00524f78dd0b6476bca94a1da344130f4bf3381ce5b954"
|
|
end
|
|
|
|
resource "ruamel.yaml.clib" do
|
|
url "https://files.pythonhosted.org/packages/92/28/612085de3fae9f82d62d80255d9f4cf05b1b341db1e180adcf28c1bf748d/ruamel.yaml.clib-0.2.0.tar.gz"
|
|
sha256 "b66832ea8077d9b3f6e311c4a53d06273db5dc2db6e8a908550f3c14d67e718c"
|
|
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/81/f4/87467aeb3afc4a6056e1fe86626d259ab97e1213b1dfec14c7cb5f538bf0/urllib3-1.25.10.tar.gz"
|
|
sha256 "91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a"
|
|
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("- /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
|