touch NOT_MOUNTED
Then using rsync it copies only new and modified files to the backup drive and excludes all .* files, this is to stop the backing up folders like the .Trash folder. It also creates and appends a log file stored in $LOGDIR.
Add as a cron job by:
crontab -e
add @daily /root/{filename} <-- name of script
Remember to change the file to make it executable
chmod +x {filename}
Usage:
$LOGDIR = log file
$SOURCE DIR =Source directory
$DESTDIR = Destination directory
# Backup SH file by Chris Hawkins
# Get date and time
DATETIME=$(date)
LOGDIR=/usr/log
SOURCEDIR=/home
DESTDIR=/backup
mount $DESTDIR
if [ -f $DESTDIR/NOT_MOUNTED ];
then
LOGMESSAGE='Backup NOT Mounted (ERROR) - Backup NOT completed'
echo $DATETIME $LOGMESSAGE >>$LOGDIR/backuplog
else
LOGMESSAGE='Backup Started'
echo $DATETIME $LOGMESSAGE >>$LOGDIR/backuplog
rsync -auqlP --delete --exclude='.*' $SOURCEDIR $DESTDIR
# Get date and time
DATETIME=$(date)
LOGMESSAGE='Backup Completed'
echo $DATETIME $LOGMESSAGE >>$LOGDIR/backuplog
fi
cd $LOGDIR
umount $DESTDIR