Backup

From Openmoko

Revision as of 16:47, 15 September 2008 by Nick (Talk | contribs)

Jump to: navigation, search

Contents

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

Backing up everything

You may either :

Backing-up flash images

NOTE: Upload support is currently broken - #676


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

Backing-up flash images (alternative)

On the device:

mkdir /var/tmp/root
mount /dev/root /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

Backing-up in a tar archive

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

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

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

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

Personal tools

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

Backing up everything

You may either :

Backing-up flash images

NOTE: Upload support is currently broken - #676


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

Backing-up flash images (alternative)

On the device:

mkdir /var/tmp/root
mount /dev/root /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

Backing-up in a tar archive

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

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

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

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