View Single Post
Posts: 167 | Thanked: 204 times | Joined on Jul 2010
#2
The second step in this endeavour is a script, with some sanity checks, to launch the automated backup run overnight. Here's the first version, which I'm now prepared to risk adding to my crontab. Put this in /usr/bin/autobackupmenu and make it executable:

Code:
#!/bin/sh

# Script to launch an automated backupmenu run
# Requires: backupmenu

# Target directory where to find our backups
LOCALDIR="/media/mmc1/systemBackups";

# Number of individual archives to keep; if you backup rootfs + optfs then set this to DOUBLE the number of backup sets you want
# THIS WILL DELETE BACKUPS OUT OF THE DIRECTORY ABOVE. UNDERSTAND THAT BEFORE YOU USE IT. SET KEEP=999 to effectively disable.
KEEP=4

# Begin script

error() {
msg=$@
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"$msg" uint32:0 string:"OK";
exit 1;
}

# Check if we are on a GSM call and abort silently if so
TEST=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus | grep -o "uint32 0"`;
if [ -z "$TEST" ]; then
	exit 1;
fi;

# First check that we are on charge and abort silently if we are not
TEST=`hal-device bme | grep -o "maemo.charger.connection_status = 'connected'"`
if [ -z "$TEST" ]; then
	exit 1;
fi;

# Check that the target directory is readable, error out if not
if [ ! -r "$LOCALDIR" ]; then
	error "AutoBackupMenu was launched but could not find $LOCALDIR. Is your MMC card mounted?"
fi

# Remove all but the latest $KEEP backups, setting KEEP=4 and backing up nightly will give you 3 days' worth.
ls -1 $LOCALDIR > /tmp/.backups
cat /tmp/.backups | tail -n $KEEP > /tmp/.keep
comm -3 /tmp/.backups /tmp/.keep > /tmp/.lose
cd $LOCALDIR
cat /tmp/.lose | xargs rm -f

# Now check whether we have sufficient space on the microSD card
if [ `df|grep mmc1|awk {'print $4'}` -lt 2097152 ]; then 
	error "AutoBackupMenu was launched, but was aborted as there is less than 2GB free on your microSD card."
	exit 1; 
fi 

# Maybe insert here a check for larger OptFS, will 2GB free be sufficient?

# A few more sanity checks. We don't want to set /autobackupmenu and reboot unless and until we believe 
# it stands a good chance of working.

if [ ! -x "/usr/share/backupmenu/AutoBackupMenu.item" ]; then
	error "AutoBackupMenu could not find /usr/share/backupmenu/AutoBackupMenu.item and assumes that it is not correctly installed. Aborting."
fi

if [ -z `grep -o AutoBackupMenu /usr/share/backupmenu/BackupMenuLauncher.item` ]; then
	error "AutoBackupMenu could not find itself mentioned in /usr/share/backupmenu/BackupMenuLauncher.item and assumes that it is not correctly installed. Aborting."
fi

if [ -z `grep -o /autobackupmenu /sbin/preinit` ]; then
	error "AutoBackupMenu could not find itself mentioned in /sbin/preinit and assumes that it is not correctly installed. Aborting."
fi

# OK, good enough for us. Let's do it.

touch /autobackupmenu
reboot
If anyone can think of any more checks it might be useful to make, please comment. Before having this happen overnight it may also be a smart idea to turn off the startup video, to minimise the noise during reboot.

Update: after a few days in operation, this seems to be working fine and I'm getting nightly backup runs, subject to the phone being on charge and the keyboard being open:
maemo:~# ls -alh /media/mmc1/systemBackups/
drwxrwxrwx 2 user root 8.0K Sep 11 04:31 .
drwxrwxrwx 6 user root 8.0K Jan 1 1970 ..
-rw-r--r-- 1 user root 459.9M Sep 9 04:33 20110909-0330-optfs.tar
-rw-r--r-- 1 user root 260.6M Sep 9 04:31 20110909-0330-rootfs.tar
-rw-r--r-- 1 user root 480.5M Sep 11 04:33 20110911-0330-optfs.tar
-rw-r--r-- 1 user root 261.0M Sep 11 04:31 20110911-0330-rootfs.tar
If you want to make this work whether or not the keyboard is open, which I do, you can make another edit to /sbin/preinit to run bootmenu.sh any time there is an /autobackupmenu file on disk whether or not the keyboard is open. This is potentially dangerous in that if nothing deletes that file during the startup process, you've got a reboot loop into bootmenu that you can't fix just by closing the keyboard - so I'm leaving this as an exercise to the reader.

Last edited by magick777; 2011-09-12 at 07:59.
 

The Following User Says Thank You to magick777 For This Useful Post: