-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
95 lines (75 loc) · 2.56 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
MKDIR = mkdir -p
COPY_TO = cp -vt
DATA_PATH = data
BACKUP := $(shell date +"%Y-%m-%d_%H-%M-%S")
BACKUP_PATH = backup/$(BACKUP)
MONGODB_DATA = $(DATA_PATH)/mongodb
UPLOADS_DATA = $(DATA_PATH)/uploads
MONGODB_BACKUP = $(BACKUP_PATH)/mongodb
UPLOADS_BACKUP = $(BACKUP_PATH)/uploads
help:
@echo "See README.md#utilities"
.PHONY: backup dirs
dirs:
mkdir -p \
$(DATA_PATH)/logs/ \
$(DATA_PATH)/mongodb/ \
$(DATA_PATH)/uploads/ \
$(dir BACKUP_PATH)
build: dirs
docker-compose pull mongo
docker-compose build infolis-web
docker-compose build infolink
#
# Create backups
#
backup: backup-files backup-mongodb
backup-files:
$(MKDIR) $(UPLOADS_BACKUP)
find $(UPLOADS_DATA) -type f -exec $(COPY_TO) "$(UPLOADS_BACKUP)" {} \;
backup-mongodb:
$(MKDIR) $(MONGODB_BACKUP)
docker exec infolis-mongo mongodump --out $(MONGODB_BACKUP)
#
# Restore backups
#
restore: restore-files restore-mongodb
restore-files:
@if [ ! -e "$(UPLOADS_BACKUP)" ];then echo "No such folder $(UPLOADS_BACKUP)\nUsage: make $@ BACKUP=<backup-timestamp>" ; exit 2 ;fi
find "$(UPLOADS_BACKUP)" -type f -exec $(COPY_TO) "$(UPLOADS_DATA)" {} \;
restore-mongodb: dropIndexes
@if [ ! -e "$(MONGODB_BACKUP)" ];then echo "No such folder $(MONGODB_BACKUP)\nUsage: make $@ BACKUP=<backup-timestamp>" ; exit 2 ;fi
docker exec infolis-mongo mongorestore --noIndexRestore $(MONGODB_BACKUP)
#
# Delete database or remove uploads
#
clear: clear-mongodb clear-files
clear-mongodb:
@echo "This will completely wipe the DB.\n<CTRL-C> to cancel <Enter> to continue" \
&& read confirm\
&& docker exec infolis-mongo mongo infolis-web --eval "db.dropDatabase()"
clear-files:
@echo "This will completely wipe all files.\n<CTRL-C> to cancel <Enter> to continue" \
&& read confirm\
&& find "$(UPLOADS_DATA)" -type f -exec rm -f {} \;
#
# XXX Disabled for now, cronjob not active anyway
# Backup to server
# - This only backs up the DB!
#
# backup-to-server: backup-mongodb
# @if [ -z "$(BACKUP_SERVER)" ];then echo "Usage: make backup-to-server BACKUP_SERVER=user@server:/path"; exit 1;fi
# rsync -Prz --progress backup/$(BACKUP) $(BACKUP_SERVER)
# # rm -rf "$(BACKUP)"
dropIndexes:
docker exec infolis-mongo mongo infolis-web --eval \
"db.getCollectionNames().forEach(function(col) { \
db.runCommand({'dropIndexes': col, 'index': '*'}); \
});"
listIndexes:
docker exec infolis-mongo mongo infolis-web --eval \
"db.getCollectionNames().forEach(function(collection) { \
indexes = db[collection].getIndexes(); \
print('Indexes for ' + collection + ':'); \
printjson(indexes); \
});"