diff --git a/libs/common.sh b/libs/common.sh index 55b4a15..ce759c0 100644 --- a/libs/common.sh +++ b/libs/common.sh @@ -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 } \ No newline at end of file diff --git a/scripts/aws-backup.sh b/scripts/aws-backup.sh index 1a42910..fd571fe 100644 --- a/scripts/aws-backup.sh +++ b/scripts/aws-backup.sh @@ -15,15 +15,18 @@ 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 touch "$BACKUP" - info_print "$BACKUP created." + 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 @@ -35,7 +38,7 @@ if [[ "--install" == $INSTALLED ]]; then (crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab - info_print "Cron job added." 6 fi - + exit 0 fi @@ -46,27 +49,40 @@ 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 fi 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" \ No newline at end of file