add some text and correct errors

This commit is contained in:
2024-12-04 09:44:32 +01:00
committed by Loïc GUEZO
parent 25da1fd321
commit e45b0a2110

View File

@@ -3,19 +3,21 @@
# change to your aws-server name # change to your aws-server name
AWS="<AWS-server Name>" AWS="<AWS-server Name>"
BACKUP="$(cd "$(dirname "$0")" && pwd)/backup_file.bak" BACKUP="$(cd "$(dirname "$0")" && pwd)/aws-bakup.bak"
LOG="/var/log/save-aws.log" LOG="/var/log/aws-bak.log"
SYNCED_FILES=""
date_print() { date_print() {
echo -n "$(date +"%Y-%m-%d %H:%M:%S") - " | tee -a $LOG echo -n "$(date +"%d-%m-%Y %H:%M:%S") - " | tee -a $LOG
} }
error_print() { error_print() {
date_print date_print
if [ "$1" ]; then if [ "$1" == "true" ]; then
echo -n "Backup error $2 -/> s3://$AWS : " | tee -a "$LOG" echo "Backup error $2 -/> s3://$AWS : " | tee -a "$LOG"
else else
echo -n "Backup succeeded --> s3://$AWS : " | tee -a "$LOG" echo "Backup succeeded --> s3://$AWS : " | tee -a "$LOG"
fi fi
} }
@@ -31,6 +33,10 @@ if [ ! -e "$BACKUP" ]; 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
continue
fi
if [ -d "$SOURCE_PATH" ] || [ -f "$SOURCE_PATH" ]; then if [ -d "$SOURCE_PATH" ] || [ -f "$SOURCE_PATH" ]; then
aws s3 sync "$SOURCE_PATH" "s3://$AWS/$(basename "$SOURCE_PATH")" --delete aws s3 sync "$SOURCE_PATH" "s3://$AWS/$(basename "$SOURCE_PATH")" --delete
@@ -39,11 +45,20 @@ while IFS= read -r SOURCE_PATH || [ -n "$SOURCE_PATH" ]; do
echo "Error while syncing $SOURCE_PATH to the AWS server." | tee -a "$LOG" echo "Error while syncing $SOURCE_PATH to the AWS server." | tee -a "$LOG"
exit 1 exit 1
fi fi
SYNCED_FILES="$SYNCED_FILES\n$SOURCE_PATH"
else else
error_print true "$SOURCE_PATH" error_print true "$SOURCE_PATH"
echo "$SOURCE_PATH not found or inaccessible." | tee -a "$LOG" echo "$SOURCE_PATH not found or inaccessible." | tee -a "$LOG"
fi fi
done < "$BACKUP" done < "$BACKUP"
if [ -n "$SYNCED_FILES" ]; then
error_print false "" error_print false ""
echo -e "Files synced:$SYNCED_FILES" | tee -a "$LOG"
else
echo "No files synced." | tee -a "$LOG"
exit 0;
fi
echo "All files synced to AWS." | tee -a "$LOG" echo "All files synced to AWS." | tee -a "$LOG"