#!/bin/ash backup_dir="." overlay_dir="/overlay" while true; do echo "" echo "请选择操作:" echo "1. 备份 /overlay 目录" echo "2. 还原 /overlay 目录" echo "q. 退出脚本" read -rp "请输入选项 (1/2/q): " choice case "$choice" in 1) backup_file="${backup_dir}/backup_$(date +%Y-%m-%d).tar.gz" echo "正在备份 $overlay_dir 到 $backup_file..." if tar -czvf "$backup_file" "$overlay_dir"; then sync echo "✅ 备份成功: $backup_file" else echo "❌ 备份失败: 无法创建备份文件" fi ;; 2) echo "扫描可用备份文件..." set -- "${backup_dir}"/backup_*.tar.gz [ -e "$1" ] || { echo "❌ 没有找到可用的备份文件!" continue } index=1 for file in "$@"; do echo "$index) $(basename "$file")" eval "backup_$index=\"$file\"" index=$((index+1)) done read -rp "请输入要还原的备份编号: " selection eval "selected_file=\${backup_$selection}" if [ -z "$selected_file" ] || [ ! -f "$selected_file" ]; then echo "❌ 无效编号,返回主菜单。" continue fi echo "正在还原 $selected_file 到根目录..." if tar -xzvf "$selected_file" -C /; then sync echo "✅ 还原成功!" else echo "❌ 还原失败: 解压过程中出错" fi ;; q) echo "👋 已退出脚本。" break ;; *) echo "❌ 无效选项,请重新输入。" ;; esac done