Database File Management and Migration
ServBay, as an integrated development and deployment platform, provides various database management systems and classifies database files stored in specific directories. This article will detail the default structure of database file storage in ServBay and provide guidance on database file management and migration.
Default Database File Storage Structure in ServBay
ServBay's default database files are stored in the directory /Applications/ServBay/db
. This directory is categorized by database type, and then further classified based on the major version number of the database. Below is a sample directory structure:
/Applications/ServBay/db
├── mariadb
│ ├── 10.10
│ ├── 10.11
│ ├── 10.5
│ ├── 10.6
│ ├── 10.7
│ ├── 10.8
│ ├── 10.9
│ ├── 11.0
│ ├── 11.1
│ ├── 11.2
│ └── 11.3
├── postgresql
│ ├── 10
│ ├── 11
│ ├── 12
│ ├── 13
│ ├── 14
│ ├── 15
│ └── 16
└── redis
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Explanation of Directory Structure
- mariadb: Stores MariaDB database files, categorized by major version numbers (e.g., 10.10, 10.11, etc.).
- postgresql: Stores PostgreSQL database files, categorized by major version numbers (e.g., 10, 11, 12, etc.).
- redis: Stores Redis database files, usually as
dump.rdb
files.
Database File Management
During everyday database management, you may need to perform tasks such as backup, recovery, and migration. Below are some common database file management operations.
Backing Up Databases
Backing up databases is an important step in ensuring data safety. Here are examples of how to back up different types of databases.
Backing Up MariaDB
- Use the
mysqldump
tool to back up:bashmysqldump -u your_username -p your_database > /Applications/ServBay/backup/your_database.sql
1
Backing Up PostgreSQL
- Use the
pg_dump
tool to back up:bashpg_dump -h /Applications/ServBay/tmp -U your_username -d your_database -F c -b -v -f /Applications/ServBay/backup/your_database.dump
1
Backing Up Redis
- Copy the
dump.rdb
file:bashcp /Applications/ServBay/db/redis/dump.rdb /Applications/ServBay/backup/dump.rdb
1
Restoring Databases
When you need to restore a database, you can use the backup files for restoration.
Restoring MariaDB
- Use the
mysql
tool to restore:bashmysql -u your_username -p your_database < /Applications/ServBay/backup/your_database.sql
1
Restoring PostgreSQL
- Use the
pg_restore
tool to restore:bashpg_restore -h /Applications/ServBay/tmp -U your_username -d your_database -v /Applications/ServBay/backup/your_database.dump
1
Restoring Redis
- Copy the
dump.rdb
file to the Redis data directory:bashcp /Applications/ServBay/backup/dump.rdb /Applications/ServBay/db/redis/dump.rdb
1
Migrating Databases
Database migration is the process of moving a database from one environment to another. Below are examples of how to migrate different types of databases.
Migrating MariaDB
Export the source database:
bashmysqldump -u your_source_username -p your_database > /Applications/ServBay/backup/your_database.sql
1Create the database in the target environment:
bashmysql -u your_target_username -p -e "CREATE DATABASE your_database;"
1Import the database to the target environment:
bashmysql -u your_target_username -p your_database < /Applications/ServBay/backup/your_database.sql
1
Migrating PostgreSQL
Export the source database:
bashpg_dump -h /Applications/ServBay/tmp -U your_source_username -d your_database -F c -b -v -f /Applications/ServBay/backup/your_database.dump
1Create the database in the target environment:
bashpsql -U your_target_username -d postgres -c "CREATE DATABASE your_database;"
1Import the database to the target environment:
bashpg_restore -U your_target_username -d your_database -v /Applications/ServBay/backup/your_database.dump
1
Migrating Redis
- Copy the
dump.rdb
file to the target environment:bashscp /Applications/ServBay/backup/dump.rdb your_target_server:/Applications/ServBay/db/redis/dump.rdb
1
Summary
ServBay provides an integrated database management environment by categorizing and storing database files in the /Applications/ServBay/db
directory, which facilitates the management and migration of database files. This article has detailed how to back up, restore, and migrate databases such as MariaDB, PostgreSQL, and Redis. By following these steps, you can ensure the safety and consistency of your database data and easily migrate databases across different environments.