---
# System prepended metadata

title: Restoring PostgreSQL Backups in Docker Container (`ras-backend-database-1`)
tags: [SPO]

---

# Restoring PostgreSQL Backups in Docker Container (`ras-backend-database-1`)

This document outlines the steps to restore PostgreSQL databases from backup `.sql` files into a Docker container named `ras-backend-database-1`.

##  What You’ll Need

-  Docker installed and running
- Your `ras-backend` Docker setup running (`docker ps` should show `ras-backend-database-1`)
* A folder with the following 5 SQL backup files:

  * `auth_backup.sql`
  * `student_backup.sql`
  * `company_backup.sql`
  * `rc_backup.sql`
  * `application_backup.sql`

---

## Step-by-Step Guide

### 1. Go to the Backup Folder

First, open a terminal and `cd` into the directory where your SQL backup files are located. Run:

```bash
ls
```

You should see the 5 `.sql` files listed.

---

### 2. Make Sure the Container is Running

Check if your backend database container is running:

```bash
docker ps
```

Look for `ras-backend-database-1` in the list. If it's not running, you might need to start your Docker setup.

---

### 3. Copy SQL Files into the Container

Now, copy all the SQL files into the container’s `/tmp` directory:

```bash
docker cp . ras-backend-database-1:/tmp/
```

This sends the whole current directory into the container.

---

### 4. To Open a Terminal Inside the Container

Start an interactive session inside the container:

```bash
docker exec -it ras-backend-database-1 bash
```

---

### 5. Go to the Folder with the Backups

Once you're inside the container, go to the folder where the files were copied:

```bash
cd /tmp
ls
```

You should see all five `.sql` files there.

---

### 6. Restore the Databases (in this exact order)

Run these commands one by one:

```bash
psql -U postgres -d auth        -f auth_backup.sql
psql -U postgres -d student     -f student_backup.sql
psql -U postgres -d company     -f company_backup.sql
psql -U postgres -d rc          -f rc_backup.sql
psql -U postgres -d application -f application_backup.sql
```

> **Important:** Stick to this order to make sure all relationships between databases are preserved correctly.

---

## Visual Reference

Here’s a snapshot of what it should look like:

![image](https://hackmd.io/_uploads/r1x_h0Sfxg.png)

