I've seen a lot of people ask if it's possible to find out what ROM a nandroid backup is of, or how to get apps out of a backup without restoring it (as is the case if you forget to backup with TB, first). In this thread, I explained how to do this from Windows. What I failed to mention is that this is natively supported in Linux. The method in that thread involves copying img files from a backup to a Windows computer, and using unyaffs with cygwin. Since Android is Linux, you can do this directly from your phone. Yes, it takes a bit longer (just a couple minutes) because you're reading/writing to the sdcard. It still takes much less time than it does to restore a backup, get what you need, then restore back to whatever you had before. So, to make this process easy, I've written a script that can be executed from the terminal directly on the phone. The process is completely automated. Here is how it works:
1) Flash unandroid-signed.zip from recovery. Reboot. (You only have to do this step once)
2) Open the terminal emulator.
3) Run this command:
unandroid
4) You will be given a list of existing Clockwork and/or Amon RA nandroid backups. For example:
5) Select the number of the backup you want to extract. For example, just type "1" without quotes to extract backup1.
6) The script will determine if the backup includes a system.img, a data.img, or both. You will be prompted to extract either one or both by pressing "s" for system.img, "d" for data.img, or "sd" for both (all without quotes).
7) That is all the user input it needs. Once that is done, the backup will be extracted to /sdcard/nandroid_tmp/nameofbackup/ with a directory named system.img for the system.img and/or a directory named data.img for the data.img.
8) Use any file browser you like to navigate to those directories. You will find all of the files you would normally find in /system or /data if you were to actually restore that backup.
Note that you only have the option for system.img and/or data.img. This method is not useful for any other image file in a nandroid backup. That being said, system.img and data.img are the only ones you'll need 99% of the time.
Note also that it will take approximately 2-3 minutes per image (data.img and/or system.img) depending on how big it is. It might look like the script is hanging, but it's not. Unless you get errors, just let it run. If you do cancel it, though, just remove the directory that gets created in /sdcard/nandroid_tmp and start over. Basically, this process is the same as restoring a nandroid the backup. The difference is that you're copying the files to a temporary location for ease of access rather than replacing your entire system (a waste of time for extracting a few files here and there).
Potential uses for this script:
1) If you forgot to rename a backup, and have no idea what it is, follow the above procedure for the system.img of that backup. Once it is done, use a file browser to navigate to the directory. In the top level of the system.img directory, you will find a file named build.prop. It is a text file with a list of properties for the ROM that was backed up. Open it, and find ro.build.description. That will tell you what ROM it is. You can also do this from the command line (terminal) by typing:
grep ro.build.description /sdcard/nandroid_tmp/nameofbackup/system.img/build.properties
2) If you forgot to backup an app and no longer have access to the apk (or you simply forgot what all you had installed), follow the above procedure for the data.img of the backup. Do the same as above, but navigate to the created data.img directory. In the app directory, you will find all the apps that were installed in that backup. You can copy the apks out of there and install them, or build a list, depending on what you wanted to do. Note that if you use a2sd, and moved apps to the sdcard, they will not be saved here. If you backed up the ext partition, it will be in a separate file named ext.tar. A tar file is different than the normal img files that are created in a backup. A tar file is basically a collection of files made into a "tarball" so that it can be easily stored, compressed, etc. in one file. If this is the case, and you want your apks, you don't need this script for that. You can untar the file by opening a terminal, and typing these commands:
cd /sdcard
mkdir ext_apps
cd ext_apps
tar xvf /sdcard/path/to/backup/ext.tar
Off that rabbit trail, there are still plenty of uses for extracting the data.img, such as:
3) if you need app data, you will find it in /data/data, normally, so if you follow the above procedure for the data.img, you will find it in data.img/data/. One such example could be if you forgot to backup your bookmarks. Most settings/history type things for the browser are stored in /data/data/com.android.browser/databases/browser.db, which is a sqlite file. It's a database, basically. So, if you extract your data.img from a nandroid backup, you *could* just copy this file out of there and replace your existing one with it. If you go that route, I would highly recommend you backup first. You could easily cause issues if you do this, especially if going between aosp and sense, and vice versa. That being said, it's easy to see what bookmarks you had set in the backed up ROM by typing this (rather lengthy) command from the command line:
sqlite3 /sdcard/nandroid_tmp/nameofbackup/data.img/data/com.android.browser/databases/browser.db "select * from bookmarks where bookmark = '1'"
That will return a list of bookmarks you had in the backed up ROM. This is just one such example. If you search for db files, you'll even find your SMS messages. This means if you forgot to backup your text messages, you don't need to restore a backup just get them. Go through this procedure, and you can get them.
NOTES:
I did my best to test this in a short amount of time. I tested it on CM7 and Mikfroyo 4.4, both of which had a2sd installed. All backups I tested were made with Amon RA. In theory, this should work with any ROM, whether a2sd is installed or not. All you need is the script itself, bash (normally installed with a2sd), and unyaffs, all of which are provided in the flashable zip in the event that you don't already have them. If you have CM7, you should already have unyaffs.
Also, this should work fine with both Clockwork and Amon RA nandroid backups. I don't use CW, so I only tested with RA. I know for a fact that the method used to make the backups is the same, but that doesn't change the fact that I didn't test it. If anyone using CW uses this and gets any errors, or simply isn't given a list of any backups, please let me know, along with the directory your backups are in, and I'll fix it.
One last thing - when I ran this, I got an I/O error, and a message that mkdir failed a couple of times. It only happened a few times, and always ran fine if I just reran the script. I'm tracking the issue down now, but just be warned.
If I forgot anything, I'll update this section. Otherwise, if you run into any errors or if this just doesn't work as advertised, please let me know, and provide the following details:
1) Error messages, if any
2) Current ROM
3) ROM of the backup (if you know)
4) Using bash or sh (if you don't know the answer to this, it's sh). This shouldn't matter, as the script will use bash, but still...
5) The recovery/version used to make the backup
LINK TO THE SCRIPT:
unandroid-signed.zip
Instructions for flashing:
1) Download the above file
2) Copy it to the root (top level) of your sdcard (or where ever you like to put your flashable zips)
3) Reboot into recovery
4) Select the option to flash a zip. You do not need to wipe cache/dalvik
5) Reboot once it's done flashing
UPDATE:
argedion has modified unandroid to support nandroid backups that include an ext backup in the form of a yaffs2 img. So, if you are using a recovery such as Amon Ra Style (which I'm told no longer packs the sd-ext image in a tar file, but in an ext.img file) you can now extract it with unandroid. Here is the new version:
unandroid2-signed
Follow the same steps to flash it. It will replace the existing version of unandroid if you have already flashed it.
1) Flash unandroid-signed.zip from recovery. Reboot. (You only have to do this step once)
2) Open the terminal emulator.
3) Run this command:
unandroid
4) You will be given a list of existing Clockwork and/or Amon RA nandroid backups. For example:
[1] backup1
[2] backup2
[3] backup3
5) Select the number of the backup you want to extract. For example, just type "1" without quotes to extract backup1.
6) The script will determine if the backup includes a system.img, a data.img, or both. You will be prompted to extract either one or both by pressing "s" for system.img, "d" for data.img, or "sd" for both (all without quotes).
7) That is all the user input it needs. Once that is done, the backup will be extracted to /sdcard/nandroid_tmp/nameofbackup/ with a directory named system.img for the system.img and/or a directory named data.img for the data.img.
8) Use any file browser you like to navigate to those directories. You will find all of the files you would normally find in /system or /data if you were to actually restore that backup.
Note that you only have the option for system.img and/or data.img. This method is not useful for any other image file in a nandroid backup. That being said, system.img and data.img are the only ones you'll need 99% of the time.
Note also that it will take approximately 2-3 minutes per image (data.img and/or system.img) depending on how big it is. It might look like the script is hanging, but it's not. Unless you get errors, just let it run. If you do cancel it, though, just remove the directory that gets created in /sdcard/nandroid_tmp and start over. Basically, this process is the same as restoring a nandroid the backup. The difference is that you're copying the files to a temporary location for ease of access rather than replacing your entire system (a waste of time for extracting a few files here and there).
Potential uses for this script:
1) If you forgot to rename a backup, and have no idea what it is, follow the above procedure for the system.img of that backup. Once it is done, use a file browser to navigate to the directory. In the top level of the system.img directory, you will find a file named build.prop. It is a text file with a list of properties for the ROM that was backed up. Open it, and find ro.build.description. That will tell you what ROM it is. You can also do this from the command line (terminal) by typing:
grep ro.build.description /sdcard/nandroid_tmp/nameofbackup/system.img/build.properties
2) If you forgot to backup an app and no longer have access to the apk (or you simply forgot what all you had installed), follow the above procedure for the data.img of the backup. Do the same as above, but navigate to the created data.img directory. In the app directory, you will find all the apps that were installed in that backup. You can copy the apks out of there and install them, or build a list, depending on what you wanted to do. Note that if you use a2sd, and moved apps to the sdcard, they will not be saved here. If you backed up the ext partition, it will be in a separate file named ext.tar. A tar file is different than the normal img files that are created in a backup. A tar file is basically a collection of files made into a "tarball" so that it can be easily stored, compressed, etc. in one file. If this is the case, and you want your apks, you don't need this script for that. You can untar the file by opening a terminal, and typing these commands:
cd /sdcard
mkdir ext_apps
cd ext_apps
tar xvf /sdcard/path/to/backup/ext.tar
Off that rabbit trail, there are still plenty of uses for extracting the data.img, such as:
3) if you need app data, you will find it in /data/data, normally, so if you follow the above procedure for the data.img, you will find it in data.img/data/. One such example could be if you forgot to backup your bookmarks. Most settings/history type things for the browser are stored in /data/data/com.android.browser/databases/browser.db, which is a sqlite file. It's a database, basically. So, if you extract your data.img from a nandroid backup, you *could* just copy this file out of there and replace your existing one with it. If you go that route, I would highly recommend you backup first. You could easily cause issues if you do this, especially if going between aosp and sense, and vice versa. That being said, it's easy to see what bookmarks you had set in the backed up ROM by typing this (rather lengthy) command from the command line:
sqlite3 /sdcard/nandroid_tmp/nameofbackup/data.img/data/com.android.browser/databases/browser.db "select * from bookmarks where bookmark = '1'"
That will return a list of bookmarks you had in the backed up ROM. This is just one such example. If you search for db files, you'll even find your SMS messages. This means if you forgot to backup your text messages, you don't need to restore a backup just get them. Go through this procedure, and you can get them.
NOTES:
I did my best to test this in a short amount of time. I tested it on CM7 and Mikfroyo 4.4, both of which had a2sd installed. All backups I tested were made with Amon RA. In theory, this should work with any ROM, whether a2sd is installed or not. All you need is the script itself, bash (normally installed with a2sd), and unyaffs, all of which are provided in the flashable zip in the event that you don't already have them. If you have CM7, you should already have unyaffs.
Also, this should work fine with both Clockwork and Amon RA nandroid backups. I don't use CW, so I only tested with RA. I know for a fact that the method used to make the backups is the same, but that doesn't change the fact that I didn't test it. If anyone using CW uses this and gets any errors, or simply isn't given a list of any backups, please let me know, along with the directory your backups are in, and I'll fix it.
One last thing - when I ran this, I got an I/O error, and a message that mkdir failed a couple of times. It only happened a few times, and always ran fine if I just reran the script. I'm tracking the issue down now, but just be warned.
If I forgot anything, I'll update this section. Otherwise, if you run into any errors or if this just doesn't work as advertised, please let me know, and provide the following details:
1) Error messages, if any
2) Current ROM
3) ROM of the backup (if you know)
4) Using bash or sh (if you don't know the answer to this, it's sh). This shouldn't matter, as the script will use bash, but still...
5) The recovery/version used to make the backup
LINK TO THE SCRIPT:
unandroid-signed.zip
Instructions for flashing:
1) Download the above file
2) Copy it to the root (top level) of your sdcard (or where ever you like to put your flashable zips)
3) Reboot into recovery
4) Select the option to flash a zip. You do not need to wipe cache/dalvik
5) Reboot once it's done flashing
UPDATE:
argedion has modified unandroid to support nandroid backups that include an ext backup in the form of a yaffs2 img. So, if you are using a recovery such as Amon Ra Style (which I'm told no longer packs the sd-ext image in a tar file, but in an ext.img file) you can now extract it with unandroid. Here is the new version:
unandroid2-signed
Follow the same steps to flash it. It will replace the existing version of unandroid if you have already flashed it.