NB: Eu não testei isso, porque eu faço meus backups de forma diferente. No entanto, penso que funcionará.
Editar:
#! /bin/bash
newestfile=$(ls /backup/location -td | head -1)
budate=$(newestfile| cut -c10-19)
cdate=$(date --iso)
# Check if there is a backup done today
if [ $cdate = $budate ]; then
# inform user that it is checking for changes.
echo "Backup done today, checking for changes."
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Checking for changes"
# get the exit code of the diff command (1 = changes, 0 = no changes)
diffexit=$(diff /home/<USER>/dir/to/backup /backup/location/backup-$(date +%Y-%m-%d-%H:%M)-<chosendirname> && $?)
# if there are no changes tell the user
if [$diffexit = 0 ]; then
echo "Backup complete, no changes"
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Backup complete, no changes"
else
# if there are changes, tell the user
echo "Propagating changes"
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Propagating changes"
# copy it acros
cp -ar /home/<USER>/dir/to/backup /backup/location/backup-$(date +%Y-%m-%d-%H:%M)-<chosendirname>
# Tell the user it is finished
echo "Backup complete, finished propagating changes"
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Backup complete, finished all changes"
fi
# if there wasn"t a folder with the current date.
else
# Tell the user it is starting
echo "Starting backup"
notify-send --expire-time=60000 -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Starting backup for today."
# copy it across.
cp -ar /home/<USER>/dir/to/backup /backup/location/backup-$(date +%Y-%m-%d-%H:%M)-<chosendirname>
# tell the user it has finished
echo "Finished backup for today."
notify-send --expire-time=60000 -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Finished backup for today."
fi
# sleep 3 mins
sleep 500
# run itself
/home/<USER>/./script.sh
Código antigo, não tão bom:
#! /bin/bash
newestfile=$(ls /backup/location -td | head -1)
budate='echo $newestfile| cut -c10-19'
cdate=$(date --iso)
if [ $cdate = $budate ]; then
echo "Backup Done today, checking for changes."
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Checking for changes"
dirls=$(ls /home/<USER>/dir/to/backup)
dirbuls=$(ls /backup/location/$(newestfile))
if [$dirls = $dirbuls ]; then
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Backup complete, no changes"
else
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Propagating changes"
cp -ar /home/<USER>/dir/to/backup /backup/location/backup-$(date +%Y-%m-%d-%H:%M)-<chosendirname>
notify-send -i /home/<USER>/Pictures/Logos/safe.png "Backup Status" "Backup complete, finished all changes"
fi
else
echo "Starting backup"
notify-send --expire-time=60000 -i /home/<USER>/Pictures/Logos/safe.png 'Backup Status' 'Starting backup for today.'
cp -ar /home/<USER>/dir/to/backup /backup/location/backup-$(date +%Y-%m-%d-%H:%M)-<chosendirname>
notify-send --expire-time=60000 -i /home/<USER>/Pictures/Logos/safe.png 'Backup Status' 'Finished backup for today.'
fi