-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore.sh
More file actions
707 lines (573 loc) · 26 KB
/
restore.sh
File metadata and controls
707 lines (573 loc) · 26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
#!/bin/bash
#===============================================================================
# Coolify Migration Tool - RESTORE SCRIPT
# https://github.com/your-repo/coolify-migration
#
# Run this on your DESTINATION server (the one you're migrating TO)
# This script will download the backup and restore everything
#===============================================================================
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
RESTORE_DIR="/tmp/coolify-restore"
BACKUP_URL=""
#-------------------------------------------------------------------------------
# Helper Functions
#-------------------------------------------------------------------------------
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_step() {
echo ""
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${CYAN} $1${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
cleanup() {
if [[ -d "${RESTORE_DIR}" ]]; then
log_info "Cleaning up temporary files..."
rm -rf "${RESTORE_DIR}"
fi
}
check_root() {
if [[ $EUID -ne 0 ]]; then
log_error "This script must be run as root (use sudo)"
exit 1
fi
}
confirm_action() {
local message="$1"
echo ""
echo -e "${YELLOW}${message}${NC}"
# If not interactive (piped), auto-confirm
if [[ ! -t 0 ]]; then
echo -e "${BLUE}[AUTO-CONFIRMED - running non-interactively]${NC}"
return
fi
read -p "Continue? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
log_info "Operation cancelled by user"
exit 0
fi
}
#-------------------------------------------------------------------------------
# System Setup Functions
#-------------------------------------------------------------------------------
install_docker() {
if command -v docker &>/dev/null; then
log_info "Docker is already installed: $(docker --version)"
return
fi
log_info "Installing Docker..."
# Install Docker using official script
curl -fsSL https://get.docker.com | sh
# Start and enable Docker
systemctl start docker
systemctl enable docker
log_success "Docker installed successfully"
}
install_dependencies() {
log_info "Installing required dependencies..."
# Detect package manager
if command -v apt-get &>/dev/null; then
apt-get update -qq
apt-get install -y -qq curl wget jq rsync tar gzip
elif command -v yum &>/dev/null; then
yum install -y -q curl wget jq rsync tar gzip
elif command -v dnf &>/dev/null; then
dnf install -y -q curl wget jq rsync tar gzip
else
log_warn "Unknown package manager. Please ensure curl, wget, jq, rsync are installed."
fi
log_success "Dependencies installed"
}
#-------------------------------------------------------------------------------
# Download Functions
#-------------------------------------------------------------------------------
get_backup_url() {
if [[ -n "$1" ]]; then
BACKUP_URL="$1"
return
fi
# Check if running interactively (stdin is a terminal)
if [[ -t 0 ]]; then
echo ""
echo -e "${YELLOW}Enter the backup URL from your source server:${NC}"
echo -e "${BLUE}(This was shown at the end of transfer.sh output)${NC}"
echo ""
read -p "Backup URL: " BACKUP_URL
if [[ -z "$BACKUP_URL" ]]; then
log_error "No URL provided"
exit 1
fi
else
# Not interactive (piped) - show usage
echo ""
log_error "No backup URL provided!"
echo ""
echo -e "${YELLOW}Usage:${NC}"
echo ""
echo " Option 1 - Download and run with URL:"
echo -e " ${GREEN}curl -fsSL https://raw.githubusercontent.com/erenbertr/coolify.migrate/main/restore.sh -o restore.sh${NC}"
echo -e " ${GREEN}chmod +x restore.sh && sudo ./restore.sh${NC}"
echo ""
echo " Option 2 - One-liner with URL argument:"
echo -e " ${GREEN}curl -fsSL https://...restore.sh | sudo bash -s -- \"http://YOUR_IP:9999/coolify-backup-XXX.tar.gz\"${NC}"
echo ""
exit 1
fi
}
download_backup() {
log_info "Downloading backup from: ${BACKUP_URL}"
mkdir -p "${RESTORE_DIR}"
cd "${RESTORE_DIR}"
# Extract filename from URL
local filename
filename=$(basename "${BACKUP_URL}")
# Download with progress
if command -v wget &>/dev/null; then
wget --progress=bar:force -O "${filename}" "${BACKUP_URL}" 2>&1
else
curl -L --progress-bar -o "${filename}" "${BACKUP_URL}"
fi
if [[ ! -f "${filename}" ]]; then
log_error "Download failed"
exit 1
fi
log_success "Download complete: ${filename}"
# Extract the archive
log_info "Extracting backup archive..."
tar -xzf "${filename}"
# Find the extracted directory
BACKUP_DIR=$(find . -maxdepth 1 -type d -name "coolify-backup-*" | head -1)
if [[ -z "$BACKUP_DIR" ]]; then
log_error "Could not find extracted backup directory"
exit 1
fi
log_success "Backup extracted to: ${BACKUP_DIR}"
}
#-------------------------------------------------------------------------------
# Validation Functions
#-------------------------------------------------------------------------------
validate_backup() {
log_info "Validating backup contents..."
local required_items=("coolify-data")
for item in "${required_items[@]}"; do
if [[ ! -e "${RESTORE_DIR}/${BACKUP_DIR}/${item}" ]]; then
log_error "Missing required backup component: ${item}"
exit 1
fi
done
# Read and display metadata (with fallbacks if parsing fails)
local metadata="${RESTORE_DIR}/${BACKUP_DIR}/metadata.json"
echo ""
echo -e "${CYAN}Backup Information:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [[ -f "$metadata" ]]; then
# Try to parse, use fallbacks if it fails
local source_hostname source_ip backup_date coolify_version docker_version os_info
source_hostname=$(jq -r '.source_hostname // "unknown"' "$metadata" 2>/dev/null || echo "unknown")
source_ip=$(jq -r '.source_ip // "unknown"' "$metadata" 2>/dev/null || echo "unknown")
backup_date=$(jq -r '.backup_date // "unknown"' "$metadata" 2>/dev/null || echo "unknown")
coolify_version=$(jq -r '.coolify_version // "unknown"' "$metadata" 2>/dev/null || echo "unknown")
docker_version=$(jq -r '.docker_version // "unknown"' "$metadata" 2>/dev/null || echo "unknown")
os_info=$(jq -r '.os_info // "unknown"' "$metadata" 2>/dev/null || echo "unknown")
echo -e " Source Server: ${YELLOW}${source_hostname}${NC}"
echo -e " Source IP: ${YELLOW}${source_ip}${NC}"
echo -e " Backup Date: ${YELLOW}${backup_date}${NC}"
echo -e " Coolify Version: ${YELLOW}${coolify_version}${NC}"
echo -e " Docker Version: ${YELLOW}${docker_version}${NC}"
echo -e " OS: ${YELLOW}${os_info}${NC}"
# Store version for later use (with fallback detection)
COOLIFY_VERSION="$coolify_version"
else
log_warn "metadata.json not found, will detect version from backup"
echo -e " ${YELLOW}Metadata file missing - will auto-detect settings${NC}"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# If version is unknown, try to detect from backup
if [[ -z "$COOLIFY_VERSION" || "$COOLIFY_VERSION" == "unknown" || "$COOLIFY_VERSION" == "null" ]]; then
if [[ -f "${RESTORE_DIR}/${BACKUP_DIR}/coolify-data/source/.env" ]]; then
COOLIFY_VERSION=$(grep -E "^COOLIFY_VERSION=" "${RESTORE_DIR}/${BACKUP_DIR}/coolify-data/source/.env" 2>/dev/null | cut -d'=' -f2 | tr -d '"' || echo "")
if [[ -n "$COOLIFY_VERSION" ]]; then
log_info "Detected Coolify version from backup: ${COOLIFY_VERSION}"
fi
fi
fi
log_success "Backup validated"
}
#-------------------------------------------------------------------------------
# Restore Functions
#-------------------------------------------------------------------------------
check_existing_coolify() {
# Stop any running Coolify containers first
log_info "Checking for running Coolify containers..."
local coolify_containers
coolify_containers=$(docker ps -aq --filter "name=coolify" 2>/dev/null || true)
if [[ -n "$coolify_containers" ]]; then
log_info "Stopping running Coolify containers..."
docker stop $coolify_containers >/dev/null 2>&1 || true
docker rm $coolify_containers >/dev/null 2>&1 || true
fi
if [[ -d "/data/coolify" ]]; then
log_warn "Existing Coolify installation detected at /data/coolify"
confirm_action "This will REPLACE the existing installation. All current data will be lost!"
# Stop existing Coolify if running (using compose)
if [[ -d "/data/coolify/source" ]]; then
log_info "Stopping existing Coolify via compose..."
cd /data/coolify/source
docker compose -f docker-compose.yml -f docker-compose.prod.yml down 2>/dev/null || \
docker compose down 2>/dev/null || \
docker-compose down 2>/dev/null || true
fi
# Remove existing Coolify docker volumes (they will be restored from backup)
log_info "Removing existing Coolify volumes (will restore from backup)..."
for vol in coolify-db coolify-redis; do
if docker volume inspect "$vol" >/dev/null 2>&1; then
docker volume rm "$vol" 2>/dev/null || log_warn "Could not remove $vol volume"
fi
done
# Backup existing installation just in case
log_info "Creating backup of existing installation..."
mv /data/coolify "/data/coolify.backup.$(date +%Y%m%d-%H%M%S)"
fi
# Also remove coolify volumes even if /data/coolify doesn't exist
# (in case volumes exist from a partial install)
for vol in coolify-db coolify-redis; do
if docker volume inspect "$vol" >/dev/null 2>&1; then
log_info "Removing existing volume: $vol"
docker volume rm "$vol" 2>/dev/null || true
fi
done
}
restore_coolify_data() {
log_info "Restoring Coolify data..."
# Create data directory
mkdir -p /data
# Restore with preserved permissions
rsync -a --info=progress2 "${RESTORE_DIR}/${BACKUP_DIR}/coolify-data/" /data/coolify/
log_success "Coolify data restored to /data/coolify"
}
restore_docker_volumes() {
log_info "Restoring Docker volumes..."
local volumes_dir="${RESTORE_DIR}/${BACKUP_DIR}/docker-volumes"
if [[ ! -d "$volumes_dir" ]] || [[ -z "$(ls -A "$volumes_dir" 2>/dev/null)" ]]; then
log_warn "No Docker volumes to restore"
return
fi
local count=0
local total
total=$(find "$volumes_dir" -name "*.tar.gz" | wc -l)
for archive in "$volumes_dir"/*.tar.gz; do
if [[ -f "$archive" ]]; then
((count++)) || true
local volume_name
volume_name=$(basename "$archive" .tar.gz)
log_info "Restoring volume ($count/$total): $volume_name"
# Remove existing volume if it exists (it may have stale/empty data)
if docker volume inspect "$volume_name" >/dev/null 2>&1; then
log_info " Removing existing volume: $volume_name"
# Stop any containers using this volume
local containers
containers=$(docker ps -aq --filter "volume=$volume_name" 2>/dev/null || true)
if [[ -n "$containers" ]]; then
docker stop $containers >/dev/null 2>&1 || true
docker rm $containers >/dev/null 2>&1 || true
fi
docker volume rm "$volume_name" >/dev/null 2>&1 || {
log_warn " Could not remove volume $volume_name, trying to restore anyway"
}
fi
# Create the volume fresh
docker volume create "$volume_name" >/dev/null 2>&1 || true
# Restore data to the volume
log_info " Extracting data to volume..."
if docker run --rm \
-v "${volume_name}:/target" \
-v "${archive}:/backup.tar.gz:ro" \
alpine sh -c "cd /target && tar -xzf /backup.tar.gz" 2>&1; then
log_success " Volume restored: $volume_name"
else
log_warn " Failed to restore volume: $volume_name"
fi
fi
done
log_success "Docker volumes restored"
}
restore_docker_networks() {
log_info "Restoring Docker networks..."
local networks_dir="${RESTORE_DIR}/${BACKUP_DIR}/docker-networks"
if [[ ! -d "$networks_dir" ]] || [[ -z "$(ls -A "$networks_dir" 2>/dev/null)" ]]; then
log_warn "No Docker networks to restore"
return
fi
for network_file in "$networks_dir"/*.json; do
if [[ -f "$network_file" ]]; then
local network_name
network_name=$(basename "$network_file" .json)
# Check if network already exists
if docker network inspect "$network_name" >/dev/null 2>&1; then
log_info "Network already exists: $network_name"
continue
fi
# Extract network configuration and recreate
local driver
local subnet
driver=$(jq -r '.[0].Driver' "$network_file")
subnet=$(jq -r '.[0].IPAM.Config[0].Subnet // empty' "$network_file")
if [[ -n "$subnet" ]]; then
docker network create --driver "$driver" --subnet "$subnet" "$network_name" >/dev/null 2>&1 || {
# Try without subnet if it conflicts
docker network create --driver "$driver" "$network_name" >/dev/null 2>&1 || true
}
else
docker network create --driver "$driver" "$network_name" >/dev/null 2>&1 || true
fi
log_info "Restored network: $network_name"
fi
done
log_success "Docker networks restored"
}
install_coolify() {
log_info "Installing Coolify (version: ${COOLIFY_VERSION:-unknown})..."
# The Coolify source should already be in /data/coolify/source from the backup
if [[ ! -d "/data/coolify/source" ]]; then
log_error "Coolify source not found in backup"
exit 1
fi
cd /data/coolify/source
# Determine which compose files to use
local compose_files=""
if [[ -f "docker-compose.prod.yml" ]]; then
compose_files="-f docker-compose.yml -f docker-compose.prod.yml"
log_info "Using production compose files"
elif [[ -f "docker-compose.yml" ]]; then
compose_files="-f docker-compose.yml"
elif [[ -f "compose.yml" ]]; then
compose_files="-f compose.yml"
else
log_error "No docker-compose file found in /data/coolify/source"
ls -la /data/coolify/source/
exit 1
fi
# Store compose files for later use
export COMPOSE_FILES="$compose_files"
# Pull the images
log_info "Pulling Docker images..."
if docker compose $compose_files pull 2>&1; then
log_success "Coolify images pulled"
else
log_warn "Could not pull images - will try to start with existing images"
fi
}
start_coolify() {
log_info "Starting Coolify..."
cd /data/coolify/source
# Determine compose files if not already set
if [[ -z "$COMPOSE_FILES" ]]; then
if [[ -f "docker-compose.prod.yml" ]]; then
COMPOSE_FILES="-f docker-compose.yml -f docker-compose.prod.yml"
else
COMPOSE_FILES="-f docker-compose.yml"
fi
fi
log_info "Using: docker compose $COMPOSE_FILES up -d"
if docker compose $COMPOSE_FILES up -d 2>&1; then
log_info "Coolify containers started"
else
log_error "Failed to start Coolify"
log_info "Try manually: cd /data/coolify/source && docker compose $COMPOSE_FILES up -d"
exit 1
fi
# Wait for Coolify to start
log_info "Waiting for Coolify to start..."
sleep 10
# Check if Coolify is running
if docker ps | grep -q coolify; then
log_success "Coolify is running"
else
log_warn "Coolify may not have started correctly. Check with: docker ps"
log_info "View logs with: docker compose $COMPOSE_FILES logs -f"
fi
}
update_server_ip() {
log_info "Checking if server IP needs updating..."
local new_ip
new_ip=$(curl -4 -s --max-time 5 https://ifconfig.me 2>/dev/null || hostname -I | awk '{print $1}')
local env_file="/data/coolify/source/.env"
if [[ -f "$env_file" ]]; then
local old_ip
old_ip=$(grep -E "^APP_URL=" "$env_file" | grep -oP '\d+\.\d+\.\d+\.\d+' || true)
if [[ -n "$old_ip" && "$old_ip" != "$new_ip" ]]; then
log_info "Updating server IP from ${old_ip} to ${new_ip}..."
sed -i "s/${old_ip}/${new_ip}/g" "$env_file"
log_success "Server IP updated in configuration"
fi
fi
}
setup_ssh_keys() {
log_info "SSH Key Setup Required..."
# SSH keys for localhost are stored in Coolify's database and regenerated on container start.
# The private key in the database is tied to the old server's authorized_keys.
# After migration, you must regenerate the key in Coolify UI and add it to authorized_keys.
# Ensure root's .ssh directory exists with correct permissions
mkdir -p /root/.ssh
chmod 700 /root/.ssh
touch /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
# Ensure SSH server allows root login with keys
if [[ -f /etc/ssh/sshd_config ]]; then
if grep -q "^PermitRootLogin" /etc/ssh/sshd_config; then
sed -i 's/^PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
elif grep -q "^#PermitRootLogin" /etc/ssh/sshd_config; then
sed -i 's/^#PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
else
echo "PermitRootLogin prohibit-password" >> /etc/ssh/sshd_config
fi
# Restart SSH service
systemctl restart sshd 2>/dev/null || systemctl restart ssh 2>/dev/null || service ssh restart 2>/dev/null || true
fi
log_warn "MANUAL STEP REQUIRED after restore completes - see instructions below"
}
setup_docker_buildx() {
log_info "Setting up Docker Buildx for Coolify..."
# Coolify uses a custom buildx builder for building applications
# This must be created on the new server
# Check if coolify builder already exists
if docker buildx inspect coolify >/dev/null 2>&1; then
log_info "Coolify buildx builder already exists"
else
log_info "Creating Coolify buildx builder..."
docker buildx create --name coolify --driver docker-container --bootstrap 2>&1 || {
log_warn "Could not create buildx builder 'coolify', trying alternative..."
docker buildx create --name coolify --driver docker-container 2>&1 || true
}
fi
# Verify buildx is working
if docker buildx inspect coolify >/dev/null 2>&1; then
log_success "Docker Buildx 'coolify' builder is ready"
else
log_warn "Buildx builder may not be fully configured - builds might use default builder"
fi
# Also ensure default builder is available
docker buildx inspect default >/dev/null 2>&1 || docker buildx create --name default --use 2>&1 || true
# Pull common build images that Coolify needs
log_info "Pulling Coolify helper images..."
docker pull ghcr.io/coollabsio/coolify-helper:latest 2>&1 || true
docker pull ghcr.io/railwayapp/nixpacks:latest 2>&1 || true
log_success "Docker Buildx setup complete"
}
#-------------------------------------------------------------------------------
# Post-Restore Functions
#-------------------------------------------------------------------------------
print_post_restore_info() {
local server_ip
server_ip=$(curl -4 -s --max-time 5 https://ifconfig.me 2>/dev/null || hostname -I | awk '{print $1}')
echo ""
echo "==============================================================================="
echo -e "${GREEN} RESTORE COMPLETE!${NC}"
echo "==============================================================================="
echo ""
echo -e "${CYAN}Your Coolify instance has been restored.${NC}"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${RED}⚠️ REQUIRED: Fix SSH Connection (do this first!)${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " Your localhost server will show 'not reachable' until you do this:"
echo ""
echo " 1. Open Coolify: http://${server_ip}:8000"
echo " 2. Go to: Security → Private Keys → localhost's key"
echo " 3. Copy the Public Key shown there"
echo " 4. Run this command (paste the key between the quotes):"
echo ""
echo -e " ${GREEN}echo \"PASTE_PUBLIC_KEY_HERE\" >> /root/.ssh/authorized_keys${NC}"
echo ""
echo " 5. Go to: Servers → localhost → Click 'Validate Server'"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${YELLOW}NEXT STEPS:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "1. ${CYAN}Update DNS Records:${NC}"
echo " Point your domains to the new server IP: ${server_ip}"
echo ""
echo "2. ${CYAN}Redeploy Applications:${NC}"
echo " After fixing SSH, redeploy your apps in Coolify dashboard"
echo ""
echo "3. ${CYAN}Verify SSL Certificates:${NC}"
echo " Coolify should auto-renew certificates after redeploy"
echo ""
echo "4. ${CYAN}Update Webhooks (if any):${NC}"
echo " Update GitHub/GitLab webhooks to point to new server"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${YELLOW}TROUBLESHOOTING:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " View logs: docker logs coolify -f"
echo " Restart Coolify: cd /data/coolify/source && docker compose restart"
echo " Check containers: docker ps"
echo ""
echo "==============================================================================="
echo ""
}
#-------------------------------------------------------------------------------
# Main Execution
#-------------------------------------------------------------------------------
main() {
echo ""
echo "==============================================================================="
echo " COOLIFY MIGRATION - RESTORE SCRIPT "
echo "==============================================================================="
echo ""
check_root
# Get backup URL (from argument or prompt)
get_backup_url "$1"
log_step "Step 1/8: Installing Dependencies"
install_dependencies
log_step "Step 2/8: Installing Docker"
install_docker
log_step "Step 3/8: Downloading Backup"
download_backup
log_step "Step 4/8: Validating Backup"
validate_backup
confirm_action "Ready to restore Coolify. This will set up the complete installation."
log_step "Step 5/8: Checking Existing Installation"
check_existing_coolify
log_step "Step 6/8: Restoring Data"
restore_coolify_data
restore_docker_volumes
restore_docker_networks
log_step "Step 7/10: Installing Coolify"
install_coolify
update_server_ip
log_step "Step 8/10: Setting up Docker Buildx"
setup_docker_buildx
log_step "Step 9/10: Setting up SSH Keys"
setup_ssh_keys
log_step "Step 10/10: Starting Coolify"
start_coolify
# Cleanup
cleanup
# Print final information
print_post_restore_info
}
main "$@"