-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs-backup-daily.sh
executable file
·58 lines (48 loc) · 1.49 KB
/
cs-backup-daily.sh
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
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# CONSUL KEY/VALUE BACKUP SNAPSHOT & EXPORT JSON FILE
# -----------------------------------------------------------------------------
# Author : Dwi Fahni Denni (@zeroc0d3)
# License : Apache version 2.0
# -----------------------------------------------------------------------------
export PATH_SNAPSHOT="/root/consul-snapshot"
export PATH_DIR="daily"
export PATH_BACKUP=$PATH_SNAPSHOT"/"$PATH_DIR
export TOKEN_AUTH_PROD="[YOUR_PROD_ACL_MASTER_TOKEN]"
export TOKEN_AUTH_STAGING="[YOUR_STAGING_ACL_MASTER_TOKEN]"
export ENV="0" # (0 = staging, 1 = production)
export SNAPSHOT_FILE=$(date +%Y-%m-%d)
select_env() {
if [ "$ENV" = "0" ]
then
export ENV_TOKEN="$TOKEN_AUTH_STAGING"
else
export ENV_TOKEN="$TOKEN_AUTH_PROD"
fi
}
create_snapshot_folder(){
mkdir -p $PATH_BACKUP
}
run_snapshot() {
select_env
/usr/local/bin/consul snapshot save -token=$ENV_TOKEN $PATH_BACKUP/$SNAPSHOT_FILE.snap
}
run_export() {
/usr/local/bin/consul kv export -token=$ENV_TOKEN / > $PATH_BACKUP/$SNAPSHOT_FILE.json
}
run_cloud_store(){
# Right here you can use AWS S3, GCP Object Storage, etc
# for better storing backup file & restore
# example AWS S3:
# ----------------
# aws s3 cp $PATH_BACKUP s3://bucket/ --recursive \
# --exclude "*" --include "*.snap" --include "*.json"
}
main() {
create_snapshot_folder
run_snapshot
run_export
run_cloud_store
}
### START HERE ###
main $@