-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore_database.sh
More file actions
executable file
·84 lines (70 loc) · 2.16 KB
/
restore_database.sh
File metadata and controls
executable file
·84 lines (70 loc) · 2.16 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
#!/bin/bash
# Restore script for Odoo database
# Usage: ./restore_database.sh <backup_file> [target_database_name]
set -e
# Configuration
BACKUP_FILE="$1"
TARGET_DB="${2:-gypex_dev}"
DB_USER="odoo"
DB_HOST="localhost"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Odoo Database Restore${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Check if backup file exists
if [ -z "${BACKUP_FILE}" ] || [ ! -f "${BACKUP_FILE}" ]; then
echo -e "${RED}ERROR: Backup file not found!${NC}"
echo ""
echo "Usage: $0 <backup_file> [target_database_name]"
echo ""
echo "Available backups:"
ls -lh /home/user/Documents/Odoo/backups/*.dump 2>/dev/null | awk '{print " " $9 " (" $5 ")"}'
exit 1
fi
echo "Backup file: ${BACKUP_FILE}"
echo "Target database: ${TARGET_DB}"
echo ""
# Warning
echo -e "${YELLOW}WARNING: This will OVERWRITE the target database!${NC}"
echo -e "${YELLOW}All data in '${TARGET_DB}' will be lost!${NC}"
echo ""
read -p "Are you sure you want to continue? (yes/no): " confirm
if [ "${confirm}" != "yes" ]; then
echo "Restore cancelled."
exit 0
fi
echo ""
echo "Stopping Odoo server..."
pkill -f odoo-bin || true
sleep 2
echo ""
echo "Dropping existing database (if exists)..."
PGPASSWORD=odoo psql -h "${DB_HOST}" -U "${DB_USER}" -c "DROP DATABASE IF EXISTS ${TARGET_DB};" postgres
echo ""
echo "Creating new database..."
PGPASSWORD=odoo psql -h "${DB_HOST}" -U "${DB_USER}" -c "CREATE DATABASE ${TARGET_DB};" postgres
echo ""
echo "Restoring backup..."
PGPASSWORD=odoo pg_restore -h "${DB_HOST}" -U "${DB_USER}" \
-d "${TARGET_DB}" \
-v \
"${BACKUP_FILE}" 2>&1 | grep -E "(restoring|ERROR|WARNING)" || true
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}✓ Restore completed successfully!${NC}"
echo ""
echo "Next steps:"
echo "1. Update config/odoo.conf if needed"
echo "2. Start Odoo server"
echo "3. Upgrade modules: odoo-bin -u all -d ${TARGET_DB}"
else
echo ""
echo -e "${RED}ERROR: Restore failed!${NC}"
exit 1
fi