blob: 48e5c6667481c7d5be219250ca5b8c70ce971db1 [file] [log] [blame]
Joe Onorato4a64bde2009-06-25 23:53:29 -04001#!/bin/bash
2
Omari Stephens1f808c62009-08-03 20:23:55 -07003# Copyright (C) 2009 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Omari Stephens0cfeb252009-08-11 21:44:21 -070017# uncomment for debugging
18#export DRY_RUN="echo"
19source test_backup_common.sh
Omari Stephens1f808c62009-08-03 20:23:55 -070020
Omari Stephens259447b2009-08-12 00:30:59 -070021[ -z "$BUGREPORT_DIR" ] && BUGREPORT_DIR="$HOME/backup/bugreports"
Omari Stephens1f808c62009-08-03 20:23:55 -070022
Joe Onorato4a64bde2009-06-25 23:53:29 -040023function check_file
24{
Omari Stephens0cfeb252009-08-11 21:44:21 -070025 data=$(a shell cat /data/data/com.android.backuptest/$1)
Joe Onorato4a64bde2009-06-25 23:53:29 -040026 if [ "$data" = "$2" ] ; then
27 echo "$1 has correct value [$2]"
Omari Stephens0cfeb252009-08-11 21:44:21 -070028 return 0
Joe Onorato4a64bde2009-06-25 23:53:29 -040029 else
30 echo $1 is INCORRECT
31 echo " value: [$data]"
32 echo " expected: [$2]"
Omari Stephens0cfeb252009-08-11 21:44:21 -070033 return 1
34 fi
35}
36
37function check_exists
38{
39 # return 0 if file exists, 1 otherwise
40 data=$(a shell "ls $@ 2> /dev/null >/dev/null && echo -n exists")
41 if [ "$data" = "exists" ]; then
42 return 0
43 else
44 return 1
Joe Onorato4a64bde2009-06-25 23:53:29 -040045 fi
46}
47
Omari Stephensaa6e73a2009-12-02 17:39:27 -080048# Make sure adb is root so we can poke at com.android.backuptest's data
Omari Stephens0cfeb252009-08-11 21:44:21 -070049adb_root
Omari Stephens1f808c62009-08-03 20:23:55 -070050
Joe Onorato4a64bde2009-06-25 23:53:29 -040051# delete the old data
52echo --- Previous files
Omari Stephens0cfeb252009-08-11 21:44:21 -070053a shell "ls -l /data/data/com.android.backuptest/files"
54a shell "rm /data/data/com.android.backuptest/files/*"
Joe Onoratodc355a92009-06-26 14:45:25 -040055echo --- Previous shared_prefs
Omari Stephens0cfeb252009-08-11 21:44:21 -070056a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
57a shell "rm /data/data/com.android.backuptest/shared_prefs/*"
Joe Onoratodc355a92009-06-26 14:45:25 -040058echo --- Erased files and shared_prefs
Omari Stephens0cfeb252009-08-11 21:44:21 -070059a shell "ls -l /data/data/com.android.backuptest/files"
60a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
Joe Onorato4a64bde2009-06-25 23:53:29 -040061echo ---
62
63echo
64echo
Joe Onorato4a64bde2009-06-25 23:53:29 -040065
Omari Stephens1f808c62009-08-03 20:23:55 -070066# FIXME: there's probably a smarter way to do this
67# FIXME: if we can get the android ID, that's probably the safest thing to do
68# pick the most recent set and restore from it
Omari Stephens0cfeb252009-08-11 21:44:21 -070069restore_set=$(a shell bmgr list sets | head -n1 | awk '{print $1}')
Omari Stephens1f808c62009-08-03 20:23:55 -070070
Joe Onorato4a64bde2009-06-25 23:53:29 -040071# run the restore
Omari Stephens0cfeb252009-08-11 21:44:21 -070072echo "Restoring from set [$restore_set]"
73a shell bmgr restore "$restore_set"
Joe Onorato4a64bde2009-06-25 23:53:29 -040074
75echo
76echo
Joe Onorato4a64bde2009-06-25 23:53:29 -040077
78# check the results
Omari Stephens0cfeb252009-08-11 21:44:21 -070079export need_bug=0
80
81# make sure files have the expected contents
82check_file files/file.txt "first file" || need_bug=1
83check_file files/another_file.txt "asdf" || need_bug=1
84#check_file files/3.txt "3" || need_bug=1
85check_file files/empty.txt "" || need_bug=1
86check_file shared_prefs/raw.xml '<map><int name="pref" value="1" /></map>' || need_bug=1
87
88# make sure that missing files weren't somehow created
89check_exists files/file_doesnt_exist.txt && need_bug=1
90check_exists files/no_files_here.txt && need_bug=1
91
92if [ \( "$need_bug" -ne 0 \) -a -d "$BUGREPORT_DIR" ]; then
93 dev_id=$(a get-serialno)
94 filename="${dev_id}_`date +%s`"
95 echo "Grabbing bugreport; filename is $filename"
96 a bugreport > "$BUGREPORT_DIR/$filename.txt"
97fi
Joe Onorato4a64bde2009-06-25 23:53:29 -040098
99echo
Joe Onorato4a64bde2009-06-25 23:53:29 -0400100echo --- Restored files
Omari Stephens0cfeb252009-08-11 21:44:21 -0700101a shell "ls -l /data/data/com.android.backuptest/files"
Joe Onoratodc355a92009-06-26 14:45:25 -0400102echo --- Restored shared_prefs
Omari Stephens0cfeb252009-08-11 21:44:21 -0700103a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
Joe Onorato4a64bde2009-06-25 23:53:29 -0400104echo ---
105echo
Omari Stephens1f808c62009-08-03 20:23:55 -0700106
Omari Stephens864ed1a2009-08-06 15:36:34 -0700107echo "Last 3 timestamps in 3.txt:"
Omari Stephens0cfeb252009-08-11 21:44:21 -0700108a shell cat /data/data/com.android.backuptest/files/3.txt | tail -n 3
Omari Stephens864ed1a2009-08-06 15:36:34 -0700109
Omari Stephens259447b2009-08-12 00:30:59 -0700110exit $need_bug
111