Skip to content

Commit 2eb5915

Browse files
committed
fix: Correct restore script creation and improve container backup list handling
1 parent ee8e680 commit 2eb5915

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docker-backup.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ log_info " 停止服务: cd ${TEMP_COMPOSE_DIR} && docker-compose -f ${COMPOSE_
689689
COMPOSE_EOF
690690
else
691691
# 为普通容器创建恢复脚本
692-
cat > "${backup_dir}/restore.sh" << 'EOF'
692+
cat > "${backup_dir}/restore.sh" << EOF
693693
#!/bin/bash
694694
695695
# Docker容器恢复脚本
@@ -934,6 +934,7 @@ fi
934934
935935
log_success "容器恢复完成!"
936936
EOF
937+
fi
937938

938939
chmod +x "${backup_dir}/restore.sh"
939940
log_success "恢复脚本创建完成"
@@ -1125,8 +1126,12 @@ main() {
11251126
mkdir -p "${BACKUP_DIR}"
11261127

11271128
# 获取要备份的容器列表
1128-
local containers_to_backup
1129-
mapfile -t containers_to_backup < <(get_containers)
1129+
local containers_to_backup=()
1130+
while IFS= read -r container; do
1131+
if [[ -n "$container" ]]; then
1132+
containers_to_backup+=("$container")
1133+
fi
1134+
done < <(get_containers)
11301135

11311136
if [[ ${#containers_to_backup[@]} -eq 0 ]]; then
11321137
log_warning "未找到要备份的容器"

0 commit comments

Comments
 (0)