This commit is contained in:
Yawasau
2025-07-07 15:39:57 +08:00
parent bf58f2f7b2
commit bd9b779a5f
3 changed files with 53 additions and 31 deletions

View File

@@ -33,13 +33,36 @@
#### !!!以下操作皆須ROOT!!! ####
1. 首先將下載到的`數據備份脚本.zip`解壓到任意目錄後,可以看到以下幾個文件與一個 目錄:`生成應用列表.sh` `backup_settings.conf` `備份應用.sh` `tools` `備份自定義資料夾.sh` `終止腳本.sh` `警告! 不論備份或是恢復都必須保證tools的存在與完整性 否則腳本失效或是二進制調用失敗`
1. 首先將下載到的腳本解壓到任意目錄後,可以看到以下目錄結構 警告! 不論備份或是恢復都必須保證tools的存在與完整性 否則腳本失效或是二進制調用失敗。
2. 然後執行`生成應用列表.sh`腳本,並等待腳本輸出結束,再等待提示結束,此時會在當前目錄生成一個`appList.txt`,這就是你當前安裝的所有第三方應用。
`這是腳本結構與說明`
```
backup_script.zip
├── tools
│ ├── Device_List
│ ├── bc
│ ├── busybox
│ ├── classes.dex
│ ├── cmd
│ ├── jq
│ ├── find
│ ├── keycheck
│ ├── soc.json
│ ├── tar
│ ├── tools.sh
│ ├── update-binary
│ ├── zip
│ └── zstd
├── backup_settings.conf <--- 腳本默認行為設置 customize.sh 由 update-binary 执行(sourced)
└── start.sh <--- 執行腳本
```
2. 然後執行`start.sh`腳本音量鍵選擇生成應用列表,等待腳本輸出提示結束,此時會在當前目錄生成一個`appList.txt`,這就是你當前安裝的所有第三方應用(腳本會屏蔽預裝應用可於backup_settings.conf設置需要備份包名)。
3. 現在打開生成的`appList.txt`,根據裏面的提示操作後保存,這樣你就設置好了需要備份的軟件。
4. 最後找到`backup_settings.conf`打開後根據提示設置保存,再打開`備份應用.sh`等候備份結束完成後會在當前目錄生成一個以`Backup_壓縮算法名`命名的資料夾,裡面就是你的軟件備份。把這個資料夾整個保持到其他位置,刷完機后複製回手機,直接在資料夾裡找到`恢復備份.sh`即可恢復備份的所有數據,同樣道理,裡面也有個`appList.txt`使用方法跟第3步驟一樣不需要還原的刪除即可另外進去備份好的資料夾找到單獨應用資料夾有個 Backup腳本 and restore腳本可以單獨備份與恢復腳本。
4. 最後找到`backup_settings.conf`打開後根據提示設置保存,再打開`start.sh`音量鍵選擇備份應用,備份結束完成後會在當前目錄生成一個以`Backup_壓縮算法名`命名的資料夾,裡面就是你的軟件備份。把這個資料夾整個保持到其他位置,刷完機后複製回手機,直接執行`Backup_壓縮算法名/start.sh`即可恢復備份的所有數據,同樣道理,裡面也有個`appList.txt`使用方法跟第3步驟一樣不需要還原的刪除即可另外進去備份好的資料夾找到單獨應用資料夾有個 backup.sh and recover.sh可以單獨備份與恢復腳本。
5. 腳本執行過程中請留意紅色字眼提示有無任何錯誤並且使用恢復腳本時留意恢復結束後是否提示應用存在ssaid假設提示存在ssaid請在恢復後立刻重啟已便套用ssaid,假設恢復ssaid後立刻打開應用會導致ssaid套用失敗因為Android會產生一個新的saaid如此會導致應用卡白屏或是提示需要登錄ssaid是判斷應用是否換過環境與設備的判斷之一保持一致可以減少諸如提示異地登錄或是需要重新登入驗證的方法。
@@ -48,11 +71,11 @@
1. 找到恢復資料夾內的appList.txt打開 編輯列表 保存退出
2. 找到恢復備份.sh 給予root後等待腳本結束即可
2. 找到start.sh 給予root音量鍵選擇恢復備份後等待腳本結束即可
3. 重新生成應用列表.sh可用於刷新appList.txt內的列表 使用時機為當你刪除列表內的任何應用備份時,抑或者是恢復備份.sh提示列表錯誤時
3. start.sh的重新生成應用列表功能可用於刷新appList.txt內的列表 使用時機為當你刪除列表內的任何應用備份時,抑或者是恢復備份提示列表錯誤時
4. 終止腳本.sh用於突然想要終止腳本或是意外操作時使用 同理備份資料夾也有一個,因為腳本無須後台特性不能使用常規手段終結,故此另外寫了一個腳本終止
4. start.sh的終止腳本功能用於突然想要終止腳本或是意外操作時使用 同理備份也有一個,因為腳本無須後台特性不能使用常規手段終結,故此另外寫了一個終止
# 關於如何更新腳本?
@@ -65,7 +88,7 @@
## 關於反饋
- 如果使用過程中出現問題,請攜帶截圖並詳細說明問題,建立 [issues](https://github.com/YAWAsau/backup_script/issues)。
- 酷安 @[落葉淒涼TEL](http://www.coolapk.com/u/2277637)
- QQ組 976613477
- QQ組 976613477 很少上 盡量來TG
- TG https://t.me/yawasau_script
## 答疑

Binary file not shown.

View File

@@ -9,7 +9,7 @@ MODDIR="$MODDIR"
MODDIR_NAME="${MODDIR##*/}"
tools_path="$MODDIR/tools"
script="${0##*/}"
backup_version="202504261629"
backup_version="202507061817"
[[ $SHELL = *mt* ]] && echo "請勿使用MT管理器拓展包環境執行,請更換系統環境" && exit 2
update_backup_settings_conf() {
echo "#0關閉音量鍵選擇 (如選項未設置,則強制使用音量鍵選擇)
@@ -258,7 +258,7 @@ arm64*)
;;
esac
get_mv="$(which mv)"
PATH="/data/adb/ksu/bin:/sbin/.magisk/busybox:/sbin/.magisk:/sbin:/data/adb/ksu/bin:/system_ext/bin:/system/bin:/system/xbin:/vendor/bin:/vendor/xbin:/data/data/com.omarea.vtools/files/toolkit:/data/user/0/com.termux/files/usr/bin"
PATH="/system/bin:/system/xbin:/data/adb/ksu/bin:/sbin/.magisk/busybox:/sbin/.magisk:/sbin:/system_ext/bin:/vendor/bin:/vendor/xbin:/data/data/com.omarea.vtools/files/toolkit:/data/user/0/com.termux/files/usr/bin"
if [[ -d $(magisk --path 2>/dev/null) ]]; then
PATH="$(magisk --path 2>/dev/null)/.magisk/busybox:$PATH"
else
@@ -336,7 +336,7 @@ while read -r file expected_hash; do
done <<< "$(cat <<EOF
zstd ab32aecb389c3ba5c1f7ab05d5eb6a861bad80261fd14ef9a8f4c283ac48c22c
tar 3c605b1e9eb8283555225dcad4a3bf1777ae39c5f19a2c8b8943140fd7555814
classes.dex 3d9372ac4a922808974bed039ca152d5741215976bedb20653e6e65e4bdcb37f
classes.dex 99ed4bb2ea2ea4a57aa015d65811a81b44b60bf5b890879238d7308beab1d4b3
bc b15d730591f6fb52af59284b87d939c5bea204f944405a3518224d8df788dc15
busybox 4d60ab3f5a59ebb2ca863f2f514e6924401b581e9b64f602665c008177626651
find 7fa812e58aafa29679cf8b50fc617ecf9fec2cfb2e06ea491e0a2d6bf79b903b
@@ -656,7 +656,10 @@ Rename_script () {
touch_shell "3" "$REPLY"
fi
else
[[ -d ${REPLY%/*}/tools ]] && touch_shell "0" "$REPLY"
[[ -d ${REPLY%/*}/tools ]] && {
[[ -f ${REPLY%/*}/backup_settings.conf ]] && touch_shell "0" "$REPLY"
[[ -f ${REPLY%/*}/restore_settings.conf ]] && touch_shell "2" "$REPLY"
}
let HT++
fi
done
@@ -1058,7 +1061,7 @@ Backup_apk() {
[[ $(sed -e '/^$/d' "$txt2" 2>/dev/null | awk '{print $2}' | grep -w "^${name2}$" | head -1) = "" ]] && echo "${Backup_folder##*/} $name2" >>"$txt2"
[[ $apk_version != "" ]] && {
echoRgb "覆蓋app_details"
jq --arg apk_version "$apk_version2" --arg software "$name1" '.[$software].apk_version = $apk_version' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --arg apk_version "$apk_version2" --arg software "$name1" '.[$software].apk_version = $apk_version' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
} || {
echoRgb "新增app_details"
extra_content="{
@@ -1067,7 +1070,7 @@ Backup_apk() {
\"apk_version\": \"$apk_version2\"
}
}"
jq --argjson new_content "$extra_content" '. += $new_content' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --argjson new_content "$extra_content" '. += $new_content' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
}
else
rm -rf "$Backup_folder"
@@ -1102,7 +1105,7 @@ Backup_ssaid() {
echoRgb "$Ssaid>$ssaid"
SSAID_apk="$(echo "$name1 \"$name2\"")"
SSAID_apk2="$(echo "$SSAID_apk\n$SSAID_apk2")"
jq --arg entry "$name1" --arg new_value "$ssaid" '.[$entry].Ssaid |= $new_value' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --arg entry "$name1" --arg new_value "$ssaid" '.[$entry].Ssaid |= $new_value' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
echo_log "備份ssaid"
fi
[[ $ssaid = null ]] && ssaid=
@@ -1112,15 +1115,15 @@ Backup_Permissions() {
Get_Permissions="$(get_Permissions "$name2" | jq -nR '[inputs | select(length>0) | split(" ") | {(.[0]): (.[1:] | join(" "))}] | add')"
if [[ $Get_Permissions != "" && ($Get_Permissions = *true* || $Get_Permissions = *false*) ]]; then
if [[ $get_Permissions = "" ]]; then
jq --arg packageName "$name1" --argjson permissions "$Get_Permissions" '.[$packageName].permissions |= $permissions' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --arg packageName "$name1" --argjson permissions "$Get_Permissions" '.[$packageName].permissions |= $permissions' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
echo_log "備份權限"
else
if [[ $get_Permissions != "" && ($get_Permissions == *true* || $get_Permissions == *false*) ]]; then
[[ $get_Permissions != $Get_Permissions ]] && jq --arg packageName "$name1" --argjson permissions "$Get_Permissions" '.[$packageName] |= . + {permissions: $permissions}' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json && echo_log "備份權限" "備份"
[[ $get_Permissions != $Get_Permissions ]] && jq --arg packageName "$name1" --argjson permissions "$Get_Permissions" '.[$packageName] |= . + {permissions: $permissions}' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json" && echo_log "備份權限" "備份"
fi
fi
else
echoRgb "備份權限失敗$(get_Permissions "$name2")" "0"
[[ $Get_Permissions != "" ]] && echoRgb "備份權限失敗$(get_Permissions "$name2")" "0"
fi
}
#檢測數據位置進行備份
@@ -1152,9 +1155,9 @@ Backup_data() {
user)
if [[ $(su "$(get_uid "$name2" 2>/dev/null)" -c keystore_cli_v2 list | wc -l) -ge 2 ]]; then
echoRgb "$name1包含keystore 恢復可能閃退" "0"
jq --arg entry "$name1" '.[$entry].keystore |= "true"' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --arg entry "$name1" '.[$entry].keystore |= "true"' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
else
jq --arg entry "$name1" '.[$entry].keystore |= "false"' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --arg entry "$name1" '.[$entry].keystore |= "false"' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
fi
Backup_ssaid
Backup_Permissions ;;
@@ -1219,7 +1222,7 @@ Backup_data() {
\"date\": \"$(date "+%Y.%m.%d %H:%M:%S")\"
}
}"
jq --argjson new_content "$extra_content" '. += $new_content' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --argjson new_content "$extra_content" '. += $new_content' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
else
extra_content="{
\"$1\": {
@@ -1229,7 +1232,7 @@ Backup_data() {
\"date\": \"$(date "+%Y.%m.%d %H:%M:%S")\"
}
}"
jq --argjson new_content "$extra_content" '. += $new_content' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
jq --argjson new_content "$extra_content" '. += $new_content' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
fi
else
rm -rf "$Backup_folder/$1".tar.*
@@ -1484,7 +1487,7 @@ get_name(){
if [[ -f $Folder/Permissions ]]; then
unset Permissions
. "$Folder/Permissions"
jq --arg packageName "$ChineseName" --argjson permissions "$(echo "$Permissions" | jq -nR '[inputs | select(length>0) | split(" ") | {(.[0]): .[-1]}] | add')" '.[$packageName] |= . + {permissions: $permissions}' "$Folder/app_details.json" > temp.json && cp temp.json "$Folder/app_details.json" && rm -rf "$Folder/Permissions" temp.json && echoRgb "更新$Folder/app_details.json"
jq --arg packageName "$ChineseName" --argjson permissions "$(echo "$Permissions" | jq -nR '[inputs | select(length>0) | split(" ") | {(.[0]): .[-1]}] | add')" '.[$packageName] |= . + {permissions: $permissions}' "$Folder/app_details.json" > "$TMPDIR/temp.json" && cp "$TMPDIR/temp.json" "$Folder/app_details.json" && rm -rf "$Folder/Permissions" "$TMPDIR/temp.json" && echoRgb "更新$Folder/app_details.json"
fi
else
if [[ -f $Folder/app_details ]]; then
@@ -1506,7 +1509,7 @@ get_name(){
}
}"
echo "{\n}">"$Folder/app_details.json"
jq --argjson new_content "$extra_content" '. += $new_content' "$Folder/app_details.json" > temp.json && cp temp.json "$Folder/app_details.json" && rm -rf temp.json "$Folder/app_details"
jq --argjson new_content "$extra_content" '. += $new_content' "$Folder/app_details.json" > "$TMPDIR/temp.json" && cp "$TMPDIR/temp.json" "$Folder/app_details.json" && rm -rf "$TMPDIR/temp.json" "$Folder/app_details"
fi
fi
[[ ! -f $txt ]] && echo "#不需要恢復還原的應用請在開頭使用#注釋 比如:#酷安 com.coolapk.market" >"$txt"
@@ -1881,8 +1884,6 @@ backup() {
[[ $Apk_info = "" ]] && echoRgb "Apk_info變量為空" "0" && exit
[[ ! -f ${0%/*}/app_details.json ]] && {
echoRgb "檢查備份列表中是否存在已經卸載應用" "3"
i1=1
r1="$(cat "$txt" 2>/dev/null | awk 'NF != 0 { count++ } END { print count }')"
while read -r ; do
if [[ $(echo "$REPLY" | sed -E 's/^[ \t]*//; /^[ \t]*[#!]/d') != "" ]]; then
app=($REPLY $REPLY)
@@ -1899,7 +1900,7 @@ backup() {
fi
done < "$txt"
}
apks=($(cat "$txt" | grep -Ev '^[#!]' | awk '{print $1 ":" $2}'))
apks=($(grep -Ev '^[#!]' "$txt" | awk '{print $1 ":" $2}'))
[[ $Update_backup = true ]] && {
echoRgb "檢查備份列表中已經更新應用" "3"
for apk in "${apks[@]}"; do
@@ -1962,7 +1963,6 @@ backup() {
keyboard="$(settings get secure default_input_method 2>/dev/null)"
Set_screen_pause_seconds on
[[ $(egrep -v '#|' "$txt" 2>/dev/null | sed -e '/^$/d' | awk '{print $2}' | grep -w "^${keyboard%/*}$") != ${keyboard%/*} ]] && unset keyboard
{
starttime1="$(date -u "+%s")"
TIME="$starttime1"
notification "101" "開始備份"
@@ -2011,7 +2011,7 @@ backup() {
app_details="$Backup_folder/app_details.json"
if [[ -f $app_details ]]; then
PackageName="$(jq -r '.[] | select(.PackageName != null).PackageName' "$app_details")"
[[ $PackageName != $name2 ]] && jq --arg name2 "$name2" 'walk(if type == "object" and .PackageName then .PackageName = $name2 else . end)' "$app_details" > temp.json && cp temp.json "$app_details" && rm -rf temp.json
[[ $PackageName != $name2 ]] && jq --arg name2 "$name2" 'walk(if type == "object" and .PackageName then .PackageName = $name2 else . end)' "$app_details" > "$TMPDIR/temp.json" && cat "$TMPDIR/temp.json" > "$app_details" && rm "$TMPDIR/temp.json"
echoRgb "上次備份時間$(jq -r --arg entry "Backup time" '.[$entry] | select(.date != null).date' "$app_details" 2>/dev/null)"
fi
[[ $hx = USB && $PT = "" ]] && echoRgb "隨身碟意外斷開 請檢查穩定性" "0" && exit 1
@@ -2144,8 +2144,7 @@ backup() {
notification "105" "備份完成 $(endtime 1 "批量備份開始到結束")"
chown "$(stat -c '%u:%g' '/data/media/0/Download')" "$txt"
chown "$(stat -c '%u:%g' '/data/media/0/Download')" "$txt2"
} &
wait && exit
exit
}
backup_update_apk() {
Update_backup='true'
@@ -2582,7 +2581,7 @@ Getlist() {
rb="0"
Output_list() {
if [[ $(cat "$txt" | cut -f2 -d ' ' | egrep -w "^${app_1[1]}$") != ${app_1[1]} ]]; then
[[ $REPLY2 = "" ]] && add_entry "${app_1[2]}" "${app_1[1]}" "$(cat "$txt" | grep -w "${app_1[2]}")" || add_entry "${app_1[2]}" "${app_1[1]}" "$REPLY2"
[[ $REPLY2 = "" ]] && add_entry "${app_1[2]}" "${app_1[1]}" "$(grep -w "${app_1[2]}" "$txt")" || add_entry "${app_1[2]}" "${app_1[1]}" "$REPLY2"
case ${app_1[1]} in
*oneplus*|*miui*|*xiaomi*|*oppo*|*flyme*|*meizu*|com.android.soundrecorder|com.mfashiongallery.emag|com.mi.health|*coloros*|com.android.soundrecorder|com.duokan.phone.remotecontroller|com.android.calendar|com.android.deskclock|com.android.calendar|com.android.deskclock|com.google.android.safetycore|com.google.android.contactkeys|com.google.android.apps.messaging|com.google.android.calendar)
if [[ $(echo "$xposed_name" | egrep -w "${app_1[1]}$") = ${app_1[1]} ]]; then