You could simplify your folder name generation:
Code:
# Manual user
backup_folder=/media/<user>/usb_hdd/backups/$(date +%Y-%m-%d)
# Current user
backup_folder=/media/$(whoami)/usb_hdd/backups/$(date +%Y-%m-%d)
You could also tweak your "mkdir" command to auto-create parent dirs if not existing:
Code:
# Your code:
mkdir $backup_folder
mkdir $backup_folder/usr
mkdir $backup_folder/var
mkdir $backup_folder/var/spool
mkdir $backup_folder/var/spool/cron
# Required code:
mkdir -p $backup_folder/var/spool/cron
mkdir $backup_folder/usr
EDIT: In fact it would probably be better to create folders before the rsync command:
Code:
backupFolder() {
{
if [ ! -d $backup_folder$1 ]; then mkdir -p $backup_folder$1; fi
rsync -aur $1 $backup_folder$1
log "Folder $1 successfully backed up to $backup_folder$1"
} || log "Could not backup folder $1!"
}
Bookmarks