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" 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
} }

View File

@@ -15,15 +15,18 @@ 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
touch "$BACKUP" touch "$BACKUP"
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
@@ -35,7 +38,7 @@ if [[ "--install" == $INSTALLED ]]; then
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab - (crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
info_print "Cron job added." 6 info_print "Cron job added." 6
fi fi
exit 0 exit 0
fi fi
@@ -46,27 +49,40 @@ 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
fi fi
done < "$BACKUP" done < "$BACKUP"
source /usr/local/bin/libs/notifications.sh source /usr/local/bin/libs/notifications.sh
send_notification "All AWS-backup file have been linked" send_notification "All AWS-backup file have been linked"