Notices


Reply
Thread Tools
Posts: 167 | Thanked: 204 times | Joined on Jul 2010
#1
Warning: This is experimental, bleeding edge, not widely tested, and has the potential to cause reboot loops or require a reflash if you don't know what you are doing. Join in at your own risk.

I've been looking for a way to automate proper backups on the N900, i.e. taking proper local backups of the RootFS and OptFS exactly as BM does, but making it happen nightly without user intervention. My design goals include working with BackupMenu, so that I can rely on it for the restore side of things. So, I've come up with a bunch of hacks and kludges that allow me to automate nightly backups using BackupMenu. It's still very much a work in progress, but I'd like to share it here for further comment and insight. Credit and thanks is due to RobbieThe1st for BackupMenu itself, without which I'd have nothing to automate.

So, as a starting point, we bastardise a copy of the core of BM to operate as if we had pressed b to backup, t for both, s twice for put both to SD card, then q to reboot once we're finished. You'll want to copy /usr/share/backupmenu/BackupMenu.item to AutoBackupMenu.item and bastardise it to suit your needs. See attached. Then, we modify the end of /usr/share/backupmenu/BackupMenu.item as follows:

Code:
if [ -f "/autobackupmenu" ]; then
rm -f /autobackupmenu
touch /nobootmenu
exec chroot /tmp/disk/ ash /usr/share/backupmenu/AutoBackupMenu.item
else
exec chroot /tmp/disk/ ash /usr/share/backupmenu/BackupMenu.item
fi
so that we will run our automated version if there is a file named /autobackupmenu, and if there is not then we run the conventional BackupMenu core. We also get rid of our trigger file and create another file, /nobootmenu, to be used from /sbin/preinit to avoid looping. We modify /sbin/preinit to check for that file and run bootmenu.sh only if it doesn't exist, deleting the file but not running bootmenu.sh this one time if it does.:

Code:
       
if [ x"$SLIDE_STATE" = "xopen" ] && [ ! -f "/nobootmenu" ]; then
  echo_g "slide open, attempting to use bootmenu"
  [ -f /bootmenu.sh ] && . /bootmenu.sh
fi
[ -f /nobootmenu ] && rm -f /nobootmenu
The upshot of all this should be (is, for me) that we can

Code:
touch /autobackupmenu; reboot
and the N900 will reboot itself, load /bootmenu.sh leading BackupMenuLauncher leading to the automated BackupMenu core, delete the /autobackupmenu trigger file and set a /nobootmenu file instead, take a RootFS backup, take an OptFS backup, and reboot again. Whereupon /sbin/preinit will detect a /nobootmenu file and not launch backupmenu again, even if the keyboard is open, so the N900 will reboot nicely into Maemo, and will then delete that file so it stops bootmenu.sh one time only.

And that's as far as I've got. Still need to clean up the old backups and devise some sanity checks to run before I automate the business of running this from cron. Comments and constructive criticisms welcomed; deploy at your own risk.
Attached Files
File Type: zip AutoBackupMenu.item.zip (5.8 KB, 72 views)

Last edited by magick777; 2011-09-06 at 03:09.
 

The Following 5 Users Say Thank You to magick777 For This Useful 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:
Reply


 
Forum Jump


All times are GMT. The time now is 06:06.