-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (41 loc) · 1.19 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
#
# Set up the Zabbix Backup Tool
#
# ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
SHELL := /bin/bash
VENV := .venv
SCRIPT := zabbix_export.py
EXE := $(SCRIPT:%.py=%)
BACKUPS := BACKUPS
P_WD := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# keep the snapshots of the x last days
DAYS := 15
define _script
#!/bin/bash
CWD=$$(dirname $$(realpath $$0))
source $${CWD}/.venv/bin/activate
no_proxy=* $${CWD}/$(SCRIPT) -d $${CWD}/$(BACKUPS) -z $$@
deactivate
endef
export _script
.PHONY: install uninstall venv
install: | $(VENV) $(EXE)
@if ! $$(crontab -l | grep -q $(P_WD)/$(BACKUPS)); then \
{ crontab -l; \
echo "0 1 * * * find $(P_WD)/$(BACKUPS)/ -ctime +$(DAYS) -delete; $(P_WD)/$(EXE)"; \
} | crontab - ; \
echo "Daily rotation set to $(DAYS) last backups"; \
echo "Remember to set the configuration (ref. zbx_config.ini)"; \
fi;
uninstall:
@crontab -l | grep -wv $(P_WD)/$(EXE) | crontab -
@echo "Backups rotation removed"
venv: | $(VENV)
$(EXE):
@echo "$$_script" > $@
@chmod +x $@
@chmod +x $(SCRIPT)
$(VENV):
python3 -m venv $@
source $@/bin/activate && pip install -r requirements.txt