Author Topic: Automating backups for old people  (Read 1127 times)

0 Members and 1 Guest are viewing this topic.

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Automating backups for old people
« on: April 29, 2018, 11:54:29 am »
I look after the computing needs of five elderly people scattered around the country – we are all on Linux (Ubuntu & Peppermint), of course.  A major problem I have is persuading them to backup and update regularly, if at all, despite my providing a script to back up everything automatically – providing they bother to run it!  (So not very automatic!)

My thoughts turned naturally to crontab which is wonderfully easy to use and will execute a file of commands but does present a difficulty. 

My script checks for obvious errors like the wrong or absent backup-USB-stick and then offers the user optional actions, but crontab scripts execute in the background (of course) so the user cannot interact.  For desktop users, having a dedicated, separate HDD would do the trick (except when the PC is stolen) but laptop users have to use a removable USB stick. 

An ideal solution would be to get crontab to open a terminal to display error messages and get responses, but although I can get crontab to open a terminal I haven’t found a way of directing output to it or receiving input. 

I understand that crontab is designed for stand-alone, background operation and might not be an appropriate solution anyway, but I do need some kind of solution to deal with my recalcitrant friends.  Any ideas, anyone?

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: Automating backups for old people
« Reply #1 on: April 30, 2018, 04:53:19 pm »
After screwing up my LibreOffice installation whilst trying to use crontab for this project (and that will be another post!), I found a potentially good method which is to display a message image (e.g. *.png) on the screen for a brief period.
This is my code:
Code: [Select]
#!/bin/bash

#Announce a message
espeak -s 120 "backup reminder!"

#Display a message:
eog $HOME/.bin/backup_reminder.png &
sleep 0.5s

#Display the message full-screen:
wmctrl -a "backup_reminder.png"; xdotool key F11
sleep 5s

#Close the message display:
wmctrl -a "backup_reminder.png"; xdotool key Ctrl+w
It works as follows:
1. After speaking a message ("espeak" is very good if rather mechanical)
2. a reminder message is displayed using the usual "Image Viewer" and
3. is made "full-screen".
4. after a suitable delay, the image is closed.

This executable file works brilliantly from the terminal but when the file is referenced in crontab only the spoken message is executed - the image is not displayed. 
I would be very grateful for any advice on why this is not working in crontab.
Thank you
« Last Edit: May 02, 2018, 03:28:39 pm by Keith »

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: Automating backups for old people
« Reply #2 on: May 04, 2018, 09:17:11 pm »
Mark's suggestion of installing gnome-schedule in another post (https://linuxforums.org.uk/index.php?topic=13353.msg108919#msg108919) solved this problem.
It turns out that crontab won't normally execute display commands, but the gnome-schedule application has a facility for doing so - just tick a box for "X-application" - and it works fine.  The help files on the GUI scheduler indicate that it might be possible to get the simple crontab to execute display commands via a script calling another script, but I haven't tried it yet.  In any case the gnome-scheduler is nice to use. 
Another nice feature is that one can initiate "once only" timed events. 

The link above provides Mark's detailed instructions for installing/removing gnome-scheduler. 

My thanks, once more, to Mark.

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: Automating backups for old people
« Reply #3 on: May 11, 2018, 09:39:31 pm »
In the next part of this saga I first need to find the total space needed for a specified list of files to see if there is enough room on the USB stick.   It's easy enough to do this for a whole directory ( du -sc $(ls) | grep total works fine ), but for a specified list of files I need to read the list of files from a file. 
For example my list of files in "files" might be:
keith@T500:~$ more files
Desktop
Documents
Pictures
Misc
play
Programming
Radio
keith@T500:~$

and I would use:
keith@T500:~$ du -sc --files0-from=files | grep total
du: cannot access 'Desktop'$'\n''Misc'$'\n''play'$'\n''Programming'$'\n''Radio'$'\n': No such file or directory
0   total
keith@T500:~$

But it doesn't work, as you can see, although it's made a brave effort.  I've tried various hacks without success and would be very grateful for advice. 
Thank you.
« Last Edit: May 11, 2018, 09:41:03 pm by Keith »

Offline Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 17820
  • Karma: 459
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Automating backups for old people
« Reply #4 on: May 11, 2018, 11:56:40 pm »
If you want a grand total only:-
Code: [Select]
du -c $(cat /path/to/files) | tail -1 | cut -f 1
where "files" is the text file containing your list of directories.

If you want the totals for all separate directories, followed by the grand total
Code: [Select]
du -c $(cat /path/to/files) | cut -f 1
If you don't want to loose the word "total" from the grand total:
Code: [Select]
du -c $(cat /path/to/files) | tail -1
I'm guessing you don't want the du "-s" (summarise) option .. so I left it out.


« Last Edit: May 12, 2018, 12:08:26 am by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline Keith

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: Automating backups for old people
« Reply #5 on: May 12, 2018, 10:25:45 am »
You are a genius, Mark !    Lateral thinking has never been my strong point. 
I notice that cat figures prominently in the various Linux advice sites and would be a useful function to become familiar with, and I shall incorporate your code in my programme.   In fact I had used a longer and somewhat roundabout method along the same lines but yours is delightfully compact. 

It still rankles with me on principle that I can't get the  "--files0-from="  option to work, so as an aside, if you have any ideas on that, I would be interested to know of them.   Have you used it?  Perhaps it's an unreliable feature of both du and rsync

In the meantime:  my grateful thanks, as usual. 
   Keith
« Last Edit: May 12, 2018, 10:27:33 am by Keith »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal