ServBay Database File Management & Migration Guide
ServBay is a powerful local web development environment that integrates multiple popular database management systems and organizes their data files in a standardized structure. Understanding the default database file organization in ServBay is crucial for developers when performing data backup, restoration, and migration.
This document explains ServBay’s default database file structure in detail and provides step-by-step guidance on managing and migrating database files using standard command-line tools.
TIP
ServBay offers data backup and restore functionalities, allowing you to back up MySQL, MariaDB, and PostgreSQL databases automatically or manually. Please refer to Backup & Restore for more information.
ServBay Default Database File Structure
To facilitate management and ensure separation of different database versions, ServBay stores all database files at /Applications/ServBay/db
. Inside this directory, data is categorized by database type, then further organized by major version number within each type.
Below is a typical example structure of the /Applications/ServBay/db
directory:
/Applications/ServBay/db
├── mysql
│ ├── 8.0
│ └── 8.1
├── 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
23
24
25
Directory Structure Explanation
/Applications/ServBay/db
: The main directory where ServBay stores all database files.mysql
: Contains MySQL data files, with subdirectories for each major version (e.g.,8.0
,8.1
).mariadb
: Contains MariaDB data files, with subdirectories per major version (e.g.,10.11
,11.3
).postgresql
: Contains PostgreSQL data files, with subdirectories for major versions (e.g.,15
,16
).redis
: Stores Redis persistence files, typically thedump.rdb
file.
This structure allows you to install and run multiple major versions of each database type in ServBay, with their data files completely isolated from each other to avoid conflicts.
Database File Management
During local development, you'll frequently need to back up, restore, or migrate your databases. The following are methods for these operations using standard command-line tools for each supported database. Note that these tasks generally require you to use the ServBay terminal environment or ensure your environment variables are set so you can access the relevant database clients and tools.
Backing Up Databases
Regular backups are key to protecting your data. Here’s how to back up different database types in ServBay.
Backing Up MySQL
The standard way to back up a MySQL database is using the mysqldump
tool.
# Switch to the terminal provided by ServBay, or ensure your PATH includes ServBay’s bin directory
# For example: export PATH="/Applications/ServBay/bin:$PATH"
mysqldump -u your_username -p your_database > /Applications/ServBay/backup/your_database.sql
2
3
4
your_username
: Replace with your database username.your_database
: Replace with the name of the database you wish to back up./Applications/ServBay/backup/your_database.sql
: Specify the path and filename where you want to save your backup. It is recommended to store the backup outside the ServBay directory, such as within your user directory.
Backing Up MariaDB
MariaDB backups work the same as MySQL, also using the mysqldump
tool.
# Switch to the terminal provided by ServBay, or ensure your PATH includes ServBay’s bin directory
mysqldump -u your_username -p your_database > /Applications/ServBay/backup/your_database.sql
2
3
- The parameters are the same as above.
Backing Up PostgreSQL
Use the pg_dump
tool to back up your PostgreSQL database. Note: In ServBay, PostgreSQL usually uses a Unix domain socket for connections, with the default path as /Applications/ServBay/tmp
, so the command must specify -h /Applications/ServBay/tmp
.
# Switch to the terminal provided by ServBay, or ensure your PATH includes ServBay’s bin directory
pg_dump -h /Applications/ServBay/tmp -U your_username -d your_database -F c -b -v -f /Applications/ServBay/backup/your_database.dump
2
3
-h /Applications/ServBay/tmp
: Specifies the PostgreSQL server's socket file path.-U your_username
: Replace with your database username.-d your_database
: The database you want to back up.-F c
: Output format set to custom archive (recommended).-b
: Include large objects (BLOBs).-v
: Verbose output.-f /Applications/ServBay/backup/your_database.dump
: File path and name for your backup file.
Backing Up Redis
Backing up Redis usually involves copying its persistence file dump.rdb
.
# Switch to the terminal provided by ServBay
# Be sure the Redis service is running, or that automatic saving (BGSAVE) is enabled
cp /Applications/ServBay/db/redis/dump.rdb /Applications/ServBay/backup/dump.rdb
2
3
4
/Applications/ServBay/db/redis/dump.rdb
: The default location of Redis persistence file./Applications/ServBay/backup/dump.rdb
: Specify the path and filename where you want to save your backup.
Restoring Databases
You can restore databases from backup files when data is lost or you need to roll back to a previous state.
Restoring MySQL
Use the mysql
client to restore a MySQL backup file.
# Switch to the terminal provided by ServBay
mysql -u your_username -p your_database < /Applications/ServBay/backup/your_database.sql
2
3
your_username
: Database username.your_database
: The database to restore into. This usually needs to be created first./Applications/ServBay/backup/your_database.sql
: Path to your backup file.
Restoring MariaDB
Restoring MariaDB is just like MySQL—use the mysql
client tool.
# Switch to the terminal provided by ServBay
mysql -u your_username -p your_database < /Applications/ServBay/backup/your_database.sql
2
3
- The parameters are the same as above.
Restoring PostgreSQL
For restoring PostgreSQL custom-format backups, use the pg_restore
tool. Again, specify the socket path with -h /Applications/ServBay/tmp
.
# Switch to the terminal provided by ServBay
pg_restore -h /Applications/ServBay/tmp -U your_username -d your_database -v /Applications/ServBay/backup/your_database.dump
2
3
-h /Applications/ServBay/tmp
: PostgreSQL server socket path.-U your_username
: Database username.-d your_database
: The database to restore to. It should be created in advance.-v
: Verbose output./Applications/ServBay/backup/your_database.dump
: Path to your backup file.
Restoring Redis
To restore Redis, copy the dump.rdb
backup file back to the Redis data directory. Important: Ensure the Redis service is stopped before proceeding.
# Switch to the terminal provided by ServBay
# Stop the Redis service in ServBay
# Copy the backup file
cp /Applications/ServBay/backup/dump.rdb /Applications/ServBay/db/redis/dump.rdb
# Start the Redis service in ServBay
2
3
4
5
/Applications/ServBay/backup/dump.rdb
: Path to your backup file./Applications/ServBay/db/redis/dump.rdb
: Default Redis persistence file path.
Migrating Databases
Database migration involves moving your database from one environment (such as another ServBay instance, a remote server, or another local setup) to another. This typically means exporting your data from the source environment and importing it into the destination environment.
Migrating MySQL
How to migrate MySQL is a common scenario in daily development.
Export the database from the source environment:
bash# Run in the terminal of the source environment mysqldump -u your_source_username -p your_database > your_database.sql
1
2your_source_username
: Source environment’s database username.your_database
: Name of the database to be migrated.your_database.sql
: Filename for the exported SQL file.
Transfer the exported SQL file to the target environment: Use
scp
or any file transfer tool to copyyour_database.sql
to an accessible location in the target ServBay instance (e.g.,/Applications/ServBay/backup/
).Create the database on the target ServBay environment:
bash# Run in the target ServBay terminal mysql -u your_target_username -p -e "CREATE DATABASE your_database;"
1
2your_target_username
: Database username for the target ServBay environment.your_database
: Name of the database to create (should match the source database name).
Import the database into the target ServBay environment:
bash# Run in the target ServBay terminal mysql -u your_target_username -p your_database < /path/to/your_database.sql
1
2/path/to/your_database.sql
: Path to the SQL file in the target environment.
Migrating MariaDB
How to migrate MariaDB is identical to MySQL because both use the same command-line tools and file formats.
- Export the database from the source environment:bash
# Run in the terminal of the source environment mysqldump -u your_source_username -p your_database > your_database.sql
1
2 - Transfer the SQL file to the target environment.
- Create the database on the target ServBay environment:bash
# Run in the target ServBay terminal mysql -u your_target_username -p -e "CREATE DATABASE your_database;"
1
2 - Import the database into the target ServBay environment:bash
# Run in the target ServBay terminal mysql -u your_target_username -p your_database < /path/to/your_database.sql
1
2
Migrating PostgreSQL
How to migrate PostgreSQL uses the pg_dump
and pg_restore
tools. Again, be mindful of the socket file path in ServBay.
Export the database from the source environment:
bash# Run in the terminal of the source environment # If the source is ServBay pg_dump -h /Applications/ServBay/tmp -U your_source_username -d your_database -F c -b -v -f your_database.dump # If the source is another system, adjust connection parameters accordingly
1
2
3
4your_source_username
: Database username in the source environment.your_database
: Database name to migrate.your_database.dump
: Name for the exported backup file.
Transfer the backup file to the target ServBay environment: Use
scp
or another tool to moveyour_database.dump
to the destination.Create the database on the target ServBay environment:
bash# Run in the target ServBay terminal # Connect to the default postgres database to create a new database psql -h /Applications/ServBay/tmp -U your_target_username -d postgres -c "CREATE DATABASE your_database;"
1
2
3your_target_username
: Database username in the target environment.your_database
: Name of the database to create.
Import the database into the target ServBay environment:
bash# Run in the target ServBay terminal pg_restore -h /Applications/ServBay/tmp -U your_target_username -d your_database -v /path/to/your_database.dump
1
2/path/to/your_database.dump
: Path to your backup file in the target environment.
Migrating Redis
Redis migration is generally done by simply copying the dump.rdb
file.
Retrieve the
dump.rdb
file from the source environment:bash# Run in the terminal of the source environment # Ensure Redis is stopped, or wait for BGSAVE to complete cp /path/to/source/redis/dump.rdb ./dump.rdb
1
2
3Transfer the
dump.rdb
file to the Redis data directory in the target ServBay environment:bash# Run in the source environment or a proxy server scp ./dump.rdb your_target_server:/Applications/ServBay/db/redis/dump.rdb
1
2your_target_server
: The address or hostname of the destination ServBay server.- Important: Before copying to
/Applications/ServBay/db/redis/
on the target ServBay, ensure the Redis service is stopped.
Start the Redis service in the target ServBay environment: When Redis starts, it will automatically load the new
dump.rdb
file.
Important Notes
- Stop Services: Always stop the relevant database service via the ServBay GUI or command-line tools before directly copying or moving any database files (especially MySQL/MariaDB/PostgreSQL data directories). Copying files from a running database can cause inconsistency or corruption. Redis must also be stopped before recovery with
dump.rdb
. - Permissions: Ensure that you have the appropriate permissions to read, write, and modify relevant directories and files during file copy, move, or import operations.
- File Paths: Double-check both the ServBay installation path (default is
/Applications/ServBay
) and the specific database file paths, especially for different versions. - Users & Permissions: After migration, review your database users, permissions, and configuration files to ensure compatibility with the new environment.
- ServBay Built-in Backup: ServBay also offers convenient built-in backup and restore features via the GUI, supporting backups of settings, website files, databases, and SSL certificates. These can serve as a supplement or alternative to manual file management.
Summary
ServBay’s standardized file structure provides a clear foundation for developers to manage database files efficiently. This guide details the storage locations for MySQL, MariaDB, PostgreSQL, and Redis database files within ServBay, and offers practical instructions for backup, restoration, and migration using standard command-line tools. Mastering these skills will help you better manage your local development databases, keep your data secure, and migrate projects seamlessly between environments. Coupled with ServBay’s built-in convenience features (like automated backups), these practices significantly boost your development efficiency and data management capabilities.