mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-01-25 04:34:23 +00:00
feat(aws-backup): add endpoint variable
This commit is contained in:
@@ -76,9 +76,9 @@ create_raw_line_variable() {
|
|||||||
local file="$2"
|
local file="$2"
|
||||||
|
|
||||||
if grep -Fxq "$line" "$file" 2>/dev/null; then
|
if grep -Fxq "$line" "$file" 2>/dev/null; then
|
||||||
info_print "'$line' already defined as raw line."
|
info_print "'$line' already defined as raw line." 2
|
||||||
else
|
else
|
||||||
echo "$line" >> "$file"
|
echo "$line" >> "$file"
|
||||||
info_print "'$line' added as raw line."
|
info_print "'$line' added as raw line." 6
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,9 @@ if [[ "--install" == $INSTALLED ]]; then
|
|||||||
read -p "Enter aws server: " AWS_client
|
read -p "Enter aws server: " AWS_client
|
||||||
create_env_variable "AWS" "$AWS_client"
|
create_env_variable "AWS" "$AWS_client"
|
||||||
|
|
||||||
|
read -p "Enter endpoint server (leave empty to not define it): " ENDPOINT_server
|
||||||
|
[[ ! -n $ENDPOINT_server ]] && create_env_variable "ENDPOINT" "$ENDPOINT_server"
|
||||||
|
|
||||||
info_print "AWS configuration."
|
info_print "AWS configuration."
|
||||||
aws configure
|
aws configure
|
||||||
|
|
||||||
@@ -23,7 +26,7 @@ if [[ "--install" == $INSTALLED ]]; then
|
|||||||
info_print "$BACKUP created."
|
info_print "$BACKUP created."
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
read -p "Add backup directory or file name (key or leave empty to quit): " key
|
read -p "Add backup directory or file name (leave empty to quit): " key
|
||||||
[[ -z "$key" ]] && break
|
[[ -z "$key" ]] && break
|
||||||
create_raw_line_variable "$key" $BACKUP
|
create_raw_line_variable "$key" $BACKUP
|
||||||
done
|
done
|
||||||
@@ -46,22 +49,35 @@ if [[ "$1" == "clean" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS= read -r SOURCE_PATH || [ -n "$SOURCE_PATH" ]; do
|
while IFS= read -r SOURCE_PATH || [ -n "$SOURCE_PATH" ]; do
|
||||||
if [ -z "$SOURCE_PATH" ] || [[ "$SOURCE_PATH" =~ ^[[:space:]]*$ ]]; then
|
if [[ -z "$SOURCE_PATH" || "$SOURCE_PATH" =~ ^[[:space:]]*$ ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "$SOURCE_PATH" ] || [ -f "$SOURCE_PATH" ]; then
|
if [[ -d "$SOURCE_PATH" || -f "$SOURCE_PATH" ]]; then
|
||||||
aws_cmd=(aws s3 sync "$SOURCE_PATH" "s3://$BUCKET/$(basename "$SOURCE_PATH")" --profile scaleway --delete)
|
DEST="s3://$AWS/$(basename "$SOURCE_PATH")"
|
||||||
|
|
||||||
|
if [[ -d "$SOURCE_PATH" ]]; then
|
||||||
|
info_print "Syncing directory: $SOURCE_PATH → $DEST"
|
||||||
|
aws_cmd=(aws s3 sync "$SOURCE_PATH" "$DEST" --delete)
|
||||||
|
elif [[ -f "$SOURCE_PATH" ]]; then
|
||||||
|
info_print "Uploading file: $SOURCE_PATH → $DEST"
|
||||||
|
aws_cmd=(aws s3 cp "$SOURCE_PATH" "$DEST")
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n "$ENDPOINT" ]]; then
|
if [[ -n "$ENDPOINT" ]]; then
|
||||||
|
info_print "Using custom endpoint: $ENDPOINT"
|
||||||
aws_cmd+=("--endpoint-url" "$ENDPOINT")
|
aws_cmd+=("--endpoint-url" "$ENDPOINT")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$aws_cmd
|
|
||||||
|
"${aws_cmd[@]}"
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
info_print "Error while syncing $SOURCE_PATH to the AWS server." 3
|
info_print "Error while syncing $SOURCE_PATH to the AWS server." 3
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
else
|
||||||
|
info_print "Successfully synced $SOURCE_PATH" 6
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
info_print "$SOURCE_PATH not found or inaccessible." 3
|
info_print "$SOURCE_PATH not found or inaccessible." 3
|
||||||
|
|||||||
Reference in New Issue
Block a user