forked from JamesClonk/backman
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from swisscom/redis
add Redis support
- Loading branch information
Showing
22 changed files
with
413 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ BACKMAN_CONFIG={"log_level":"debug","logging_timestamp":true,"username":"john"," | |
CF_INSTANCE_GUID=e5d1bf0f-7b51-4ff8-7621-9f20 | ||
VCAP_APPLICATION={"application_id":"fa05c1a9-0fc1-4fbd-bae1-139850dec7a3","application_name":"backman","application_uris":["appcloud-backman-app.example.com","backman-app.example.com","backman.example.com"],"application_version":"fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca","cf_api":"https://api.example.com","limits":{"disk":1024,"fds":16384,"mem":256},"name":"backman","organization_id":"c0134bad-97a9-468d-ab9d-e97547e3aed5","organization_name":"my-org","space_id":"06450c72-4669-4dc6-8096-45f9777db68a","space_name":"my-space","uris":["appcloud-backman-app.example.com","backman-app.example.com","backman.example.com"],"version":"fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca"} | ||
|
||
VCAP_SERVICES={"elasticsearch":[{"binding_name":null,"credentials":{"full_access_password":"yolo","full_access_username":"yolo","host":"https://yolo.elasticsearch.lyra-836.appcloud.swisscom.com","kibana_read_only_password":"yolo","kibana_read_only_username":"yolo","kibana_system_password":"yolo","kibana_system_username":"yolo","logstash_system_password":"yolo","logstash_system_username":"yolo"},"instance_name":"my-elasticsearch","label":"elasticsearch","name":"my-elasticsearch","plan":"medium","provider":null,"syslog_drain_url":null,"tags":["elasticsearch"]}],"mongodb":[{"credentials":{"uri":"mongodb://mongoadmin:[email protected]:27017","host":"127.0.0.1","port":27017,"name":"my_mongodb","database":"my-db","username":"mongoadmin","password":"super-secret"},"syslog_drain_url":null,"volume_mounts":[],"label":"mongodb","provider":null,"plan":"usage","name":"my_mongodb","tags":["mangodb","mongodb"]},{"credentials":{"uri":"mongodb://mongoadmin:[email protected]:27017","host":"127.0.0.1","port":27017,"name":"my_mongodb","database":"my-db","username":"mongoadmin","password":"super-secret"},"syslog_drain_url":null,"volume_mounts":[],"label":"mongodbent","provider":null,"plan":"usage","name":"some other mangodb!","tags":["mangodb","mongodb"]}],"mysql":[{"credentials":{"host":"127.0.0.1","port":3306,"name":"my_mysql_db","database":"mysql","username":"root","password":"my-secret-pw"},"syslog_drain_url":null,"volume_mounts":[],"label":"mysql","provider":null,"plan":"usage","name":"my_mysql_db","tags":["mysql","mariadb"]}],"postgres":[{"credentials":{"host":"127.0.0.1","hostname":"127.0.0.1","port":5432,"name":"my_postgres_db","database":"my_postgres_db","username":"dev-user","password":"dev-secret","database_uri":"postgres://dev-user:[email protected]:5432/my_postgres_db?sslmode=disable","uri":"postgres://dev-user:[email protected]:5432/my_postgres_db?sslmode=disable","jdbcUrl":"jdbc:postgres://127.0.0.1:5432/my_postgres_db?sslmode=disable"},"syslog_drain_url":null,"volume_mounts":[],"label":"postgres","provider":null,"plan":"usage","name":"my_postgres_db","tags":[]},{"credentials":{"host":"127.0.0.1","hostname":"127.0.0.1","port":5432,"name":"other_postgres_db","database":"other_postgres_db","username":"dev-user","password":"dev-secret","database_uri":"postgres://dev-user:[email protected]:5432/other_postgres_db?sslmode=disable","uri":"postgres://dev-user:[email protected]:5432/other_postgres_db?sslmode=disable","jdbcUrl":"jdbc:postgres://127.0.0.1:5432/other_postgres_db?sslmode=disable"},"syslog_drain_url":null,"volume_mounts":[],"label":"postgres","provider":null,"plan":"usage","name":"other_postgres_db","tags":[]}],"dynstrg":[{"binding_name":null,"credentials":{"accessHost":"127.0.0.1:9000","accessKey":"6d611e2d-330b-4e52-a27c-59064d6e8a62","namespace":"deadbeef","sharedSecret":"eW9sbywgeW91IGhhdmUganVzdCBiZWVuIHRyb2xsZWQh"},"instance_name":"my-database-backups","syslog_drain_url":null,"volume_mounts":[],"label":"dynstrg","provider":null,"plan":"usage","name":"my-database-backups","tags":[]}]} | ||
VCAP_SERVICES={"elasticsearch":[{"binding_name":null,"credentials":{"full_access_password":"yolo","full_access_username":"yolo","host":"https://yolo.elasticsearch.lyra-836.appcloud.swisscom.com","kibana_read_only_password":"yolo","kibana_read_only_username":"yolo","kibana_system_password":"yolo","kibana_system_username":"yolo","logstash_system_password":"yolo","logstash_system_username":"yolo"},"instance_name":"my-elasticsearch","label":"elasticsearch","name":"my-elasticsearch","plan":"medium","provider":null,"syslog_drain_url":null,"tags":["elasticsearch"]}],"redis-2":[{"binding_name":null,"credentials":{"host":"127.0.0.1","master_port":6379,"password":"very-secret","port":6379},"instance_name":"my-redis","label":"redis-2","name":"my-redis","plan":"small","provider":null,"syslog_drain_url":null,"tags":["redis"],"volume_mounts":[]}],"mongodb":[{"credentials":{"uri":"mongodb://mongoadmin:[email protected]:27017","host":"127.0.0.1","port":27017,"name":"my_mongodb","database":"my-db","username":"mongoadmin","password":"super-secret"},"syslog_drain_url":null,"volume_mounts":[],"label":"mongodb","provider":null,"plan":"usage","name":"my_mongodb","tags":["mangodb","mongodb"]},{"credentials":{"uri":"mongodb://mongoadmin:[email protected]:27017","host":"127.0.0.1","port":27017,"name":"my_mongodb","database":"my-db","username":"mongoadmin","password":"super-secret"},"syslog_drain_url":null,"volume_mounts":[],"label":"mongodbent","provider":null,"plan":"usage","name":"some other mangodb!","tags":["mangodb","mongodb"]}],"mysql":[{"credentials":{"host":"127.0.0.1","port":3306,"name":"my_mysql_db","database":"mysql","username":"root","password":"my-secret-pw"},"syslog_drain_url":null,"volume_mounts":[],"label":"mysql","provider":null,"plan":"usage","name":"my_mysql_db","tags":["mysql","mariadb"]}],"postgres":[{"credentials":{"host":"127.0.0.1","hostname":"127.0.0.1","port":5432,"name":"my_postgres_db","database":"my_postgres_db","username":"dev-user","password":"dev-secret","database_uri":"postgres://dev-user:[email protected]:5432/my_postgres_db?sslmode=disable","uri":"postgres://dev-user:[email protected]:5432/my_postgres_db?sslmode=disable","jdbcUrl":"jdbc:postgres://127.0.0.1:5432/my_postgres_db?sslmode=disable"},"syslog_drain_url":null,"volume_mounts":[],"label":"postgres","provider":null,"plan":"usage","name":"my_postgres_db","tags":[]},{"credentials":{"host":"127.0.0.1","hostname":"127.0.0.1","port":5432,"name":"other_postgres_db","database":"other_postgres_db","username":"dev-user","password":"dev-secret","database_uri":"postgres://dev-user:[email protected]:5432/other_postgres_db?sslmode=disable","uri":"postgres://dev-user:[email protected]:5432/other_postgres_db?sslmode=disable","jdbcUrl":"jdbc:postgres://127.0.0.1:5432/other_postgres_db?sslmode=disable"},"syslog_drain_url":null,"volume_mounts":[],"label":"postgres","provider":null,"plan":"usage","name":"other_postgres_db","tags":[]}],"dynstrg":[{"binding_name":null,"credentials":{"accessHost":"127.0.0.1:9000","accessKey":"6d611e2d-330b-4e52-a27c-59064d6e8a62","namespace":"deadbeef","sharedSecret":"eW9sbywgeW91IGhhdmUganVzdCBiZWVuIHRyb2xsZWQh"},"instance_name":"my-database-backups","syslog_drain_url":null,"volume_mounts":[],"label":"dynstrg","provider":null,"plan":"usage","name":"my-database-backups","tags":[]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ appcloud-backup-app | |
appcloud-backman-app | ||
backman-app | ||
backman | ||
/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ packages: | |
- mysql-client | ||
- postgresql-client-11 | ||
- mongodb-org-tools=4.2.0 | ||
- redis-tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/bash | ||
|
||
# fail on error | ||
set -e | ||
|
||
# ============================================================================================= | ||
if [[ "$(basename $PWD)" == "scripts" ]]; then | ||
cd .. | ||
fi | ||
echo $PWD | ||
|
||
# ============================================================================================= | ||
source .env | ||
|
||
# ============================================================================================= | ||
retry() { | ||
local -r -i max_attempts="$1"; shift | ||
local -r cmd="$@" | ||
local -i attempt_num=1 | ||
|
||
until $cmd | ||
do | ||
if (( attempt_num == max_attempts )) | ||
then | ||
echo "Attempt $attempt_num failed and there are no more attempts left!" | ||
return 1 | ||
else | ||
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..." | ||
sleep $(( attempt_num++ )) | ||
fi | ||
done | ||
} | ||
|
||
# ============================================================================================= | ||
echo "waiting on redis ..." | ||
retry 10 redis-cli -h 127.0.0.1 ping | ||
echo "redis is up!" | ||
|
||
echo "configuring redis auth password ..." | ||
redis-cli -h 127.0.0.1 CONFIG SET requirepass "very-secret" || true | ||
|
||
# ============================================================================================= | ||
echo "testing redis integration ..." | ||
|
||
sleep 5 | ||
# starting backman | ||
killall backman || true | ||
./backman 2>&1 & | ||
sleep 5 | ||
|
||
set -x | ||
if [ $(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:9990) != "401" ]; then | ||
echo "Should be Unauthorized" | ||
exit 1 | ||
fi | ||
|
||
if [ $(curl -s -o /dev/null -w "%{http_code}" http://john:[email protected]:9990) != "200" ]; then | ||
echo "Should be authorized" | ||
exit 1 | ||
fi | ||
|
||
if [ $(curl -s -o /dev/null -w "%{http_code}" http://john:[email protected]:9990/api/v1/state/redis-2/my-redis) != "200" ]; then | ||
echo "Failed to query state" | ||
exit 1 | ||
fi | ||
curl -s http://john:[email protected]:9990/api/v1/state/redis-2/my-redis | grep '"Status":"idle"' | ||
|
||
# write to redis | ||
redis-cli -h 127.0.0.1 -a 'very-secret' SET blubb 123 | ||
redis-cli -h 127.0.0.1 -a 'very-secret' SET blabb hello | ||
sleep 2 | ||
|
||
# trigger new backup | ||
curl -X POST http://john:[email protected]:9990/api/v1/backup/redis-2/my-redis | ||
curl -s http://john:[email protected]:9990/api/v1/state/redis-2/my-redis | grep '"Operation":"backup"' | grep '"Status":"running"' | ||
sleep 15 | ||
curl -s http://john:[email protected]:9990/api/v1/state/redis-2/my-redis | grep '"Operation":"backup"' | grep '"Status":"success"' | ||
|
||
# read from redis | ||
redis-cli -h 127.0.0.1 -a 'very-secret' GET blubb | grep 123 | ||
redis-cli -h 127.0.0.1 -a 'very-secret' GET blabb | grep hello | ||
|
||
# download backup and check for completeness | ||
FILENAME=$(curl -s http://john:[email protected]:9990/api/v1/backup/redis-2/my-redis | jq -r .Files[0].Filename) | ||
curl -s http://john:[email protected]:9990/api/v1/backup/redis-2/my-redis/${FILENAME}/download | zgrep 'blubb' | ||
|
||
# delete from redis | ||
redis-cli -h 127.0.0.1 -a 'very-secret' DEL blubb | ||
redis-cli -h 127.0.0.1 -a 'very-secret' SET blibb howdy | ||
sleep 2 | ||
redis-cli -h 127.0.0.1 -a 'very-secret' GET blubb | grep -v 123 | ||
redis-cli -h 127.0.0.1 -a 'very-secret' GET blibb | grep howdy | ||
|
||
## restore is unsupported for redis | ||
# # trigger restore | ||
# FILENAME=$(curl -s http://john:[email protected]:9990/api/v1/backup/redis-2/my-redis | jq -r .Files[0].Filename) | ||
# curl -X POST http://john:[email protected]:9990/api/v1/restore/redis-2/my-redis/${FILENAME} | ||
# curl -s http://john:[email protected]:9990/api/v1/state/redis-2/my-redis | grep '"Operation":"restore"' | grep '"Status":"running"' | ||
# sleep 15 | ||
# curl -s http://john:[email protected]:9990/api/v1/state/redis-2/my-redis | grep '"Operation":"restore"' | grep '"Status":"success"' | ||
|
||
# # read from redis | ||
# redis-cli -h 127.0.0.1 -a 'very-secret' GET blibb | grep -v howdy | ||
# redis-cli -h 127.0.0.1 -a 'very-secret' GET blubb | grep 123 | ||
# redis-cli -h 127.0.0.1 -a 'very-secret' GET blabb | grep hello | ||
|
||
# delete backup | ||
curl -X DELETE http://john:[email protected]:9990/api/v1/backup/redis-2/my-redis/${FILENAME} | ||
sleep 10 | ||
curl -s http://john:[email protected]:9990/api/v1/backup/redis-2/my-redis | grep -v 'Filename' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.