To avoid editing files at the same time of backup scheduled by cron, I figure out a way:
Before backup, send a desktop notification such as
notify-send -t 0 "Ready for backup", to let me prepare (save my editing to files, and plug in external hard drive as backup destination), and when I am ready, I will click okay on the notification, and backup starts.
Once backup finishes, optionally notify me with backup command's exit value and time taken for backup, so I can resume editing.
How can I do that in bash and Ubuntu? This contains a smaller problem: how to schedule desktop notification in cron?
Feel free if you have a better way to achieve my goal at the beginning.
* * * * * /home/t/mybackup.sh to
where I wrote a bash script
/home/t/mybackup.sh wrapping backup and notifications:
#! /usr/bin/env bash export DISPLAY=:0 /usr/bin/notify-send -t 0 "Ready for backup?" && dest=/tmp/`date +%Y.%m.%d_%H:%M:%S`&& mkdir -p "$dest" && timetake=`time /usr/bin/rsync -a /home/t/program_files/dir/ "$dest"/ 2>"$dest"/rsync-errors`; exitvalue=`echo $?` /usr/bin/notify-send -t 0 "Finished backup!" "time taken: " $timetake " exit value:" $exitvalue
It has the following problems:
I want to make the first notification "Ready for backup?" wait for my response before backup. i.e. Ideally, if I click "OK", then it can continue to backup. If I click "Cancel", then it shouldn't run backup and the following commands in the script.
But in my current script, the first
notify-senddoesn't wait for my response and continue to backup.
Even if I could make it wait for my response, I don't know how to code in my script to pick up my response of whether I click "OK" or "Cancel".
notify-sendfor "Finished backup! ..." doesn't appear after backup finishes.