- describe db backup and restore
parent
e2f435a698
commit
af4aa72894
|
@ -157,3 +157,57 @@ worstcase: Restore whole data disk, which is mounted into /storage, and all of i
|
|||
|
||||
One of the common backup and restore configurations is an environment with two SQL Servers (SQLServer-1 and SQLServer-2), two SQL Server instances (SQLInstance-1 and SQLInstance-2), and one database named SQLDB-1 which will be backed up, transferred, and restored to SQLServer-2.
|
||||
![Image](./db_backup.drawio.svg)
|
||||
<br>
|
||||
<br>
|
||||
## Create DB backup
|
||||
|
||||
To create a backup of a research database using pg_dump, you can follow these steps:
|
||||
|
||||
1. Open a terminal or command prompt and navigate to the directory where you want to store the backup file.
|
||||
2. Type the following command to create a backup of the database:
|
||||
|
||||
```bash
|
||||
pg_dump -U <username> -E UTF8 -F c -b -v -f <backup_file_name>.backup <database_name>
|
||||
```
|
||||
|
||||
Here, replace **username** with the username of the database, **backup_file_name** with the name you want to give to the backup file, and **database_name** with the name of the research database you want to backup.
|
||||
|
||||
-E is for the encoding, e.g. UTF8
|
||||
-F c specifies the format of the backup as a custom format, which is more flexible than plain SQL text format. \
|
||||
-b includes the backup of the objects such as functions and procedures. \
|
||||
-v enables verbose mode which will display the progress of the backup process. \
|
||||
|
||||
Usually the timestamp is integrated into the backup_file_name:
|
||||
|
||||
```bash
|
||||
pg_dump -U <username> -F c -b -v -f <database_name>_$(date +"%Y%m%d_%H%M%S").backup <database_name>
|
||||
e.g.:
|
||||
pg_dump -U tethys_user -E UTF8 -F c -b -v -f /home/user/backups/tethys_$(date +"%Y%m%d").backup tethys
|
||||
```
|
||||
|
||||
3. When you run the command, you will be prompted to enter the password for the database user. Enter the password and press enter.
|
||||
4. The pg_dump command will start creating the backup file. Wait until it completes, which may take several minutes depending on the size of the database.
|
||||
|
||||
5. Once the backup is complete, you will see a message indicating that the backup has been created successfully.
|
||||
|
||||
It's important to note that the backup file may contain sensitive information, so it should be stored securely and only accessible to authorized personnel.
|
||||
<br>
|
||||
<br>
|
||||
## Restore DB on second DB-Server
|
||||
|
||||
To restore a backup of the research database using pg_restore, you can follow these steps:
|
||||
|
||||
1. Open a terminal or command prompt and navigate to the directory where the backup file is located.
|
||||
2. Type the following command to restore the backup to the database:
|
||||
```bash
|
||||
pg_restore -U <username> -d <database_name> <backup_file_name>
|
||||
```
|
||||
Here, replace <username> with the username of the database, <database_name> with the name of the research database you want to restore the backup to, and <backup_file_name> with the name of the backup file.
|
||||
3. When you run the command, you will be prompted to enter the password for the database user. Enter the password and press enter.
|
||||
4. The pg_restore command will start restoring the backup file to the database. Wait until it completes, which may take several minutes depending on the size of the database.
|
||||
|
||||
e.g.
|
||||
```
|
||||
pg_restore -h localhost -p 5432 -U tethys_user -d tethys_db -v /tmp/tethys_20230404.backup
|
||||
```
|
||||
Once the restore process is complete, the research database should be fully recovered with all its data and objects.
|
||||
|
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 14 KiB |
Loading…
Reference in New Issue
Block a user