Android's system backup may be used in many situations, the following Python script, Can be used to back up the entire data partition: package files and directories of all data partitions into data.zip, and generate recovery's private edify script to update-script.sh. Of course, simply modify the backup path of the script can back up the system partition, if you add a few lines of code, you can back up the boot,recovery,uboot and so on, but this to different partitions to write different backup code:
backup.py
Import sysimport osfrom os.path import joinfrom os import pathimport zipfilefrom zipfile import zipfiledef packdir (dir,z,d Irinfo,emptydirs,linkinfo): dirs = Os.listdir (dir) if not Dirs:emptydirs.append (dir) else:for D i n Dirs:absdir = Join (dir,d) if not Path.islink (Absdir) and (Path.isdir (Absdir) or Path.isfile (ABSDI R): 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.app End (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) el Se: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 (inf o) info.append (key) info = tuple (info) set_perm = ' set_perm (%d,%d,%d, '%s '); \ n '%info f.write (set_perm) for Ke Y in linkinfo:info = Linkinfo[key] Info = tuple (info) symlink = ' symlink ('%s ', '%s '); \ n '% (Key,info[3]) Set_pe RM = ' 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 root permissions, and the script will run on python-for-android.
The script is then packaged into the APK or executed via the command line on the ADB shell.