-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshellCodeAllinOne.txt
More file actions
63 lines (42 loc) · 2.86 KB
/
Copy pathshellCodeAllinOne.txt
File metadata and controls
63 lines (42 loc) · 2.86 KB
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
#codeFrom brittle unix-shell-based poc:
## this block does the export call to redisEnterprise:
. envars
DATE=gdate # Use gdate to mimic linux date on mac. Install thus: brew install coreutils
EXPIRY=$(${DATE:?} -u -d "60 minutes" '+%Y-%m-%dT%H:%MZ')
TOKEN=$(az storage container generate-sas --account-key $SRC_ACCOUNT_ACCESS_KEY --account-name $SRC_ACCOUNT --expiry "${EXPIRY}" --name $SRC_CONTAINER --permissions dlrw | tr -d '"')
SAS_URI="https://${SRC_ACCOUNT:?}.blob.core.windows.net/${SRC_CONTAINER:?}?${TOKEN:?}"
JSON_BODY="{ \"sasUri\": \"${SAS_URI:?};${SRC_ACCOUNT_ACCESS_KEY:?}\" }"
az rest -m POST -u https://management.azure.com/subscriptions/${SUBSCRIPTION_ID:?}/resourceGroups/${RESOURCE_GROUP_NAME:?}/providers/Microsoft.Cache/redisEnterprise/${SRC_CLUSTER_NAME:?}/databases/${SRC_DATABASE_NAME:?}/export?api-version=2021-03-01 -b "$JSON_BODY"
## this block does the import call to redisEnterprise:
. envars
DEST_BLOB_NAME=${1:?No blob name given}
DATE=gdate # Use gdate to mimic linux date on mac. Install thus: brew install coreutils
EXPIRY=$(${DATE} -u -d "60 minutes" '+%Y-%m-%dT%H:%MZ')
TOKEN=$(az storage blob generate-sas --account-key ${DEST_ACCOUNT_ACCESS_KEY:?} --account-name ${DEST_ACCOUNT:?} --expiry "${EXPIRY:?}" --container-name ${DEST_CONTAINER:?} --name ${DEST_BLOB_NAME:?} --permissions r | tr -d '"')
SAS_URI="https://${DEST_ACCOUNT:?}.blob.core.windows.net/${DEST_CONTAINER:?}/${DEST_BLOB_NAME:?}?${TOKEN:?}"
JSON_BODY="{ \"sasUri\": \"${SAS_URI};${DEST_ACCOUNT_ACCESS_KEY}\" }"
az rest -m POST -u https://management.azure.com/subscriptions/${SUBSCRIPTION_ID:?}/resourceGroups/${RESOURCE_GROUP_NAME:?}/providers/Microsoft.Cache/redisEnterprise/${DEST_CLUSTER_NAME:?}/databases/${DEST_DATABASE_NAME:?}/import?api-version=2021-03-01 -b "$JSON_BODY"
## this block does the copy from storage to storage:
. envars
SRC_BLOB=${1:?"No source blob given"}
DEST_BLOB=${SRC_BLOB:?}
az storage blob copy start --source-container ${SRC_CONTAINER:?} --source-blob ${SRC_BLOB:?} --destination-container ${DEST_CONTAINER:?} --destination-blob ${DEST_BLOB:?} --account-name ${DEST_ACCOUNT:?} --account-key ${DEST_ACCOUNT_ACCESS_KEY:?} --source-account-name ${SRC_ACCOUNT:?} --source-account-key ${SRC_ACCOUNT_ACCESS_KEY:?}
## this is the environment variables block:
SUBSCRIPTION_ID="ef03f41d-d2bd-4691-b3a0-3aff1c6711f7"
RESOURCE_GROUP_NAME=redisgeeknjhc
# Source, or primary, location
## Storage
SRC_ACCOUNT=sourceaccount
SRC_ACCOUNT_ACCESS_KEY="garbledegookwOIBlx3nkvVo1Q=="
SRC_CONTAINER=sourcecontainer-xyz
## Redis Enterprise Cache
SRC_CLUSTER_NAME=primary-redis-xyz
SRC_DATABASE_NAME=default
# Destination, or secondary, location
## Storage
DEST_ACCOUNT=backupabc
DEST_ACCOUNT_ACCESS_KEY='garbledegook5NDUMlKGetjgSMOctXyNjUvEoNeaOnkf1cL3J9Qg=='
DEST_CONTAINER=destinationcontainer-abc
## Redis Enterprise Cache
DEST_CLUSTER_NAME=backup-redis-abc
DEST_DATABASE_NAME=default