test_restore.sh revision 1f808c6f6ed893bb50c94cf5be676712e4d68b9b
14a64bded06a0299785c295a975e2818308eb53e2Joe Onorato#!/bin/bash
24a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
31f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# Copyright (C) 2009 The Android Open Source Project
41f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#
51f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# Licensed under the Apache License, Version 2.0 (the "License");
61f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# you may not use this file except in compliance with the License.
71f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# You may obtain a copy of the License at
81f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#
91f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#      http://www.apache.org/licenses/LICENSE-2.0
101f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#
111f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# Unless required by applicable law or agreed to in writing, software
121f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# distributed under the License is distributed on an "AS IS" BASIS,
131f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# See the License for the specific language governing permissions and
151f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# limitations under the License.
161f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
171f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
181f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari StephensADB_OPTS="$@"
191f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
204a64bded06a0299785c295a975e2818308eb53e2Joe Onoratofunction check_file
214a64bded06a0299785c295a975e2818308eb53e2Joe Onorato{
221f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    data=$(adb $ADB_OPTS shell cat /data/data/com.android.backuptest/$1)
234a64bded06a0299785c295a975e2818308eb53e2Joe Onorato    if [ "$data" = "$2" ] ; then
244a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        echo "$1 has correct value [$2]"
254a64bded06a0299785c295a975e2818308eb53e2Joe Onorato    else
264a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        echo $1 is INCORRECT
274a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        echo "   value:    [$data]"
284a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        echo "   expected: [$2]"
294a64bded06a0299785c295a975e2818308eb53e2Joe Onorato    fi
304a64bded06a0299785c295a975e2818308eb53e2Joe Onorato}
314a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
321f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# run adb as root so we can poke at com.android.backuptest's data
331f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensroot_status=$(adb $ADB_OPTS root)
341f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensif [ "x$root_status" != "xadbd is already running as root" ]; then
351f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    echo -n "Restarting adb as root..."
361f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    sleep 2
371f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    adb $ADB_OPTS 'wait-for-device'
381f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    echo done.
391f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensfi
401f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
414a64bded06a0299785c295a975e2818308eb53e2Joe Onorato# delete the old data
424a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho --- Previous files
431f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files"
441f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "rm /data/data/com.android.backuptest/files/*"
45dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratoecho --- Previous shared_prefs
461f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs"
471f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "rm /data/data/com.android.backuptest/shared_prefs/*"
48dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratoecho --- Erased files and shared_prefs
491f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files"
501f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs"
514a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho ---
524a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
534a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
544a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
554a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
564a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
571f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# FIXME: there's probably a smarter way to do this
581f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# FIXME: if we can get the android ID, that's probably the safest thing to do
591f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# pick the most recent set and restore from it
601f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensrestore_set=$(adb $ADB_OPTS shell bmgr list sets | head -n1 | awk '{print $1}')
611f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
624a64bded06a0299785c295a975e2818308eb53e2Joe Onorato# run the restore
631f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensprintf "Restoring from set %d (hex: 0x%x)\n" $restore_set $restore_set
641f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell bmgr restore $restore_set
654a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
664a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
674a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
684a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
694a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
704a64bded06a0299785c295a975e2818308eb53e2Joe Onorato# check the results
71dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratocheck_file files/file.txt "first file"
72dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratocheck_file files/another_file.txt "asdf"
73dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratocheck_file files/3.txt "3"
74dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratocheck_file files/empty.txt ""
75dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratocheck_file shared_prefs/raw.xml '<map><int name="pref" value="1" /></map>'
764a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
774a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
784a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
794a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
804a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho --- Restored files
811f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files"
82dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onoratoecho --- Restored shared_prefs
831f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensadb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs"
844a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho ---
854a64bded06a0299785c295a975e2818308eb53e2Joe Onoratoecho
861f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
87