feat(aws-backup): add endpoint variable

This commit is contained in:
2025-07-31 14:37:14 +02:00
parent bad61e1fcf
commit 6beeb2738b
2 changed files with 27 additions and 11 deletions

View File

@@ -76,9 +76,9 @@ create_raw_line_variable() {
local file="$2"
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
echo "$line" >> "$file"
info_print "'$line' added as raw line."
info_print "'$line' added as raw line." 6
fi
}

View File

@@ -16,6 +16,9 @@ if [[ "--install" == $INSTALLED ]]; then
read -p "Enter aws server: " 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."
aws configure
@@ -23,7 +26,7 @@ if [[ "--install" == $INSTALLED ]]; then
info_print "$BACKUP created."
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
create_raw_line_variable "$key" $BACKUP
done
@@ -46,22 +49,35 @@ if [[ "$1" == "clean" ]]; then
fi
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
fi
if [ -d "$SOURCE_PATH" ] || [ -f "$SOURCE_PATH" ]; then
aws_cmd=(aws s3 sync "$SOURCE_PATH" "s3://$BUCKET/$(basename "$SOURCE_PATH")" --profile scaleway --delete)
if [[ -d "$SOURCE_PATH" || -f "$SOURCE_PATH" ]]; then
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
info_print "Using custom endpoint: $ENDPOINT"
aws_cmd+=("--endpoint-url" "$ENDPOINT")
fi
$aws_cmd
"${aws_cmd[@]}"
if [ $? -ne 0 ]; then
info_print "Error while syncing $SOURCE_PATH to the AWS server." 3
exit 1
else
info_print "Successfully synced $SOURCE_PATH" 6
fi
else
info_print "$SOURCE_PATH not found or inaccessible." 3