Skip to content

Commit 06313df

Browse files
author
Victor Machado
committed
improved s3-restore.sh
1 parent 0365c50 commit 06313df

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

s3-restore.sh

+24-17
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
# Check your AWS PROFILE at ~/.aws/credentials and ~/.aws/config
2121
# The output of rclone command should be shown in a few minuts
2222

23-
export RCLONE_S3_PROVIDER=
23+
export RCLONE_S3_PROFILE=
24+
export RCLONE_S3_REGION=
25+
export RCLONE_S3_PROVIDER=
2426
export RCLONE_S3_ENDPOINT=
25-
export RCLONE_S3_REGION=
2627
export RCLONE_S3_LOCATION_CONSTRAINT=
27-
export RCLONE_S3_PROFILE=
2828
export AWS_ACCESS_KEY_ID=
2929
export AWS_SECRET_ACCESS_KEY=
3030

@@ -86,21 +86,22 @@ check_environment() {
8686

8787
if [[ -z $RCLONE_S3_REGION ]]; then
8888
echo -e "\nWARNING: RCLONE_S3_REGION not set. Set it in the install.sh top's variables.\n"
89+
echo -e "If your S3 provider does not need a region, you can ignore this warning.\n"
8990
echo -e "You may get this information from the Where-did-the-files-go.txt manifest file\n"
9091
fi
9192

9293
if [[ -z $RCLONE_S3_LOCATION_CONSTRAINT ]]; then
9394
echo -e "\n WARNING: RCLONE_S3_LOCATION_CONSTRAINT not set. Set it in the install.sh top's variables.\n"
95+
echo -e "If your S3 provider does not need a region, you can ignore this warning.\n"
9496
echo -e "You may get this information from the Where-did-the-files-go.txt manifest file\n"
9597
fi
9698

9799
if [[ -z $RCLONE_S3_PROFILE ]]; then
98-
if [[ -z $AWS_ACCESS_KEY_ID || -z $AWS_SECRET_ACCESS_KEY ]]; then
99-
echo -e "\nAWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY not set. Set it in the install.sh top's variables.\n"
100-
echo -e "You may get this information from the Where-did-the-files-go.txt manifest file\n"
101-
exit 1
102-
else
103-
echo -e "\nRCLONE_S3_PROFILE not set. Set it in the install.sh top's variables.\n"
100+
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
101+
echo -e "\nRclone needs to configure one of two options:"
102+
echo " 1) RCLONE_S3_PROFILE"
103+
echo " 2) AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY\n"
104+
echo -e "\nSet one of them it in the install.sh top's variables.\n"
104105
echo -e "You may get this information from the Where-did-the-files-go.txt manifest file\n"
105106
exit 1
106107
fi
@@ -154,7 +155,7 @@ restore_rclone(){
154155
echo -e "\t[-]${RCLONE_S3_PROFILE} profile not found in ~/.aws/credentials. Add credentials to restore.conf.\n"
155156
exit 1
156157
else
157-
echo -e "\t\t[+] Using configured AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as AWS credentials\n"
158+
echo -e "\t\t[+] Using configured AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as AWS credentials"
158159
fi
159160
else
160161
echo -e "\t\t[+] Using ~/.aws/credentials profile:${RCLONE_S3_PROFILE}"
@@ -204,10 +205,16 @@ restore_rclone(){
204205

205206
# Execute the restore command
206207
rclone backend restore --max-depth=1 -o priority=Bulk -o lifetime=30 ${ARCHIVE_FOLDER} > ${RESTORE_OUTPUT}
207-
208+
208209
# Get the status of each file
209210
statuses=$(jq -r '.[].Status' ${RESTORE_OUTPUT})
210211

212+
# Check if the retrieve command failed
213+
if [ -z "$statuses" ]; then
214+
echo -e "\nError: Retrieve command failed. Check the configured variables at the top of the script.\n"
215+
exit 1
216+
fi
217+
211218
# Variable to store the status of the restore
212219
all_ok=true
213220

@@ -219,12 +226,12 @@ restore_rclone(){
219226
fi
220227
done
221228

229+
222230
if $all_ok; then
223231
echo -e "\nGlacier retrieve initiated."
224232
echo -e "Execute the same command again 48 hours after restore was initiated.\n"
225233
exit 0
226234
else
227-
# Retrieval already initiated
228235

229236
# Execute the restore-status command
230237
rclone backend restore-status --max-depth=1 -o priority=Bulk -o lifetime=30 ${ARCHIVE_FOLDER} > ${RESTORE_STATUS_OUTPUT}
@@ -251,25 +258,25 @@ restore_rclone(){
251258
done
252259

253260
if $all_true; then
254-
echo -e "\nRetrieve: Glacier retrieve in progress, try again 48 hours after restore was initiated.\n"
261+
echo -e "\nINFO: Glacier retrieve in progress, try again 48 hours after restore was initiated.\n"
255262
exit 0
256263
elif $all_false; then
257264
# If all files have been restored, we can proceed with the restore
258265
# This path is the only one that goes though the restore process
259-
echo -e "\nRetrieve: Glacier retrieve finished."
266+
echo -e "\nINFO: Glacier retrieve finished."
260267
else
261-
echo -e "\nRetrieve: Only some files have been retrieved. Glacier retrieve in progress, try again 48 hours after restore was initiated.\n"
268+
echo -e "\nINFO: Only some files have been retrieved. Glacier retrieve in progress, try again 48 hours after restore was initiated.\n"
262269
exit 0
263270
fi
264271
fi
265272
fi
266273

267274
### Restoring from S3 to local folder
268-
echo "Restoring from ${ARCHIVE_FOLDER} to ${DIRECTORY_PATH} ..."
275+
echo -e "\nRestoring from ${ARCHIVE_FOLDER} to ${DIRECTORY_PATH} ..."
269276
rclone copy --checksum --progress --verbose ${ARCHIVE_FOLDER} ${DIRECTORY_PATH} ${DEPTH}
270277

271278
### Comparing S3 with local folder
272-
echo "Running Checksum comparison, hit ctrl+c to cancel ... "
279+
echo -e "\nRunning Checksum comparison, hit ctrl+c to cancel ... "
273280
rclone check --verbose --exclude='.froster.md5sum' ${ARCHIVE_FOLDER} ${DIRECTORY_PATH} ${DEPTH}
274281

275282
### After restore we must check if there are any files to untar

0 commit comments

Comments
 (0)