| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 1 | page.title=bmgr |
| 2 | @jd:body |
| 3 | |
| 4 | <!-- quickview box content here --> |
| 5 | |
| 6 | <div id="qv-wrapper"> |
| 7 | <div id="qv"> |
| 8 | <h2>bmgr quickview</h2> |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 9 | <p><code>bmgr</code> lets you control the backup/restore system on an Android device. |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 10 | |
| 11 | <h2>In this document</h2> |
| 12 | <ol> |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 13 | <li><a href="#backup">Forcing a Backup Operation</a></li> |
| 14 | <li><a href="#restore">Forcing a Restore Operation</a></li> |
| 15 | <li><a href="#other">Other Commands</a></li> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 16 | </ol> |
| 17 | |
| Scott Main | 337b087 | 2010-06-25 15:55:57 -0700 | [diff] [blame] | 18 | <h2>See also</h2> |
| 19 | <ol> |
| 20 | <li><a href="{@docRoot}guide/topics/data/backup.html">Data Backup</a></li> |
| 21 | </ol> |
| 22 | |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 23 | </div> |
| 24 | </div> |
| 25 | |
| 26 | <!-- normal page content here --> |
| 27 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 28 | <p><code>bmgr</code> is a shell tool you can use to interact with the Backup Manager |
| 29 | on Android devices supporting API Level 8 or greater. It provides commands to induce backup |
| 30 | and restore operations so that you don't need to repeatedly wipe data or take similar |
| 31 | intrusive steps in order to test your application's backup agent. These commands are |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 32 | accessed via the <a href="{@docRoot}guide/developing/tools/adb.html">adb</a> shell. |
| 33 | |
| Scott Main | 337b087 | 2010-06-25 15:55:57 -0700 | [diff] [blame] | 34 | <p>For information about adding support for backup in your application, read <a |
| 35 | href="{@docRoot}guide/topics/data/backup.html">Data Backup</a>, which includes a guide to testing |
| 36 | your application using {@code bmgr}.</p> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 37 | |
| 38 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 39 | <h2 id="backup">Forcing a Backup Operation</h2> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 40 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 41 | <p>Normally, your application must notify the Backup Manager when its data has changed, via {@link |
| 42 | android.app.backup.BackupManager#dataChanged()}. The Backup Manager will then invoke your |
| 43 | backup agent's {@link |
| 44 | android.app.backup.BackupAgent#onBackup(ParcelFileDescriptor,BackupDataOutput,ParcelFileDescriptor) |
| 45 | onBackup()} implementation at some time in the future. However, instead of calling {@link |
| 46 | android.app.backup.BackupManager#dataChanged()}, you can invoke a backup request from the command |
| 47 | line by running the <code>bmgr backup</code> command: |
| 48 | |
| 49 | <pre class="no-pretty-print">adb shell bmgr backup <em><package></em></pre> |
| 50 | |
| 51 | <p><code><em><package></em></code> is the formal package name of the application you wish to |
| 52 | schedule for |
| 53 | backup. When you execute this backup command, your application's backup agent will be invoked to |
| 54 | perform a backup operation at some time in the future (via your {@link |
| 55 | android.app.backup.BackupAgent#onBackup(ParcelFileDescriptor,BackupDataOutput,ParcelFileDescriptor) |
| 56 | onBackup()} method), though there is no guarantee when it will occur. However, you can force all |
| 57 | pending backup operations to run immediately by using the <code>bmgr run</code> command: |
| 58 | |
| 59 | <pre class="no-pretty-print">adb shell bmgr run</pre> |
| 60 | |
| 61 | <p>This causes a backup pass to execute immediately, invoking the backup agents of all applications |
| 62 | that had previously called {@link android.app.backup.BackupManager#dataChanged()} since the |
| 63 | last backup operation, plus any applications which had been manually scheduled for |
| 64 | backup via <code>bmgr backup</code>. |
| 65 | |
| 66 | |
| 67 | |
| 68 | <h2 id="restore">Forcing a Restore Operation</h2> |
| 69 | |
| 70 | <p>Unlike backup operations, which are batched together and run on an occasional basis, restore |
| 71 | operations execute immediately. The Backup Manager currently provides two kinds of restore |
| 72 | operations. The first kind restores an entire device with the data that has been backed up. This |
| 73 | is typically performed only when a device is first provisioned (to replicate settings and other |
| 74 | saved state from the user's previous device) and is an operation that only the system can |
| 75 | perform. The second kind of restore operation restores |
| 76 | a single application to its "active" data set; that is, the application will abandon its current |
| 77 | data and revert to the last-known-good data that is held in the current backup image. You can |
| 78 | invoke this second restore operation with the {@link |
| 79 | android.app.backup.BackupManager#requestRestore(RestoreObserver) requestRestore()} method. The |
| 80 | Backup Manager will then invoke your backup agent's {@link |
| 81 | android.app.backup.BackupAgent#onRestore(BackupDataInput,int,ParcelFileDescriptor) |
| 82 | onRestore()} implementation. |
| 83 | |
| 84 | <p>While testing your application, you can immediately invoke the restore operation (bypassing the |
| 85 | {@link android.app.backup.BackupManager#requestRestore(RestoreObserver) requestRestore()} method) |
| 86 | for your application by using the <code>bmgr restore</code> command: |
| 87 | |
| 88 | <pre class="no-pretty-print">adb shell bmgr restore <em><package></em></pre> |
| 89 | |
| 90 | <p><code><em><package></em></code> is the formal Java-style package name of the application |
| 91 | participating in the backup/restore mechanism, which you would like to restore. The Backup |
| 92 | Manager will immediately instantiate the application's backup agent and invoke it for restore. This |
| 93 | will happen even if your application is not currently running. |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | <h2 id="other">Other Commands</h2> |
| 100 | |
| Scott Main | 337b087 | 2010-06-25 15:55:57 -0700 | [diff] [blame] | 101 | <h3>Wiping data</h3> |
| 102 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 103 | <p>The data for a single application can be erased from the active data set on demand. This is |
| 104 | very useful while you're developing a backup agent, in case bugs lead you to write corrupt data |
| 105 | or saved state information. You can wipe an application's data with the <code>bmgr wipe</code> |
| 106 | command: |
| 107 | |
| 108 | <pre class="no-pretty-print">adb shell bmgr wipe <em><package></em></pre> |
| 109 | |
| 110 | <p><code><em><package></em></code> is the formal package name of the application whose data |
| 111 | you wish to |
| 112 | erase. The next backup operation that the application's agent processes will look as |
| 113 | though the application had never backed anything up before. |
| 114 | |
| Scott Main | 337b087 | 2010-06-25 15:55:57 -0700 | [diff] [blame] | 115 | |
| 116 | <h3>Enabling and disabling backup</h3> |
| 117 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 118 | <p>You can see whether the Backup Manager is operational at all with the <code>bmgr |
| 119 | enabled</code> command: |
| 120 | |
| 121 | <pre class="no-pretty-print">adb shell bmgr enabled</pre> |
| 122 | |
| 123 | <p>This might be useful if your application's backup agent is never being invoked for backup, to |
| 124 | verify whether the operating system thinks it should be performing such operations at all.</p> |
| 125 | |
| 126 | <p>You can also directly disable or enable the Backup Manager with this command: |
| 127 | |
| 128 | <pre class="no-pretty-print">adb shell bmgr enable <em><boolean></em></pre> |
| 129 | |
| 130 | <p><code><em><boolean></em></code> is either <code>true</code> or <code>false</code>. |
| 131 | This is equivalent to disabling or enabling backup in the device's main Settings UI.</p> |
| 132 | |
| 133 | <p class="warning"><strong>Warning!</strong> When backup is disabled, the current backup transport |
| 134 | will explicitly wipe |
| 135 | the entire active data set from its backend storage. This is so that when a user says |
| 136 | they do <em>not</em> want their data backed up, the Backup Manager respects that wish. No further |
| 137 | data will be saved from the device, and no restore operations will be possible, unless the Backup |
| 138 | Manager is re-enabled (either through Settings or through the above <code>bmgr</code> command). |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | <!-- The following is not useful to applications, but may be some useful information some day... |
| 144 | |
| 145 | |
| 146 | <h2 id="transports">Applying a Backup Transport</h2> |
| 147 | |
| 148 | <p>A "backup transport" is the code module responsible for moving backup and restore data |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 149 | to and from some storage location. A device can have multipe transports installed, though only |
| 150 | one is active at any given time. Transports are identified by name. You can see what |
| 151 | transports are available on your device or emulator by running the |
| 152 | <code>bmgr list transports</code> command: |
| 153 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 154 | <pre class="no-pretty-print">adb shell bmgr list transports</pre> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 155 | |
| 156 | <p>The output of this command is a list of the transports available on the device. The currently |
| 157 | active transport is flagged with a <code>*</code> character. Transport names may look like |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 158 | component names (for example, <code>android/com.android.internal.backup.LocalTransport</code>), |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 159 | but they need not be, and the strings are never used as direct class references. The use of |
| 160 | a component-like naming scheme is simply for purposes of preventing name collisions. |
| 161 | |
| 162 | <p>You can change which transport is currently active from the command line as well: |
| 163 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 164 | <pre class="no-pretty-print">adb shell bmgr transport <em><name></em></pre> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 165 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 166 | <p><code><em><name></em></code> is one of the names as printed by the <code>bmgr list |
| 167 | transports</code> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 168 | command. From this point forward, backup and restore operations will be directed through the |
| 169 | newly-selected transport. Backup state tracking is managed separately for each transport, so |
| 170 | switching back and forth between them will not corrupt the saved state. |
| 171 | |
| 172 | |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 173 | |
| 174 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 175 | <h2 id="restoresets">Viewing Restore Sets</h2> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 176 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 177 | <p>All of the application data that a device has written to its backup transport is tracked |
| 178 | as a group that is collectively called a "restore set," because each data set is |
| 179 | most often manipulated during a restore operation. When a device is provisioned for the first |
| 180 | time, a new restore set is established. You can get a listing of all the restore sets available to |
| 181 | the current transport by running the <code>bmgr list sets</code> command: |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 182 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 183 | <pre class="no-pretty-print">adb shell bmgr list sets</pre> |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 184 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 185 | <p>The output is a listing of available restore sets, one per line. The first item on each line is |
| 186 | a token (a hexadecimal value that identifies the restore set to the transport). Following |
| 187 | the token is a string that briefly identifies the restore set. |
| 188 | Only the token is used within the backup and restore mechanism. |
| Christopher Tate | f781e86 | 2010-04-21 14:32:53 -0700 | [diff] [blame] | 189 | |
| 190 | |
| Scott Main | ff8c7ad | 2010-04-28 11:20:20 -0700 | [diff] [blame] | 191 | --> |