Backup

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m (Replacing 'Freerunner' with 'FreeRunner')
(Undo revision 82184 by Mefio (Talk):spam)
 
(42 intermediate revisions by 22 users not shown)
Line 1: Line 1:
 +
== Backing up just PIM data ==
 +
 +
The following applies to all Qtopia PIM suite based derivations (FDOM, 2008.8, Qtopia). PIM data covers:
 +
 +
* Contacts, calendar appointments, and tasks
 +
* E-Mails and text messages
 +
 +
To make a backup which can be easily restored later on use secure copy:
 +
 +
scp -pr root@192.168.0.202:~/Applications/ .
 +
scp -pr root@192.168.0.202:~/Documents/ .
 +
 +
To restore do the reverse:
 +
 +
scp -pr Applications root@192.168.0.202:~/
 +
scp -pr Documents root@192.168.0.202:~/
 +
 +
Make sure you restart to allow the Qtopia PIM suite to see the changes:
 +
 +
reboot
 +
 +
This way we can flash applicable distributions with minimal effort without loosing important data. To access the PIM data on the computer take a look at the following files and folders:
 +
 +
* Contacts, calendar appointments, and tasks are kept in <tt>~/Applications/Qtopia/qtopia_db.sqlite</tt>.
 +
* E-Mails and text messages are kept in <tt>~/Applications/qtmail/mail/</tt>.
 +
 
== Backing up just /home/root ==
 
== Backing up just /home/root ==
  
To backup the home folder (all your files personal files in theory).
+
To backup the home folder (all your personal files in theory).
  
 
From the desktop pc run:
 
From the desktop pc run:
Line 7: Line 33:
 
  ssh root@phone 'tar -cpz /home/root' > moko-home-`date +%Y%m%d-%H%M%S`.tar.gz
 
  ssh root@phone 'tar -cpz /home/root' > moko-home-`date +%Y%m%d-%H%M%S`.tar.gz
  
Where phone is the ip address of your phone (192.168.0.202).
+
Where '''<tt>phone</tt>''' is the ip address of your phone (192.168.0.202).
  
 
Personally I added an entry to /etc/hosts so the above works for me. I also added the desktop key to /home/root/.ssh/authorized_keys on the phone as per the instructions in [[USB_Networking#SSH_Keys]].
 
Personally I added an entry to /etc/hosts so the above works for me. I also added the desktop key to /home/root/.ssh/authorized_keys on the phone as per the instructions in [[USB_Networking#SSH_Keys]].
Line 20: Line 46:
  
 
You may either :
 
You may either :
* Backup the flash contents, in order to be able to restore (see bellow)
+
* Backup the flash contents, in order to be able to restore (see below)
 
* or move the system to SD to be able to boot it from SD in case of need. See [[Moving current system from flash to SD]]
 
* or move the system to SD to be able to boot it from SD in case of need. See [[Moving current system from flash to SD]]
  
 
=== Backing-up flash images ===
 
=== Backing-up flash images ===
 +
 +
{{note|Upload support is currently broken - [http://docs.openmoko.org/trac/ticket/676 #676], [http://docs.openmoko.org/trac/ticket/1843 #1843]}}
  
 
You will need the [[Dfu-util]] to make a backup of your existing image.
 
You will need the [[Dfu-util]] to make a backup of your existing image.
  
As when [[Flashing_the_Neo_FreeRunner|flashing]], you will need to be in [[Booting_the_Neo_FreeRunner#Log_into_U-Boot_in_the_NOR_Flash|U-Boot in the NOR Flash]]. Log into the NOR uBoot menu and select ''Set console to USB'' (for NRF just stay in NOR uBoot menu, do not select or enter anything). Now you will be able to flash, make backups of your FreeRunner or query the FreeRunner with [[Dfu-util|dfu-util]].  Backup is fairly slow; it took over ten minutes to back up a 247 MB rootfs.
+
As when [[Flashing_the_Neo_FreeRunner|flashing]], you will need to be in [[Booting_the_Neo_FreeRunner#Log_into_U-Boot_in_the_NOR_Flash|U-Boot in the NOR Flash]]. Log into the NOR uBoot menu and select ''Set console to USB'' (for FreeRunner just stay in NOR uBoot menu, do not select or enter anything). Now you will be able to flash, make backups of your FreeRunner or query the FreeRunner with [[Dfu-util|dfu-util]].  Backup is fairly slow; it took over ten minutes to back up a 247 MB rootfs.
  
 
It is important that you connect the USB cable directly from your computer to your phone.  If there is a hub between them, backup (and flashing) will mostly likely fail.
 
It is important that you connect the USB cable directly from your computer to your phone.  If there is a hub between them, backup (and flashing) will mostly likely fail.
Line 69: Line 97:
 
DEVICE_CONFIGURED: 1
 
DEVICE_CONFIGURED: 1
 
Starting DFU Upload of partition 'kernel'
 
Starting DFU Upload of partition 'kernel'
 +
DEVICE_CONFIGURED: 1
 
</pre>
 
</pre>
  
 
A failed run of dfu-util looks like this:
 
A failed run of dfu-util looks like this:
 +
<pre>
 +
dfu-util - (C) 2007 by Openmoko Inc.
 +
This program is Free Software and has ABSOLUTELY NO WARRANTY
  
dfu-util - (C) 2007 by Openmoko Inc.
+
Opening USB Device 0x0000:0x0000...
This program is Free Software and has ABSOLUTELY NO WARRANTY
+
Claiming USB DFU Runtime Interface...
+
Determining device status: state = appIDLE, status = 0
Opening USB Device 0x0000:0x0000...
+
Device really in Runtime Mode, send DFU detach request...
Claiming USB DFU Runtime Interface...  
+
Resetting USB...
Determining device status: state = appIDLE, status = 0
+
Opening USB Device...
Device really in Runtime Mode, send DFU detach request...
+
Found Runtime: [0x1d50:0x5119] devnum=20, cfg=0, intf=0, alt=6, name="rootfs"
Resetting USB...  
+
Claiming USB DFU Interface...
Opening USB Device...
+
Setting Alternate Setting ...
Found Runtime: [0x1d50:0x5119] devnum=20, cfg=0, intf=0, alt=6, name="rootfs"
+
Determining device status: state = dfuIDLE, status = 0
Claiming USB DFU Interface...
+
dfuIDLE, continuing
Setting Alternate Setting ...
+
Transfer Size = 0x1000
Determining device status: state = dfuIDLE, status = 0
+
dfu_upload error -110
dfuIDLE, continuing
+
</pre>
Transfer Size = 0x1000
+
And shows demsg errors like this:
dfu_upload error -110
+
<pre>
 +
usb 5-2: usbfs: USBDEVFS_CONTROL failed cmd dfu-util rqt 161 rq 2 len 4096 ret -110
 +
</pre>
 +
This error is detected within the Linux USB stack (drivers/usb/core/message.c) and looking at
 +
errno.h for the negatived error status number, the reason is e.g.
 +
{|
 +
| 110 || ETIMEDOUT || Connection timed out
 +
|-
 +
|  84 || EILSEQ    || Illegal byte sequence
 +
|-
 +
| 108 || ESHUTDOWN || Cannot send after transport endpoint shutdown
 +
|-
 +
| ... ||          ||
 +
|}
 +
Insure yourself, that you connect the FR directly to the computer (without any USB hubs), if you experience timed out connections
 +
and use the
 +
 
 +
dfu-util -d [[USB Product IDs|0x1d50:0x5119]] ...
 +
 
 +
option, if the FR is not detected properly.
 +
 
 +
=== Backing-up flash images (alternative) ===
 +
 
 +
On the device:
 +
<pre>
 +
mkdir /var/tmp/root
 +
mount /dev/root /var/tmp/root
 +
</pre>
 +
 
 +
If you have om2008.9 you have to use:
 +
<pre>
 +
mount -t jffs2 /dev/mtdblock6 /var/tmp/root
 +
</pre>
 +
 
 +
On your workstation:
 +
<pre>
 +
ssh root@192.168.0.202 "mkfs.jffs2 -d /var/tmp/root -e 128 --pad --no-cleanmarkers -x lzo" | pv -W > rootfs.jffs2
 +
</pre>
 +
(The "| pv -W" is optional, it just gives you something to watch as the bytes fly by.)
 +
 
 +
On the device:
 +
<pre>
 +
umount /var/tmp/root
 +
</pre>
 +
 
 +
=== Backing-up in a tar archive ===
 +
 
 +
ssh root@192.168.0.202 "tar c /bin /etc /home /lib /opt /sbin /tmp /usr /var" | pv -s 2200000 -W > rootfs.tar
 +
(The "| pv -W" is optional, it just gives you something to watch as the bytes fly by; the "-s" option presume you're transferring 2200000 bytes of data)
  
And shows errors demsg like this:
+
Extract it and use <code>mkfs.jffs2</code> if you want convert it to a jffs2 image.
usb 5-2: usbfs: USBDEVFS_CONTROL failed cmd dfu-util rqt 161 rq 2 len 4096 ret -110
+
  
 
==Backup Scripts==
 
==Backup Scripts==
Line 129: Line 208:
 
#############################################################################################################
 
#############################################################################################################
 
##                                                                                                        ##
 
##                                                                                                        ##
## This script is Free Software is licensed under the GPLv3 and has ABSOLUTELY NO WARRANTY                 ##
+
## This script is Free Software, it's licensed under the GPLv3 and has ABSOLUTELY NO WARRANTY             ##
 
## you can find and read the complete version of the GPLv3 @ http://www.gnu.org/licenses/gpl.html          ##
 
## you can find and read the complete version of the GPLv3 @ http://www.gnu.org/licenses/gpl.html          ##
 
##                                                                                                        ##
 
##                                                                                                        ##
Line 138: Line 217:
 
## IMPORTANT:!!! REMEMBER TO RUN THIS SCRIPT AS ROOT SINCE dfu-util HAS TO BE USED AS ROOT!!!              ##
 
## IMPORTANT:!!! REMEMBER TO RUN THIS SCRIPT AS ROOT SINCE dfu-util HAS TO BE USED AS ROOT!!!              ##
 
##                                                                                                        ##
 
##                                                                                                        ##
## based on the orginal simple backup script at http://wiki.openmoko.org/wiki/Pre-Flash_Backup            ##
+
## based on the orginal simple backup script at http://wiki.openmoko.org/wiki/Backup                      ##
 
##                                                                                                        ##
 
##                                                                                                        ##
 
## this version has been conceived and written by cga, x77686d, Infoport, jomat at /server irc.freenode.net##
 
## this version has been conceived and written by cga, x77686d, Infoport, jomat at /server irc.freenode.net##
Line 248: Line 327:
  
 
</pre>
 
</pre>
[[category:Guides]]
+
 
[[category:Technical]]
+
=== Pretty GUI Script ===
 +
 
 +
[[NeoTool]] is a zenity-based script which allows you to both backup and Flash your device from a pretty GUI. It uses both the dfu-util method and the alternate method described on this page, and can produce flashable images of everything including rootfs. Check it out.
 +
 
 +
== Backing up the incremental rsync hardlink way ==
 +
 
 +
Following is a very simple implementation of
 +
[http://www.mikerubel.org/computers/rsync_snapshots/ incremental rsync snapshots with hardlinks]. Just put it to /etc/cron.daily/backup-neo
 +
on your PC and setup ssh keys between your PC and neo. It will then
 +
daily try to backup all files in the / partition. Each successful
 +
backup is hardlinked under a timestamped directory so you can access
 +
old backups easily. In fact, you can even NFS mount /backup/neo to
 +
phone and then chroot inside the backups to run programs in the
 +
backup'ed environment.
 +
#!/bin/bash
 +
# /etc/cron.daily/backup-neo
 +
rsync --delete -ax --numeric-ids 192.168.0.202:/ /backup/neo/latest 2>  /dev/null
 +
ret=$?
 +
 +
case $ret in
 +
0)
 +
        # backup done, let's save it
 +
        cp -al /backup/neo/latest /backup/neo/`date -I`
 +
        ;;
 +
12)
 +
        # neo was not at home
 +
        ;;
 +
*)
 +
        echo "backup failed with return value $ret"
 +
        ;;
 +
esac
 +
 
 +
== Backing up internal flash when booted on external SD-card ==
 +
 
 +
#Freerunner
 +
mkdir internal_flash
 +
mount /dev/mtdblock6 internal_flash -t jffs2
 +
 
 +
Now you can pack directory or copy selected files out from it.
 +
 
 +
(This mounting is usefull also if your internal operating system is non-bootable. You can get files out or even repair the system using operating system on external card.)
 +
 
 +
== Weblinks ==
 +
* [http://www.oesf.org/forum/index.php?showtopic=25994#entry178835 read jffs file system on pc]
 +
 
 +
[[Category:PIM]]
 +
[[category:Advanced End User]]
 +
[[Category:Flashing Openmoko]]

Latest revision as of 20:51, 29 August 2010

Contents

[edit] Backing up just PIM data

The following applies to all Qtopia PIM suite based derivations (FDOM, 2008.8, Qtopia). PIM data covers:

* Contacts, calendar appointments, and tasks
* E-Mails and text messages

To make a backup which can be easily restored later on use secure copy:

scp -pr root@192.168.0.202:~/Applications/ .
scp -pr root@192.168.0.202:~/Documents/ .

To restore do the reverse:

scp -pr Applications root@192.168.0.202:~/
scp -pr Documents root@192.168.0.202:~/

Make sure you restart to allow the Qtopia PIM suite to see the changes:

reboot

This way we can flash applicable distributions with minimal effort without loosing important data. To access the PIM data on the computer take a look at the following files and folders:

  • Contacts, calendar appointments, and tasks are kept in ~/Applications/Qtopia/qtopia_db.sqlite.
  • E-Mails and text messages are kept in ~/Applications/qtmail/mail/.

[edit] Backing up just /home/root

To backup the home folder (all your personal files in theory).

From the desktop pc run:

ssh root@phone 'tar -cpz /home/root' > moko-home-`date +%Y%m%d-%H%M%S`.tar.gz

Where phone is the ip address of your phone (192.168.0.202).

Personally I added an entry to /etc/hosts so the above works for me. I also added the desktop key to /home/root/.ssh/authorized_keys on the phone as per the instructions in USB_Networking#SSH_Keys.

If you want to check what is in the backup, run the following, replacing the filename with what was just created.

tar -tzf moko-home-20080802-203108.tar.gz | less

reference

[edit] Backing up everything

You may either :

[edit] Backing-up flash images

NOTE: Upload support is currently broken - #676, #1843


You will need the Dfu-util to make a backup of your existing image.

As when flashing, you will need to be in U-Boot in the NOR Flash. Log into the NOR uBoot menu and select Set console to USB (for FreeRunner just stay in NOR uBoot menu, do not select or enter anything). Now you will be able to flash, make backups of your FreeRunner or query the FreeRunner with dfu-util. Backup is fairly slow; it took over ten minutes to back up a 247 MB rootfs.

It is important that you connect the USB cable directly from your computer to your phone. If there is a hub between them, backup (and flashing) will mostly likely fail.

NOTE: On a Windows host, omit the "./" or "sudo ./" that precedes the commands listed on this page


sudo ./dfu-util -a kernel -R -U good-kernel.bin
sudo ./dfu-util -a rootfs -R -U good-rootfs.jffs2
sudo ./dfu-util -a splash -R -U good-splash.bin
sudo ./dfu-util -a u-boot -R -U good-u-boot.bin
sudo ./dfu-util -a u-boot_env -R -U good-u-boot_env.bin

Here is what a successful dfu-util backup run looks like:

on the host PC:

$ sudo ./dfu-util -a kernel -R -U good-kernel.img
dfu-util - (C) 2007 by Openmoko Inc.
This program is Free Software and has ABSOLUTELY NO WARRANTY

Opening USB Device 0x0000:0x0000...
Claiming USB DFU Runtime Interface...
Determining device status: state = appIDLE, status = 0
Device really in Runtime Mode, send DFU detach request...
Resetting USB...
Opening USB Device...
Found Runtime: [0x1d50:0x5119] devnum=12, cfg=0, intf=0, alt=3, name="kernel"
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x1000
Resetting USB to switch back to runtime mode

on the FreeRunner:

DFU: Switching to DFU Mode
DEVICE_CONFIGURED: 1
Starting DFU Upload of partition 'kernel'
DEVICE_CONFIGURED: 1

A failed run of dfu-util looks like this:

dfu-util - (C) 2007 by Openmoko Inc.
This program is Free Software and has ABSOLUTELY NO WARRANTY

Opening USB Device 0x0000:0x0000...
Claiming USB DFU Runtime Interface...
Determining device status: state = appIDLE, status = 0
Device really in Runtime Mode, send DFU detach request...
Resetting USB...
Opening USB Device...
Found Runtime: [0x1d50:0x5119] devnum=20, cfg=0, intf=0, alt=6, name="rootfs"
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x1000
dfu_upload error -110

And shows demsg errors like this:

usb 5-2: usbfs: USBDEVFS_CONTROL failed cmd dfu-util rqt 161 rq 2 len 4096 ret -110

This error is detected within the Linux USB stack (drivers/usb/core/message.c) and looking at errno.h for the negatived error status number, the reason is e.g.

110 ETIMEDOUT Connection timed out
84 EILSEQ Illegal byte sequence
108 ESHUTDOWN Cannot send after transport endpoint shutdown
...

Insure yourself, that you connect the FR directly to the computer (without any USB hubs), if you experience timed out connections and use the

dfu-util -d 0x1d50:0x5119 ...

option, if the FR is not detected properly.

[edit] Backing-up flash images (alternative)

On the device:

mkdir /var/tmp/root
mount /dev/root /var/tmp/root

If you have om2008.9 you have to use:

mount -t jffs2 /dev/mtdblock6 /var/tmp/root

On your workstation:

ssh root@192.168.0.202 "mkfs.jffs2 -d /var/tmp/root -e 128 --pad --no-cleanmarkers -x lzo" | pv -W > rootfs.jffs2

(The "| pv -W" is optional, it just gives you something to watch as the bytes fly by.)

On the device:

umount /var/tmp/root

[edit] Backing-up in a tar archive

ssh root@192.168.0.202 "tar c /bin /etc /home /lib /opt /sbin /tmp /usr /var" | pv -s 2200000 -W > rootfs.tar

(The "| pv -W" is optional, it just gives you something to watch as the bytes fly by; the "-s" option presume you're transferring 2200000 bytes of data)

Extract it and use mkfs.jffs2 if you want convert it to a jffs2 image.

[edit] Backup Scripts

If you plan on backing up frequently, using a script will simplify the process:

[edit] Simple backup script

This script works well if you want to configure it to backup always the same device.

#!/bin/sh
#
# Back up all partitions of the phone to a backup directory,
# adding today's date to the saved filenames.

DATE=`date +%Y-%m-%d`
DFU=./dfu-util
BACKUP_DIR=bak/

${DFU} -a kernel -R -U ${BACKUP_DIR}kernel-${DATE}.bin
${DFU} -a rootfs -R -U ${BACKUP_DIR}rootfs-${DATE}.jffs2
${DFU} -a splash -R -U ${BACKUP_DIR}splash-${DATE}.bin
${DFU} -a u-boot -R -U ${BACKUP_DIR}u-boot-${DATE}.bin
${DFU} -a u-boot_env -R -U ${BACKUP_DIR}u-boot_env-${DATE}.bin

[edit] Interactive script

This script is based on the above "Simple backup script" (by unknown). It does the backup of what you want and choose promting you for choices. Enjoy it! test it! contribute! You can find us at /server irc.freenode.net /j #openmoko and we'll be pleased to accept you help (ideas || code).

NOTE that the script works for me(tm) but it still needs some love. especially on traps and catches for wrong choices.

#!/bin/bash

#############################################################################################################
##                                                                                                         ##
## This script is Free Software, it's licensed under the GPLv3 and has ABSOLUTELY NO WARRANTY              ##
## you can find and read the complete version of the GPLv3 @ http://www.gnu.org/licenses/gpl.html          ##
##                                                                                                         ##
## Q: what does this script do?                                                                            ##
## A: the script back up all partitions of the phone to a backup directory, interactively,                 ## 
##    adding today's date to the saved filenames.                                                          ##
##                                                                                                         ##
## IMPORTANT:!!! REMEMBER TO RUN THIS SCRIPT AS ROOT SINCE dfu-util HAS TO BE USED AS ROOT!!!              ##
##                                                                                                         ##
## based on the orginal simple backup script at http://wiki.openmoko.org/wiki/Backup                       ##
##                                                                                                         ##
## this version has been conceived and written by cga, x77686d, Infoport, jomat at /server irc.freenode.net##
## /j #openmoko,#bash and my collegue aubba @ work.                                                        ##
##                                                                                                         ##
## for any suggestions and contributions contact cga (or one of the above) in the #openmoko channel        ##
##                                                                                                         ##
#############################################################################################################

## let's roll!!

## sets the date format for the date in the backup file, change accordingly to your local custom if you need
DATE=`date +%d-%m-%Y`

## here the scripts try to find the dfu-util binary and set it as the DFU var:
if which dfu-util >/dev/null ; then
	echo
	echo "dfu-util found in your path"
	echo
	## 1 the function use this if you placed/linked dfu-util in your $PATH
	DFU=dfu-util

elif ls dfu-util >/dev/null ; then
	echo
	echo "dfu-util found in current directory" 
	echo
	## or 2 use following line if dfu-util is placed in the same directory where you run the script
	DFU=./dfu-util
	 
else
	## or 3 if the script doesn't find dfu-util shows the link for installing it and exit
	echo
	echo "dfu-util NOT found! install and use howto @ http://wiki.openmoko.org/wiki/Dfu-util"
	echo
	exit 1
fi

## here we get the hex code for devices found with dfu-util --list 
## the hex code is grabbed and the name of the device is shown accordingly and you are prompetd to chose the right one:
echo
echo 'these are the devices i found:' 
echo
for device in `${DFU} --list | grep 0x | cut -f3 -d' ' | tr -d '[]'` ; do
	if [ "$device" == '0x1457:0x5119' ] ; then
		echo 'Neo 1973'
	elif [ "$device" == '0x1d50:0x5119' ] ;	then
		echo "Neo FreeRunner"
	else
		echo 'other device found, DO NOT use dfu-util on this!!! it might bork it...'
		exit 1
	fi
done | nl
echo
echo 'choose the device to backup:' 
echo
read selection
HEX=$(${DFU} --list | grep 0x | head -n $selection | tail -1 | cut -f3 -d' ' | tr -d '[]') 

## use the built-in read command to ask you and use the directory for the backup
while [ -z "$BACKUP_DIR" ] ; do
	echo
	read -e -p $"enter the directory for the backup:" BACKUP_DIR
	echo

	## chek wether the dir exist and proceed, else create it and proceed.
	if [ ! -d "$BACKUP_DIR" ] ; then
		echo
		echo -n "$BACKUP_DIR does not exist, create it? [Y/n] "
		echo
		read CREATE_DIR
		if [ x"$CREATE_DIR" = xy -o x"$CREATE_DIR" = xY -o -z "$CREATE_DIR" ] ; then
			mkdir -p -v "${BACKUP_DIR}"
		else
			BACKUP_DIR=
		fi
	fi
done

## here you get prompted to chose the backup you want, you can backup single files or all of them.
echo
echo 'choose the component to backup from the list:'
echo

select howto in kernel splash u-boot u-boot_env rootfs all quit; do
	if [ "$howto" == "kernel" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a kernel -R -U ${BACKUP_DIR}/kernel-${DATE}.bin
	fi
	if [ "$howto" == "splash" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a splash -R -U ${BACKUP_DIR}/splash-${DATE}.bin
	fi
	if [ "$howto" == "u-boot" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a u-boot -R -U ${BACKUP_DIR}/u-boot-${DATE}.bin
	fi
	if [ "$howto" == "u-boot_env" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a u-boot_env -R -U ${BACKUP_DIR}/u-boot_env-${DATE}.bin
	fi
	if [ "$howto" == "rootfs" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a rootfs -R -U ${BACKUP_DIR}/rootfs-${DATE}.jffs2
	fi
	if [ "$howto" == "quit" ] ; then
		exit 0
	fi
	echo
	echo 'the component(s) has/have been backed up, what next? (press enter for menu)'
	echo
done

exit 0

[edit] Pretty GUI Script

NeoTool is a zenity-based script which allows you to both backup and Flash your device from a pretty GUI. It uses both the dfu-util method and the alternate method described on this page, and can produce flashable images of everything including rootfs. Check it out.

[edit] Backing up the incremental rsync hardlink way

Following is a very simple implementation of incremental rsync snapshots with hardlinks. Just put it to /etc/cron.daily/backup-neo on your PC and setup ssh keys between your PC and neo. It will then daily try to backup all files in the / partition. Each successful backup is hardlinked under a timestamped directory so you can access old backups easily. In fact, you can even NFS mount /backup/neo to phone and then chroot inside the backups to run programs in the backup'ed environment.

#!/bin/bash
# /etc/cron.daily/backup-neo
rsync --delete -ax --numeric-ids 192.168.0.202:/ /backup/neo/latest 2>  /dev/null
ret=$?

case $ret in
0)
        # backup done, let's save it
        cp -al /backup/neo/latest /backup/neo/`date -I`
        ;;
12)
        # neo was not at home
        ;;
*)
        echo "backup failed with return value $ret"
        ;;
esac

[edit] Backing up internal flash when booted on external SD-card

#Freerunner
mkdir internal_flash
mount /dev/mtdblock6 internal_flash -t jffs2

Now you can pack directory or copy selected files out from it.

(This mounting is usefull also if your internal operating system is non-bootable. You can get files out or even repair the system using operating system on external card.)

[edit] Weblinks

Personal tools

Backing up just /home/root

To backup the home folder (all your files personal files in theory).

From the desktop pc run:

ssh root@phone 'tar -cpz /home/root' > moko-home-`date +%Y%m%d-%H%M%S`.tar.gz

Where phone is the ip address of your phone (192.168.0.202).

Personally I added an entry to /etc/hosts so the above works for me. I also added the desktop key to /home/root/.ssh/authorized_keys on the phone as per the instructions in USB_Networking#SSH_Keys.

If you want to check what is in the backup, run the following, replacing the filename with what was just created.

tar -tzf moko-home-20080802-203108.tar.gz | less

reference

Backing up everything

You may either :

Backing-up flash images

You will need the Dfu-util to make a backup of your existing image.

As when flashing, you will need to be in U-Boot in the NOR Flash. Log into the NOR uBoot menu and select Set console to USB (for NRF just stay in NOR uBoot menu, do not select or enter anything). Now you will be able to flash, make backups of your FreeRunner or query the FreeRunner with dfu-util. Backup is fairly slow; it took over ten minutes to back up a 247 MB rootfs.

It is important that you connect the USB cable directly from your computer to your phone. If there is a hub between them, backup (and flashing) will mostly likely fail.

NOTE: On a Windows host, omit the "./" or "sudo ./" that precedes the commands listed on this page


sudo ./dfu-util -a kernel -R -U good-kernel.bin
sudo ./dfu-util -a rootfs -R -U good-rootfs.jffs2
sudo ./dfu-util -a splash -R -U good-splash.bin
sudo ./dfu-util -a u-boot -R -U good-u-boot.bin
sudo ./dfu-util -a u-boot_env -R -U good-u-boot_env.bin

Here is what a successful dfu-util backup run looks like:

on the host PC:

$ sudo ./dfu-util -a kernel -R -U good-kernel.img
dfu-util - (C) 2007 by Openmoko Inc.
This program is Free Software and has ABSOLUTELY NO WARRANTY

Opening USB Device 0x0000:0x0000...
Claiming USB DFU Runtime Interface...
Determining device status: state = appIDLE, status = 0
Device really in Runtime Mode, send DFU detach request...
Resetting USB...
Opening USB Device...
Found Runtime: [0x1d50:0x5119] devnum=12, cfg=0, intf=0, alt=3, name="kernel"
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x1000
Resetting USB to switch back to runtime mode

on the FreeRunner:

DFU: Switching to DFU Mode
DEVICE_CONFIGURED: 1
Starting DFU Upload of partition 'kernel'

A failed run of dfu-util looks like this:

dfu-util - (C) 2007 by Openmoko Inc.
This program is Free Software and has ABSOLUTELY NO WARRANTY

Opening USB Device 0x0000:0x0000...
Claiming USB DFU Runtime Interface... 
Determining device status: state = appIDLE, status = 0
Device really in Runtime Mode, send DFU detach request...
Resetting USB... 
Opening USB Device...
Found Runtime: [0x1d50:0x5119] devnum=20, cfg=0, intf=0, alt=6, name="rootfs"
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x1000
dfu_upload error -110

And shows errors demsg like this:

usb 5-2: usbfs: USBDEVFS_CONTROL failed cmd dfu-util rqt 161 rq 2 len 4096 ret -110

Backup Scripts

If you plan on backing up frequently, using a script will simplify the process:

Simple backup script

This script works well if you want to configure it to backup always the same device.

#!/bin/sh
#
# Back up all partitions of the phone to a backup directory,
# adding today's date to the saved filenames.

DATE=`date +%Y-%m-%d`
DFU=./dfu-util
BACKUP_DIR=bak/

${DFU} -a kernel -R -U ${BACKUP_DIR}kernel-${DATE}.bin
${DFU} -a rootfs -R -U ${BACKUP_DIR}rootfs-${DATE}.jffs2
${DFU} -a splash -R -U ${BACKUP_DIR}splash-${DATE}.bin
${DFU} -a u-boot -R -U ${BACKUP_DIR}u-boot-${DATE}.bin
${DFU} -a u-boot_env -R -U ${BACKUP_DIR}u-boot_env-${DATE}.bin

Interactive script

This script is based on the above "Simple backup script" (by unknown). It does the backup of what you want and choose promting you for choices. Enjoy it! test it! contribute! You can find us at /server irc.freenode.net /j #openmoko and we'll be pleased to accept you help (ideas || code).

NOTE that the script works for me(tm) but it still needs some love. especially on traps and catches for wrong choices.

#!/bin/bash

#############################################################################################################
##                                                                                                         ##
## This script is Free Software is licensed under the GPLv3 and has ABSOLUTELY NO WARRANTY                 ##
## you can find and read the complete version of the GPLv3 @ http://www.gnu.org/licenses/gpl.html          ##
##                                                                                                         ##
## Q: what does this script do?                                                                            ##
## A: the script back up all partitions of the phone to a backup directory, interactively,                 ## 
##    adding today's date to the saved filenames.                                                          ##
##                                                                                                         ##
## IMPORTANT:!!! REMEMBER TO RUN THIS SCRIPT AS ROOT SINCE dfu-util HAS TO BE USED AS ROOT!!!              ##
##                                                                                                         ##
## based on the orginal simple backup script at http://wiki.openmoko.org/wiki/Pre-Flash_Backup             ##
##                                                                                                         ##
## this version has been conceived and written by cga, x77686d, Infoport, jomat at /server irc.freenode.net##
## /j #openmoko,#bash and my collegue aubba @ work.                                                        ##
##                                                                                                         ##
## for any suggestions and contributions contact cga (or one of the above) in the #openmoko channel        ##
##                                                                                                         ##
#############################################################################################################

## let's roll!!

## sets the date format for the date in the backup file, change accordingly to your local custom if you need
DATE=`date +%d-%m-%Y`

## here the scripts try to find the dfu-util binary and set it as the DFU var:
if which dfu-util >/dev/null ; then
	echo
	echo "dfu-util found in your path"
	echo
	## 1 the function use this if you placed/linked dfu-util in your $PATH
	DFU=dfu-util

elif ls dfu-util >/dev/null ; then
	echo
	echo "dfu-util found in current directory" 
	echo
	## or 2 use following line if dfu-util is placed in the same directory where you run the script
	DFU=./dfu-util
	 
else
	## or 3 if the script doesn't find dfu-util shows the link for installing it and exit
	echo
	echo "dfu-util NOT found! install and use howto @ http://wiki.openmoko.org/wiki/Dfu-util"
	echo
	exit 1
fi

## here we get the hex code for devices found with dfu-util --list 
## the hex code is grabbed and the name of the device is shown accordingly and you are prompetd to chose the right one:
echo
echo 'these are the devices i found:' 
echo
for device in `${DFU} --list | grep 0x | cut -f3 -d' ' | tr -d '[]'` ; do
	if [ "$device" == '0x1457:0x5119' ] ; then
		echo 'Neo 1973'
	elif [ "$device" == '0x1d50:0x5119' ] ;	then
		echo "Neo FreeRunner"
	else
		echo 'other device found, DO NOT use dfu-util on this!!! it might bork it...'
		exit 1
	fi
done | nl
echo
echo 'choose the device to backup:' 
echo
read selection
HEX=$(${DFU} --list | grep 0x | head -n $selection | tail -1 | cut -f3 -d' ' | tr -d '[]') 

## use the built-in read command to ask you and use the directory for the backup
while [ -z "$BACKUP_DIR" ] ; do
	echo
	read -e -p $"enter the directory for the backup:" BACKUP_DIR
	echo

	## chek wether the dir exist and proceed, else create it and proceed.
	if [ ! -d "$BACKUP_DIR" ] ; then
		echo
		echo -n "$BACKUP_DIR does not exist, create it? [Y/n] "
		echo
		read CREATE_DIR
		if [ x"$CREATE_DIR" = xy -o x"$CREATE_DIR" = xY -o -z "$CREATE_DIR" ] ; then
			mkdir -p -v "${BACKUP_DIR}"
		else
			BACKUP_DIR=
		fi
	fi
done

## here you get prompted to chose the backup you want, you can backup single files or all of them.
echo
echo 'choose the component to backup from the list:'
echo

select howto in kernel splash u-boot u-boot_env rootfs all quit; do
	if [ "$howto" == "kernel" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a kernel -R -U ${BACKUP_DIR}/kernel-${DATE}.bin
	fi
	if [ "$howto" == "splash" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a splash -R -U ${BACKUP_DIR}/splash-${DATE}.bin
	fi
	if [ "$howto" == "u-boot" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a u-boot -R -U ${BACKUP_DIR}/u-boot-${DATE}.bin
	fi
	if [ "$howto" == "u-boot_env" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a u-boot_env -R -U ${BACKUP_DIR}/u-boot_env-${DATE}.bin
	fi
	if [ "$howto" == "rootfs" -o "$howto" == "all" ] ; then
		${DFU} -d ${HEX} -a rootfs -R -U ${BACKUP_DIR}/rootfs-${DATE}.jffs2
	fi
	if [ "$howto" == "quit" ] ; then
		exit 0
	fi
	echo
	echo 'the component(s) has/have been backed up, what next? (press enter for menu)'
	echo
done

exit 0