rename s3 backup subdirectory

This commit is contained in:
Karol Wypchlo 2022-03-31 14:38:06 +02:00
parent f3ec613a5a
commit 94fb6dc244
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
1 changed files with 11 additions and 3 deletions

View File

@ -13,11 +13,13 @@ ENV_VARIABLES=("AWS_ACCESS_KEY_ID" "AWS_SECRET_ACCESS_KEY" "PORTAL_DOMAIN" "SERV
for ENV_VARIABLE in "${ENV_VARIABLES[@]}"; do for ENV_VARIABLE in "${ENV_VARIABLES[@]}"; do
ENV_VARIABLE_VALUE=$(grep -v '^#' /home/user/skynet-webportal/.env | grep ${ENV_VARIABLE} || true) ENV_VARIABLE_VALUE=$(grep -v '^#' /home/user/skynet-webportal/.env | grep ${ENV_VARIABLE} || true)
if test -z "${ENV_VARIABLE_VALUE}"; then if test -z "${ENV_VARIABLE_VALUE}"; then
if $ENV_VARIABLE ~= "SERVER_DOMAIN"; then # all variables except SERVER_DOMAIN are required
if [ "${ENV_VARIABLE}" != "SERVER_DOMAIN" ]; then
echo "Environment variable ${ENV_VARIABLE} is not set" && exit 1 echo "Environment variable ${ENV_VARIABLE} is not set" && exit 1
fi fi
else
export ${ENV_VARIABLE_VALUE}
fi fi
export ${ENV_VARIABLE_VALUE}
done done
# create bucket skynet-backup-[portaldomain] (replace dots with dashes and strip anything other than alnum) # create bucket skynet-backup-[portaldomain] (replace dots with dashes and strip anything other than alnum)
@ -30,11 +32,17 @@ if test -z "${SERVER_DOMAIN}"; then
SERVER_PREFIX=$(echo ${SERVER_UID} | tr '.' '-' | tr -cd '[[:alnum:]]-') SERVER_PREFIX=$(echo ${SERVER_UID} | tr '.' '-' | tr -cd '[[:alnum:]]-')
else else
# use both uid and server domain if available (replace dots with dashes and strip anything other than alnum) # use both uid and server domain if available (replace dots with dashes and strip anything other than alnum)
SERVER_PREFIX=$(echo ${SERVER_UID}-${SERVER_DOMAIN} | tr '.' '-' | tr -cd '[[:alnum:]]-') SERVER_PREFIX=$(echo ${SERVER_DOMAIN}-${SERVER_UID} | tr '.' '-' | tr -cd '[[:alnum:]]-')
SERVER_PREFIX_LEGACY=$(echo ${SERVER_UID}-${SERVER_DOMAIN} | tr '.' '-' | tr -cd '[[:alnum:]]-')
fi fi
aws s3api create-bucket --acl private --bucket ${BUCKET_NAME} aws s3api create-bucket --acl private --bucket ${BUCKET_NAME}
# move old backup dir to new location if legacy backup path exists
if test -n "${SERVER_PREFIX_LEGACY}"; then
aws s3 mv --recursive s3://${BUCKET_NAME}/${SERVER_PREFIX_LEGACY} s3://${BUCKET_NAME}/${SERVER_PREFIX}
fi
# sync all nginx logs # sync all nginx logs
mkdir -p /home/user/skynet-webportal/docker/data/nginx/logs # ensure path exists mkdir -p /home/user/skynet-webportal/docker/data/nginx/logs # ensure path exists
aws s3 sync --no-progress /home/user/skynet-webportal/docker/data/nginx/logs s3://${BUCKET_NAME}/${SERVER_PREFIX}/docker/data/nginx/logs aws s3 sync --no-progress /home/user/skynet-webportal/docker/data/nginx/logs s3://${BUCKET_NAME}/${SERVER_PREFIX}/docker/data/nginx/logs