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