diff --git a/docker-compose.yml b/docker-compose.yml index 04b14e17..0c417c64 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -294,7 +294,7 @@ services: ipv4_address: 10.10.10.83 cockroach: - image: cockroachdb/cockroach:v20.1.10 + image: cockroachdb/cockroach:v20.2.3 container_name: cockroach env_file: - .env diff --git a/scripts/crdb_backup.sh b/scripts/crdb_backup.sh new file mode 100644 index 00000000..9ec34498 --- /dev/null +++ b/scripts/crdb_backup.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Get current working directory (pwd doesn't cut it) +cwd=$(cd -P -- "$(dirname -- "$0")" && pwd -P) +# Set the environment: +set -o allexport +source $cwd/../.env +set +o allexport +# Check for AWS credentials: +if [[ $AWS_ACCESS_KEY_ID == "" || $AWS_SECRET_ACCESS_KEY == "" ]]; then + echo "Missing AWS credentials!" + exit 1 +fi +# Take the current datetime: +DT=`date +%Y-%m-%d` +# Create the backup: +docker exec cockroach \ + cockroach sql \ + --host cockroach:26257 \ + --certs-dir=/certs \ + --execute="BACKUP TO 's3://skynet-crdb-backups/backups/$DT?AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID&AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY';" diff --git a/scripts/crdb_restore.sh b/scripts/crdb_restore.sh new file mode 100644 index 00000000..f76114d1 --- /dev/null +++ b/scripts/crdb_restore.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +BACKUP=$1 +if [[ $BACKUP == "" ]]; then + echo "No backup name given. It should look like '2020-01-29'." + exit 1 +fi + +# Get current working directory (pwd doesn't cut it) +cwd=$(cd -P -- "$(dirname -- "$0")" && pwd -P) +# Set the environment: +set -o allexport +source $cwd/../.env +set +o allexport +# Check for AWS credentials: +if [[ $AWS_ACCESS_KEY_ID == "" || $AWS_SECRET_ACCESS_KEY == "" ]]; then + echo "Missing AWS credentials!" + exit 1 +fi +# Restore the backup: +docker exec cockroach \ + cockroach sql \ + --host cockroach:26257 \ + --certs-dir=/certs \ + --execute="RESTORE DATABASE defaultdb FROM 's3://skynet-crdb-backups/backups/$DT?AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID&AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY';"