Compare commits
2 Commits
ad4de2994a
...
ad13bb343a
Author | SHA1 | Date | |
---|---|---|---|
ad13bb343a | |||
f2b47dcba2 |
8
Makefile
8
Makefile
|
@ -31,6 +31,14 @@ test-setup:
|
||||||
#git ls-files -z | tar --null -T - -cf - | tar -C /tmp/test-borg -xvf -
|
#git ls-files -z | tar --null -T - -cf - | tar -C /tmp/test-borg -xvf -
|
||||||
/tmp/test-borg/initial-setup.sh
|
/tmp/test-borg/initial-setup.sh
|
||||||
|
|
||||||
|
# Pull master and rebase "setup-$HOSTNAME" branch onto it
|
||||||
|
.PHONY: rebase
|
||||||
|
rebase:
|
||||||
|
git checkout master
|
||||||
|
git pull
|
||||||
|
git checkout -
|
||||||
|
git rebase master
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f README.html
|
rm -f README.html
|
||||||
|
|
33
backup.py
33
backup.py
|
@ -241,10 +241,8 @@ def main(argv: list[str]):
|
||||||
base = pathlib.Path(__file__).parent
|
base = pathlib.Path(__file__).parent
|
||||||
parser.add_argument('-c', '--config',
|
parser.add_argument('-c', '--config',
|
||||||
help="Config file", default=str(base / "config.yaml"))
|
help="Config file", default=str(base / "config.yaml"))
|
||||||
parser.add_argument('-b', '--borg',
|
parser.add_argument('-v', '--vars',
|
||||||
help="Borg command", default=str(base / "borg.sh"))
|
help="Variables file", default=str(base / "vars.sh"))
|
||||||
parser.add_argument('-N', '--notify',
|
|
||||||
help="Notify command", default=str(base / "notify.sh"))
|
|
||||||
parser.add_argument('-n', '--dry-run', action="store_true",
|
parser.add_argument('-n', '--dry-run', action="store_true",
|
||||||
help="Just print log output, don't run borg")
|
help="Just print log output, don't run borg")
|
||||||
parser.add_argument('-d', '--debug', action="store_true",
|
parser.add_argument('-d', '--debug', action="store_true",
|
||||||
|
@ -253,6 +251,27 @@ def main(argv: list[str]):
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
config = Config(args.config)
|
config = Config(args.config)
|
||||||
|
|
||||||
|
# Parse variables from vars.sh
|
||||||
|
hostname = os.uname().nodename
|
||||||
|
borg = str(base / "borg.sh")
|
||||||
|
notify = str(base / "notify.sh")
|
||||||
|
try:
|
||||||
|
with open(args.vars) as f:
|
||||||
|
for line in f:
|
||||||
|
m = re.match(r"\s*export\s*([A-Z_]+)=(.*)", line)
|
||||||
|
if not m:
|
||||||
|
continue
|
||||||
|
var = m.group(1)
|
||||||
|
value = m.group(2)
|
||||||
|
if var == "HOSTNAME":
|
||||||
|
hostname = value
|
||||||
|
if var == "BORG":
|
||||||
|
borg = value
|
||||||
|
if var == "BORG_DIR":
|
||||||
|
notify = pathlib.Path(value) / "notify.sh"
|
||||||
|
except Exception as e:
|
||||||
|
self.log('W', f"failed to parse variables from {args.vars}: {str(e)}")
|
||||||
|
|
||||||
# Run backup
|
# Run backup
|
||||||
backup = Backup(config, args.dry_run)
|
backup = Backup(config, args.dry_run)
|
||||||
captured_output: list[bytes] = []
|
captured_output: list[bytes] = []
|
||||||
|
@ -265,7 +284,7 @@ def main(argv: list[str]):
|
||||||
backup.run(out)
|
backup.run(out)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
else:
|
else:
|
||||||
borg = subprocess.Popen([args.borg,
|
borg = subprocess.Popen([borg,
|
||||||
"create",
|
"create",
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"--list",
|
"--list",
|
||||||
|
@ -275,7 +294,7 @@ def main(argv: list[str]):
|
||||||
"--compression", "zstd,3",
|
"--compression", "zstd,3",
|
||||||
"--paths-from-stdin",
|
"--paths-from-stdin",
|
||||||
"--paths-delimiter", "\\0",
|
"--paths-delimiter", "\\0",
|
||||||
"::{hostname}-{now:%Y%m%d-%H%M%S}"],
|
"::" + hostname + "-{now:%Y%m%d-%H%M%S}"],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
|
@ -367,7 +386,7 @@ def main(argv: list[str]):
|
||||||
summary = warnmsg
|
summary = warnmsg
|
||||||
|
|
||||||
# Call notify.sh
|
# Call notify.sh
|
||||||
res = subprocess.run([args.notify, summary, email], input=body_text)
|
res = subprocess.run([notify, summary, email], input=body_text)
|
||||||
if res.returncode != 0:
|
if res.returncode != 0:
|
||||||
backup.log('E', f"failed to send notification")
|
backup.log('E', f"failed to send notification")
|
||||||
errors += 1
|
errors += 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user