Skip to content

Commit

Permalink
upgrade the pg
Browse files Browse the repository at this point in the history
Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa committed Dec 18, 2024
1 parent e7461f0 commit dcbca61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
34 changes: 34 additions & 0 deletions doc/upgrade/restore_event_tables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Tables: `history.local_compliance` and `history.local_compliance_job_log`

# Set namespace and pod names
NAMESPACE="${1:-multicluster-global-hub}"
SOURCE_POD="multicluster-global-hub-postgres-0" # Source pod
SOURCE_CONTAINER="multicluster-global-hub-postgres" # Source container
TARGET_POD="multicluster-global-hub-postgresql-0" # Target pod
TARGET_CONTAINER="multicluster-global-hub-postgresql" # Target container
REMOTE_PATH="/tmp/history_tables_backup.sql" # Without leading `/` to suppress tar warnings
DB_NAME="hoh"
DB_USER="postgres"

echo "Using namespace: $NAMESPACE"

# Backup from source pod
echo ">> Backing up history tables from $SOURCE_POD ($SOURCE_CONTAINER)..."
kubectl exec -c $SOURCE_CONTAINER $SOURCE_POD -n $NAMESPACE -- pg_dump -U $DB_USER -d $DB_NAME -t 'history.*' --data-only -f $REMOTE_PATH 2>/dev/null
kubectl cp $NAMESPACE/$SOURCE_POD:$REMOTE_PATH ./history_tables_backup.sql -c $SOURCE_CONTAINER >/dev/null 2>&1
echo ">> Backup completed."

# Restore to target pod
echo ">> Restoring history tables to $TARGET_POD ($TARGET_CONTAINER)..."
kubectl cp ./history_tables_backup.sql $NAMESPACE/$TARGET_POD:$REMOTE_PATH -c $TARGET_CONTAINER
kubectl exec -c $TARGET_CONTAINER $TARGET_POD -n $NAMESPACE -- psql -U $DB_USER -d $DB_NAME -f $REMOTE_PATH
echo ">> Restore completed."

# Cleanup
echo ">> Cleaning up temporary files..."
kubectl exec -c $SOURCE_CONTAINER $SOURCE_POD -n $NAMESPACE -- rm $REMOTE_PATH
kubectl exec -c $TARGET_CONTAINER $TARGET_POD -n $NAMESPACE -- rm $REMOTE_PATH
rm ./history_tables_backup.sql
echo ">> Local and remote backup files removed. Done!"
19 changes: 2 additions & 17 deletions doc/upgrade/upgrade_to_globalhub_1.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,9 @@ But the history data like event and history tables will be be recovered. If you

### History data backup and restore[Optional]

1. Restore History Tables
1. Restore History Tables use the script `./doc/upgrade/restore_history_tables.sh`.

- Target tables: `history.local_compliance` and `history.local_compliance_job_log`

- Bacup

```bash
kubectl exec -it multicluster-global-hub-postgres-0 -n multicluster-global-hub -- pg_dump -U postgres -d hoh -t 'history.*' --data-only -f /tmp/history_tables_backup.sql
kubectl cp multicluster-global-hub/multicluster-global-hub-postgres-0:/tmp/history_tables_backup.sql ./history_tables_backup.sql
```

- Restore

```bash
kubectl cp ./history_tables_backup.sql multicluster-global-hub/multicluster-global-hub-postgresql-0:/tmp/history_tables_backup.sql
kubectl exec -it multicluster-global-hub-postgresql-0 -n multicluster-global-hub -- psql -U postgres -d hoh -f /tmp/history_tables_backup.sql
kubectl exec -it multicluster-global-hub-postgresql-0 -n multicluster-global-hub -- rm /tmp/history_tables_backup.sql
```
2. Restore Event Tables use the script `./doc/upgrade/restore_event_tables.sh`.

### Delete the legacy builtin postgres resources manually[Optional]

Expand Down

0 comments on commit dcbca61

Please sign in to comment.