#!/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
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