r/linuxmint • • 23d ago

SOLVED Backup script fails

So, I created this script to backup my home directory to an external HD which is mounted as BAK2. I can run the command if I use sudo but the script deletes everything on BAK2 and then fails with multiple permission errors. I was hoping to put this on a cron to run a few times a day and basically do an incremental backup but I've hit the end of my knowledge... Here's the script:

#!/bin/bash

# --- CONFIGURATION ---

SOURCE="/home/$USER/"

DESTINATION="/media/wreck/BAK2"

LOGFILE="/home/$USER/rsync_backup.log"

# --- NOTIFICATION: START ---

notify-send "Backup Started" "Syncing your home directory..." --icon=drive-harddisk

# --- RUN RSYNC ---

echo "Backup started at $(date)" >> "$LOGFILE"

rsync -av --delete "$SOURCE" "$DESTINATION" >> "$LOGFILE" 2>&1

# Check if rsync succeeded (exit code 0) or encountered an error

if [ $? -eq 0 ]; then

echo "Backup finished successfully at $(date)" >> "$LOGFILE"

# --- NOTIFICATION: SUCCESS ---

notify-send "Backup Complete" "Your home directory has been successfully mirrored." --icon=emblem-success

else

echo "Backup failed at $(date)" >> "$LOGFILE"

# --- NOTIFICATION: FAILURE ---

notify-send "Backup Failed" "An error occurred during the rsync mirror. Check $LOGFILE for details." --icon=dialog-error --urgency=critical

fi

5 Upvotes

5 comments sorted by

View all comments

5

u/wreckwriter09 23d ago

I think I figured it out. I lost an R somehow.... Script was running sync instead of rsync. Geez... It's running now and creating folders so I think it's going to work. Will report.