forked from Altinity/clickhouse-backup
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
80 lines (64 loc) · 1.99 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Origin: https://github.com/innogames/graphite-ch-optimizer/blob/master/Makefile
# MIT License
NAME = clickhouse-backup
VERSION = $(shell git describe --long --tags 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/c\1/;s/-/./g')
GIT_COMMIT = $(shell git rev-parse HEAD)
DATE = $(shell date +%F)
VENDOR = "Alexander Akulov <[email protected]>"
URL = https://github.com/AlexAkulov/$(NAME)
define DESC =
'Tool for easy ClickHouse backup and restore with S3 and GCS support
Easy creating and restoring backups of all or specific tables
Efficient storing of multiple backups on the file system
Most efficient AWS S3/GCS uploading and downloading with streaming compression
Support of incremental backups on remote storages'
endef
GO_FILES = $(shell find -name '*.go')
GO_BUILD = go build -ldflags "-X 'main.version=$(VERSION)' -X 'main.gitCommit=$(GIT_COMMIT)' -X 'main.buildDate=$(DATE)'"
PKG_FILES = build/$(NAME)_$(VERSION)_amd64.deb build/$(NAME)-$(VERSION)-1.x86_64.rpm
export CGO_ENABLED = 0
.PHONY: clean all version test
all: build config
version:
@echo $(VERSION)
clean:
rm -rf build
rm -rf $(NAME)
rebuild: clean all
test:
go vet ./...
go test -v ./...
build: $(NAME)/$(NAME)
config: $(NAME)/config.yml
$(NAME)/config.yml: $(NAME)/$(NAME)
./$(NAME)/$(NAME) default-config > $@
$(NAME)/$(NAME): $(GO_FILES)
$(GO_BUILD) -o $@ .
build/$(NAME): $(GO_FILES)
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o $@ .
packages: $(PKG_FILES)
.ONESHELL:
build/pkg: build/$(NAME) $(NAME)/config.yml
cd build
mkdir -p pkg/etc/$(NAME)
mkdir -p pkg/usr/bin
cp -l $(NAME) pkg/usr/bin/
cp -l ../$(NAME)/config.yml pkg/etc/$(NAME)/config.yml.example
deb: $(word 1, $(PKG_FILES))
rpm: $(word 2, $(PKG_FILES))
# Set TYPE to package suffix w/o dot
$(PKG_FILES): TYPE = $(subst .,,$(suffix $@))
$(PKG_FILES): build/pkg
fpm --verbose \
-s dir \
-a x86_64 \
-t $(TYPE) \
--vendor $(VENDOR) \
-m $(VENDOR) \
--url $(URL) \
--description $(DESC) \
--license MIT \
-n $(NAME) \
-v $(VERSION) \
-p build \
build/pkg/=/