Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Omari Stephens | 1f808c6 | 2009-08-03 20:23:55 -0700 | [diff] [blame] | 3 | # 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 Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 17 | # uncomment for debugging |
| 18 | #export DRY_RUN="echo" |
| 19 | source test_backup_common.sh |
Omari Stephens | 1f808c6 | 2009-08-03 20:23:55 -0700 | [diff] [blame] | 20 | |
Omari Stephens | 259447b | 2009-08-12 00:30:59 -0700 | [diff] [blame] | 21 | [ -z "$BUGREPORT_DIR" ] && BUGREPORT_DIR="$HOME/backup/bugreports" |
Omari Stephens | 1f808c6 | 2009-08-03 20:23:55 -0700 | [diff] [blame] | 22 | |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 23 | function check_file |
| 24 | { |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 25 | data=$(a shell cat /data/data/com.android.backuptest/$1) |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 26 | if [ "$data" = "$2" ] ; then |
| 27 | echo "$1 has correct value [$2]" |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 28 | return 0 |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 29 | else |
| 30 | echo $1 is INCORRECT |
| 31 | echo " value: [$data]" |
| 32 | echo " expected: [$2]" |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 33 | return 1 |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | function 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 Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 45 | fi |
| 46 | } |
| 47 | |
Omari Stephens | aa6e73a | 2009-12-02 17:39:27 -0800 | [diff] [blame] | 48 | # Make sure adb is root so we can poke at com.android.backuptest's data |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 49 | adb_root |
Omari Stephens | 1f808c6 | 2009-08-03 20:23:55 -0700 | [diff] [blame] | 50 | |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 51 | # delete the old data |
| 52 | echo --- Previous files |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 53 | a shell "ls -l /data/data/com.android.backuptest/files" |
| 54 | a shell "rm /data/data/com.android.backuptest/files/*" |
Joe Onorato | dc355a9 | 2009-06-26 14:45:25 -0400 | [diff] [blame] | 55 | echo --- Previous shared_prefs |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 56 | a shell "ls -l /data/data/com.android.backuptest/shared_prefs" |
| 57 | a shell "rm /data/data/com.android.backuptest/shared_prefs/*" |
Joe Onorato | dc355a9 | 2009-06-26 14:45:25 -0400 | [diff] [blame] | 58 | echo --- Erased files and shared_prefs |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 59 | a shell "ls -l /data/data/com.android.backuptest/files" |
| 60 | a shell "ls -l /data/data/com.android.backuptest/shared_prefs" |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 61 | echo --- |
| 62 | |
| 63 | echo |
| 64 | echo |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 65 | |
Omari Stephens | 1f808c6 | 2009-08-03 20:23:55 -0700 | [diff] [blame] | 66 | # 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 Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 69 | restore_set=$(a shell bmgr list sets | head -n1 | awk '{print $1}') |
Omari Stephens | 1f808c6 | 2009-08-03 20:23:55 -0700 | [diff] [blame] | 70 | |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 71 | # run the restore |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 72 | echo "Restoring from set [$restore_set]" |
| 73 | a shell bmgr restore "$restore_set" |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 74 | |
| 75 | echo |
| 76 | echo |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 77 | |
| 78 | # check the results |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 79 | export need_bug=0 |
| 80 | |
| 81 | # make sure files have the expected contents |
| 82 | check_file files/file.txt "first file" || need_bug=1 |
| 83 | check_file files/another_file.txt "asdf" || need_bug=1 |
| 84 | #check_file files/3.txt "3" || need_bug=1 |
| 85 | check_file files/empty.txt "" || need_bug=1 |
| 86 | check_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 |
| 89 | check_exists files/file_doesnt_exist.txt && need_bug=1 |
| 90 | check_exists files/no_files_here.txt && need_bug=1 |
| 91 | |
| 92 | if [ \( "$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" |
| 97 | fi |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 98 | |
| 99 | echo |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 100 | echo --- Restored files |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 101 | a shell "ls -l /data/data/com.android.backuptest/files" |
Joe Onorato | dc355a9 | 2009-06-26 14:45:25 -0400 | [diff] [blame] | 102 | echo --- Restored shared_prefs |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 103 | a shell "ls -l /data/data/com.android.backuptest/shared_prefs" |
Joe Onorato | 4a64bde | 2009-06-25 23:53:29 -0400 | [diff] [blame] | 104 | echo --- |
| 105 | echo |
Omari Stephens | 1f808c6 | 2009-08-03 20:23:55 -0700 | [diff] [blame] | 106 | |
Omari Stephens | 864ed1a | 2009-08-06 15:36:34 -0700 | [diff] [blame] | 107 | echo "Last 3 timestamps in 3.txt:" |
Omari Stephens | 0cfeb25 | 2009-08-11 21:44:21 -0700 | [diff] [blame] | 108 | a shell cat /data/data/com.android.backuptest/files/3.txt | tail -n 3 |
Omari Stephens | 864ed1a | 2009-08-06 15:36:34 -0700 | [diff] [blame] | 109 | |
Omari Stephens | 259447b | 2009-08-12 00:30:59 -0700 | [diff] [blame] | 110 | exit $need_bug |
| 111 | |