How to completely back up the system partitions and data partitions on the android system, androiddata

Source: Internet
Author: User
Tags symlink

How to completely back up the system partitions and data partitions on the android system, androiddata

Android system backup may be used in many cases, the following python script, can be used to back up the entire data Partition: All the datapartition files and directories into data.zip, and generate a recovery edify script to update-script.sh. Of course, you can simply modify the backup path of the script to back up the system partition. if you add a few lines of code, you can back up partitions such as boot, recovery, and uboot, however, different backup codes should be written based on different partitions:

Backup. py

import sysimport osfrom os.path import joinfrom os import pathimport zipfilefrom zipfile import ZipFiledef packdir(dir,z,dirinfo,emptydirs,linkinfo):    dirs = os.listdir(dir)    if not dirs:        emptydirs.append(dir)    else:        for d in dirs:            absdir = join(dir,d)            if not path.islink(absdir) and (path.isdir(absdir) or path.isfile(absdir)):                break        else:            emptydirs.append(dir)    for d in dirs:        absdir = join(dir,d)        st = os.lstat(absdir)        info = [st.st_uid,st.st_gid,st.st_mode]        if path.islink(absdir):            info.append(absdir)            linkdir = os.readlink(absdir)            linkinfo[linkdir] = info        elif path.isdir(absdir):            dirinfo[absdir] = info            packdir(absdir,z,dirinfo,emptydirs,linkinfo)        elif path.isfile(absdir):            dirinfo[absdir] = info            os.utime(absdir,(1403408099,1403408099))            z.write(absdir)        else:             print 'file type unknow %s'%(absdir,)            zi = ZipFile('data.zip','w',zipfile.ZIP_DEFLATED)dirinfo = {}emptydirs = []linkinfo = {}packdir('/data',zi,dirinfo,emptydirs,linkinfo)f = open('update-script.sh','wb');f.write('ifelse(is_mounted("/data"),unmount("/data"),0);\n')f.write('format("ext4", "EMMC", "/dev/block/data", "0", "/data");\n')f.write('mount("ext4", "EMMC", "/dev/block/data", "/data");\n')f.write('package_extract_dir("data", "/data");\n')mkdir_cmd = 'run_program("/sbin/busybox","mkdir","-p","'mkdir_cmd += '","'.join(emptydirs)mkdir_cmd += '");\n'f.write(mkdir_cmd)for key in dirinfo.keys():    info = dirinfo[key]    info = list(info)    info.append(key)    info = tuple(info)    set_perm = 'set_perm(%d, %d, %d, "%s");\n'%info    f.write(set_perm)for key in linkinfo:    info = linkinfo[key]    info = tuple(info)    symlink = 'symlink("%s", "%s");\n'%(key,info[3])    set_perm = 'run_program("/sbin/busybox","chown","-h","install:install","%s");\n'%(info[3],)    f.write(symlink)    f.write(set_perm)f.write('unmount("/data");')f.close()update_script='update-script.sh' os.utime(update_script,(1403408099,1403408099))zi.write(update_script)zi.close()

How to run:

First, you must have the root permission. In addition, the script runs on python-for-android.

Then Package the script into the apk, or run it on the adb shell using the command line.


What does Android data, system, and sd partition mean?

Hi, let me add it.
Data: data
It is also called user data. Data partitions contain user data: contacts, information, settings, and applications.
System: system
This partition mainly contains the entire operating system, including the user interface, as well as all system applications, pre-installed devices.
Sd: sdcard
This is the memory card we purchased and installed.
SD card partition refers to dividing part of the SD card memory into the phone memory to solve the problem of insufficient memory on the phone body!
You can use the built-in partition function or some other partition software in the recovery mode for SD card partitioning! Use the mobile phone software to contact the partition. Link2SD is available for Android!


What is the use of the data partition system partition sdcard partition of the mobile phone?

Data Partition, system partition, these two are rom, sdcard is the memory card. I don't know what phone you are using. I can only answer this question.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.