-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
241 lines (221 loc) · 11.1 KB
/
Taskfile.yml
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
version: '3'
# TO RUN ANY *-container TASKS YOU MUST PROVIDE HOST IP (for containers to communicate with each other).
# EXAMPLE:
# task test-backup-pgsql-container -- 192.168.1.1
# To test locally, re-use env file with this command:
# env $(cat test/.env | xargs) test/podbackup <command>
vars:
PODBACKUP_CONTAINER_IMAGE: "localhost/podbackup:taskfile"
MINIO_CONTAINER_NAME: "minio-podbackup"
MINIO_CONTAINER_IMAGE: "quay.io/minio/minio"
MINIO_ACCESS_KEY: "123"
MINIO_SECRET_KEY: "12345678"
MINIO_BUCKET_NAME: "test"
MYSQL_CONTAINER_IMAGE: "docker.io/library/mariadb:10.10"
MYSQL_CONTAINER_NAME: "mysql-podbackup"
PGSQL_CONTAINER_IMAGE: "docker.io/bitnami/postgresql:14.9.0"
PGSQL_CONTAINER_NAME: "pgsql-podbackup"
dotenv: ['test/.env']
tasks:
build:
cmds:
- go build -o test/podbackup -v
build-podbackup-container:
cmds:
- podman build -t {{.PODBACKUP_CONTAINER_IMAGE}} .
generate-test-data:
cmds:
- mkdir -p test/backup-data
- rm -rf test/restore-data
- mkdir -p test/restore-data
- for ((i=1; i<=5; i++)); do echo $RANDOM | md5sum | head -c 20 > test/backup-data/backupfile-$i; done;
create-minio:
cmds:
- podman stop -i {{.MINIO_CONTAINER_NAME}}
- sleep 1
- podman run -d --rm -p 9000:9000 -p 9001:9001 --name {{.MINIO_CONTAINER_NAME}} -e MINIO_ACCESS_KEY={{.MINIO_ACCESS_KEY}} -e MINIO_SECRET_KEY={{.MINIO_SECRET_KEY}} {{.MINIO_CONTAINER_IMAGE}} server /data --console-address ":9001"
- sleep 5
- podman exec {{.MINIO_CONTAINER_NAME}} mc config host add localminio http://localhost:9000 {{.MINIO_ACCESS_KEY}} {{.MINIO_SECRET_KEY}}
- podman exec {{.MINIO_CONTAINER_NAME}} mc mb localminio/{{.MINIO_BUCKET_NAME}}
test-backup-data:
deps: [build,generate-test-data]
cmds:
- task: create-minio
- test/podbackup backup
- test/podbackup restore
- test/podbackup list
- if [[ $(diff -r test/backup-data/ test/restore-data) ]]; then echo "TEST FAILED - RESTORE != BACKUP"; else echo "TEST SUCCESSFUL"; fi
- podman stop -i {{.MINIO_CONTAINER_NAME}}
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "test/backup-data/"
DIR_TO_RESTORE: "test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: localhost:9000
test-backup-data-container:
deps: [generate-test-data,create-minio]
cmds:
- task: build-podbackup-container
- podman run -i --rm --name podbackup --env-host -v $(pwd)/test/backup-data:/test/backup-data:Z -v $(pwd)/test/restore-data:/test/restore-data:Z {{.PODBACKUP_CONTAINER_IMAGE}} backup
- podman run -i --rm --name podbackup --env-host -v $(pwd)/test/backup-data:/test/backup-data:Z -v $(pwd)/test/restore-data:/test/restore-data:Z {{.PODBACKUP_CONTAINER_IMAGE}} restore
- podman run -i --rm --name podbackup --env-host -v $(pwd)/test/backup-data:/test/backup-data:Z -v $(pwd)/test/restore-data:/test/restore-data:Z {{.PODBACKUP_CONTAINER_IMAGE}} list
- if [[ $(diff -r test/backup-data/ test/restore-data) ]]; then echo "TEST FAILED - RESTORE != BACKUP"; else echo "TEST SUCCESSFUL"; fi
- podman stop -i {{.MINIO_CONTAINER_NAME}}
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "/test/backup-data/"
DIR_TO_RESTORE: "/test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: "{{.CLI_ARGS}}:9000"
create-mysql:
cmds:
- podman stop -i {{.MYSQL_CONTAINER_NAME}}
- sleep 1
- podman run -d --rm -p 3306:3306 --name {{.MYSQL_CONTAINER_NAME}} -e MARIADB_USER={{.MYSQL_USER}} -e MARIADB_PASSWORD={{.MYSQL_PASSWORD}} -e MARIADB_ROOT_PASSWORD={{.MYSQL_PASSWORD}} -e MARIADB_DATABASE={{.MYSQL_DATABASE}} {{.MYSQL_CONTAINER_IMAGE}}
- sleep 10
generate-mysql-data:
cmds:
- podman exec {{.MYSQL_CONTAINER_NAME}} mysql -h 127.0.0.1 -P 3306 -u root --password={{.MYSQL_PASSWORD}} -e "CREATE DATABASE IF NOT EXISTS {{.MYSQL_DATABASE}};"
- podman exec {{.MYSQL_CONTAINER_NAME}} mysql -h 127.0.0.1 -P 3306 -u root --password={{.MYSQL_PASSWORD}} -e "use {{.MYSQL_DATABASE}}; CREATE TABLE IF NOT EXISTS testdata (id INT AUTO_INCREMENT PRIMARY KEY, testtext TEXT);"
- podman exec {{.MYSQL_CONTAINER_NAME}} mysql -h 127.0.0.1 -P 3306 -u root --password={{.MYSQL_PASSWORD}} -e "use {{.MYSQL_DATABASE}}; INSERT INTO testdata (testtext) VALUES('testtext1');"
- podman exec {{.MYSQL_CONTAINER_NAME}} mysql -h 127.0.0.1 -P 3306 -u root --password={{.MYSQL_PASSWORD}} -e "use {{.MYSQL_DATABASE}}; INSERT INTO testdata (testtext) VALUES('testtext2');"
test-backup-mysql:
deps: [build,create-minio]
cmds:
- task: create-mysql
- task: generate-mysql-data
- test/podbackup backup-sql
- podman stop -i {{.MYSQL_CONTAINER_IMAGE}}
- task: create-mysql
- test/podbackup restore-sql
- podman exec {{.MYSQL_CONTAINER_NAME}} mysql -h 127.0.0.1 -P 3306 -u root --password={{.MYSQL_PASSWORD}} -e "use {{.MYSQL_DATABASE}}; SELECT * FROM testdata;"
- podman stop -i {{.MYSQL_CONTAINER_IMAGE}}
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "test/backup-data/"
DIR_TO_RESTORE: "test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: localhost:9000
MYSQL_USER: root
MYSQL_PASSWORD: "{{.MYSQL_PASSWORD}}"
MYSQL_HOST: "127.0.0.1"
test-backup-mysql-container:
deps: [create-minio,create-mysql]
cmds:
- task: build-podbackup-container
- task: generate-mysql-data
- podman run -i --rm --name podbackup --env-host -v $(pwd)/test/backup-data:/test/backup-data:Z -v $(pwd)/test/restore-data:/test/restore-data:Z {{.PODBACKUP_CONTAINER_IMAGE}} backup-sql
- podman stop -i {{.MYSQL_CONTAINER_IMAGE}}
- task: create-mysql
- podman run -i --rm --name podbackup --env-host -v $(pwd)/test/backup-data:/test/backup-data:Z -v $(pwd)/test/restore-data:/test/restore-data:Z {{.PODBACKUP_CONTAINER_IMAGE}} restore-sql
- podman exec {{.MYSQL_CONTAINER_NAME}} mysql -h 127.0.0.1 -P 3306 -u root --password={{.MYSQL_PASSWORD}} -e "use {{.MYSQL_DATABASE}}; SELECT * FROM testdata;"
- podman stop -i {{.MYSQL_CONTAINER_IMAGE}}
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "test/backup-data/"
DIR_TO_RESTORE: "test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: "{{.CLI_ARGS}}:9000"
MYSQL_USER: root
MYSQL_PASSWORD: "{{.MYSQL_PASSWORD}}"
MYSQL_HOST: "{{.CLI_ARGS}}"
create-pgsql:
cmds:
- podman stop -i {{.PGSQL_CONTAINER_NAME}}
- sleep 1
- podman run -d --rm -p 5432:5432 --name {{.PGSQL_CONTAINER_NAME}} -e POSTGRES_DATABASE={{.PGSQL_DATABASE}} -e POSTGRES_USER={{.PGSQL_USER}} -e POSTGRES_PASSWORD={{.PGSQL_PASSWORD}} {{.PGSQL_CONTAINER_IMAGE}}
- sleep 15
generate-pgsql-data:
cmds:
- podman exec -e PGPASSWORD={{.PGSQL_PASSWORD}} {{.PGSQL_CONTAINER_NAME}} psql -h 127.0.0.1 -p 5432 -U {{.PGSQL_USER}} --command="CREATE TABLE IF NOT EXISTS testdata (id INTEGER PRIMARY KEY, testtext TEXT);" --dbname="{{.PGSQL_DATABASE}}"
- podman exec -e PGPASSWORD={{.PGSQL_PASSWORD}} {{.PGSQL_CONTAINER_NAME}} psql -h 127.0.0.1 -p 5432 -U {{.PGSQL_USER}} --command="INSERT INTO testdata (id, testtext) VALUES('1', 'testtext1');" --dbname="{{.PGSQL_DATABASE}}"
- podman exec -e PGPASSWORD={{.PGSQL_PASSWORD}} {{.PGSQL_CONTAINER_NAME}} psql -h 127.0.0.1 -p 5432 -U {{.PGSQL_USER}} --command="INSERT INTO testdata (id, testtext) VALUES('2', 'testtext2');" --dbname="{{.PGSQL_DATABASE}}"
test-backup-pgsql:
deps: [build,create-minio]
cmds:
- task: create-pgsql
- task: generate-pgsql-data
- test/podbackup backup-pgsql
- task: create-pgsql
- test/podbackup restore-pgsql
- podman exec -e PGPASSWORD={{.PGSQL_PASSWORD}} {{.PGSQL_CONTAINER_NAME}} psql -h 127.0.0.1 -p 5432 -U {{.PGSQL_USER}} --command="SELECT * FROM testdata;" --dbname="{{.PGSQL_DATABASE}}"
- podman stop -i {{.PGSQL_CONTAINER_NAME}}
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "test/backup-data/"
DIR_TO_RESTORE: "test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: localhost:9000
PGSQL_DATABASE: "{{.PGSQL_DATABASE}}"
PGSQL_USER: "{{.PGSQL_USER}}"
PGSQL_PASSWORD: "{{.PGSQL_PASSWORD}}"
PGSQL_HOST: "127.0.0.1"
test-backup-pgsql-container:
deps: [create-minio,create-pgsql]
cmds:
- task: build-podbackup-container
- task: generate-pgsql-data
- podman run -i --rm --name podbackup --env-host -v $(pwd)/test/backup-data:/test/backup-data:Z -v $(pwd)/test/restore-data:/test/restore-data:Z {{.PODBACKUP_CONTAINER_IMAGE}} backup-pgsql
- task: create-pgsql
- podman run -i --rm --name podbackup --env-host -v $(pwd)/test/backup-data:/test/backup-data:Z -v $(pwd)/test/restore-data:/test/restore-data:Z {{.PODBACKUP_CONTAINER_IMAGE}} restore-pgsql
- podman exec -e PGPASSWORD={{.PGSQL_PASSWORD}} {{.PGSQL_CONTAINER_NAME}} psql -h 127.0.0.1 -p 5432 -U {{.PGSQL_USER}} --command="SELECT * FROM testdata;" --dbname="{{.PGSQL_DATABASE}}"
- podman stop -i {{.PGSQL_CONTAINER_NAME}}
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "/test/backup-data/"
DIR_TO_RESTORE: "/test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: "{{.CLI_ARGS}}:9000"
PGSQL_DATABASE: "{{.PGSQL_DATABASE}}"
PGSQL_USER: "{{.PGSQL_USER}}"
PGSQL_PASSWORD: "{{.PGSQL_PASSWORD}}"
PGSQL_HOST: "{{.CLI_ARGS}}"
backup-pgsql:
cmds:
- task: build
- test/podbackup backup-pgsql
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "test/backup-data/"
DIR_TO_RESTORE: "test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: localhost:9000
PGSQL_DATABASE: "{{.PGSQL_DATABASE}}"
PGSQL_USER: "{{.PGSQL_USER}}"
PGSQL_PASSWORD: "{{.PGSQL_PASSWORD}}"
PGSQL_HOST: "127.0.0.1"
restore-pgsql:
cmds:
- task: build
- test/podbackup restore-pgsql
env:
AWS_BUCKET: "{{.MINIO_BUCKET_NAME}}"
DIR_TO_BACKUP: "test/backup-data/"
DIR_TO_RESTORE: "test/restore-data/"
S3_BUCKET_FOLDER: "test-data"
AWS_KEY: "{{.MINIO_ACCESS_KEY}}"
AWS_SECRET_KEY: "{{.MINIO_SECRET_KEY}}"
S3_ENDPOINT: localhost:9000
PGSQL_DATABASE: "{{.PGSQL_DATABASE}}"
PGSQL_USER: "{{.PGSQL_USER}}"
PGSQL_PASSWORD: "{{.PGSQL_PASSWORD}}"
PGSQL_HOST: "127.0.0.1"
create-all-containers:
deps: [build,create-minio,create-pgsql,create-mysql,generate-test-data]
cmds:
- task: generate-pgsql-data
- task: generate-mysql-data