ServBay Database File Management & Migration Guide
ServBay is a powerful local web development environment that integrates several widely used database management systems and manages their data files in a standardized way. Understanding ServBay’s default database file structure is crucial for developers who need to back up, restore, or migrate their data.
This guide provides detailed information about ServBay’s default database file storage, plus instructions for managing files and migrating databases between environments using standard command-line tools.
TIP
ServBay offers automated and manual backup and restore functionality for MySQL, MariaDB, and PostgreSQL databases. See Backup & Restore for more details.
ServBay Default Database File Structure
To simplify management and isolate data between database versions, ServBay stores all database data files in the /Applications/ServBay/db
directory. This location is organized by database type, then by major version number within each type’s folder.
Here’s a typical 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Description of the Directory Structure
/Applications/ServBay/db
: The main directory for all database files managed by ServBay.mysql
: Stores MySQL database data files, organized into subfolders by major version (e.g.,8.0
,8.1
).mariadb
: Contains MariaDB data files, with subfolders divided by major version (e.g.,10.11
,11.3
).postgresql
: Houses PostgreSQL data files in version-specific folders (e.g.,15
,16
).redis
: Stores Redis persistent files, typically nameddump.rdb
.
This structure allows you to install and run multiple major versions of the same database within ServBay, with complete separation and no data interference between them.
Database File Management
During local development, it’s common to back up, restore, or migrate database data. Below are methods for these tasks using standard command-line utilities. Make sure to use the ServBay-provided terminal environment or properly set up your environment variables so you can access the necessary database clients and tools.
Database Backup
Regular backups are essential for data safety. Here’s how to back up different database types in ServBay:
Backing Up MySQL
The standard tool for backing up MySQL databases is mysqldump
.
bash
# Switch to the ServBay terminal environment, or make sure your PATH environment variable includes ServBay’s bin directory
# Example: export PATH="/Applications/ServBay/bin:$PATH"
mysqldump -u your_username -p your_database > /Applications/ServBay/backup/your_database.sql
1
2
3
4
2
3
4
your_username
: Substitute your MySQL username.your_database
: Replace with the name of the database to back up./Applications/ServBay/backup/your_database.sql
: Path and filename for your backup. It’s recommended to store backups outside of the ServBay folder, such as within your user directory.
Backing Up MariaDB
MariaDB is backed up the same way as MySQL, using mysqldump
:
bash
# Switch to the ServBay terminal environment, or ensure PATH includes ServBay’s bin directory
mysqldump -u your_username -p your_database > /Applications/ServBay/backup/your_database.sql
1
2
3
2
3
- Arguments are as described above.
Backing Up PostgreSQL
Use pg_dump
to back up PostgreSQL databases. In ServBay, PostgreSQL typically connects via Unix Domain Socket at /Applications/ServBay/tmp
, so include -h /Applications/ServBay/tmp
in your command.
bash
# Switch to the ServBay terminal environment, or ensure 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
1
2
3
2
3
- Connection parameters: How PostgreSQL connects to the server.
- macOS:
-h /Applications/ServBay/tmp
(Unix Domain Socket path) - Windows:
-h localhost -p 5432
(TCP connection)
- macOS:
-U your_username
: Replace with your PostgreSQL username.-d your_database
: Name of the database to back up.-F c
: Output in custom archive format (recommended).-b
: Includes large objects (blobs).-v
: Verbose output.-f /Applications/ServBay/backup/your_database.dump
: Where to save your backup file.
Backing Up Redis
Redis backup typically means copying its dump.rdb
persistent file.
bash
# Switch to the ServBay terminal environment
# Make sure Redis server is running, or auto-save (BGSAVE) is configured
cp /Applications/ServBay/db/redis/dump.rdb /Applications/ServBay/backup/dump.rdb
1
2
3
4
2
3
4
/Applications/ServBay/db/redis/dump.rdb
: Default Redis persistence file path./Applications/ServBay/backup/dump.rdb
: Path/filename where you want the backup saved.
Restoring Databases
When data is lost or you need to revert to a previous state, restore using your backup files.
Restoring MySQL
Use the mysql
client to restore MySQL backups.
bash
# Switch to the ServBay terminal environment
mysql -u your_username -p your_database < /Applications/ServBay/backup/your_database.sql
1
2
3
2
3
your_username
: Replace with your MySQL username.your_database
: Name of the database to restore to (must exist before restoration)./Applications/ServBay/backup/your_database.sql
: Path to your backup file.
Restoring MariaDB
Same steps as for MySQL, using the mysql
client utility:
bash
# Switch to the ServBay terminal environment
mysql -u your_username -p your_database < /Applications/ServBay/backup/your_database.sql
1
2
3
2
3
- Arguments as explained above.
Restoring PostgreSQL
Restore PostgreSQL custom-format backups with pg_restore
. Specify the socket path as before.
bash
# Switch to the ServBay terminal environment
pg_restore -h /Applications/ServBay/tmp -U your_username -d your_database -v /Applications/ServBay/backup/your_database.dump
1
2
3
2
3
- Connection parameters:
- macOS:
-h /Applications/ServBay/tmp
(Unix Domain Socket path) - Windows:
-h localhost -p 5432
(TCP connection)
- macOS:
-U your_username
: PostgreSQL username for restoration.-d your_database
: Database you’re restoring to (must be created beforehand).-v
: Verbose output.- Backup file path:
- macOS:
/Applications/ServBay/backup/your_database.dump
- Windows:
C:\ServBay\backup\your_database.dump
- macOS:
Restoring Redis
To restore Redis, copy the backup dump.rdb
file back to the Redis data directory. Important: Stop Redis before doing this.
bash
# Switch to the ServBay terminal environment
# 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
1
2
3
4
5
2
3
4
5
/Applications/ServBay/backup/dump.rdb
: Your backup file path./Applications/ServBay/db/redis/dump.rdb
: Redis default persistence file location.
Database Migration
Database migration refers to transferring databases from one environment (another ServBay instance, remote server, or other local setup) to another. This typically involves exporting data from the source, then importing it in the target environment.
Migrating MySQL
Migrating MySQL is a common scenario in day-to-day development.
Export the database from the source environment:
bash# Run in the source terminal environment mysqldump -u your_source_username -p your_database > your_database.sql
1
2your_source_username
: Username in the source database.your_database
: The database to migrate.your_database.sql
: Exported SQL file name.
Transfer the exported SQL file to the destination environment: Use
scp
or any file transfer tool to moveyour_database.sql
to an accessible location in the target ServBay environment (e.g.,/Applications/ServBay/backup/
).Create the database in 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
: Username for ServBay’s target environment.your_database
: Name for the database (should match the source).
Import the database into ServBay:
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
: Actual path of the SQL file in the target system.
Migrating MariaDB
Migrating MariaDB is identical to MySQL since both use the same command-line tools and file formats.
- Export the database from the source environment:bash
# Run in the source terminal mysqldump -u your_source_username -p your_database > your_database.sql
1
2 - Transfer the SQL file to the target environment.
- Create the database in ServBay:bash
# Run in the ServBay terminal mysql -u your_target_username -p -e "CREATE DATABASE your_database;"
1
2 - Import into the ServBay database:bash
# Run in the ServBay terminal mysql -u your_target_username -p your_database < /path/to/your_database.sql
1
2
Migrating PostgreSQL
Migrating PostgreSQL uses pg_dump
and pg_restore
. Always pay attention to the socket file path with ServBay.
Export the database in the source environment:
bash# Run in the source terminal # If source is ServBay pg_dump -h /Applications/ServBay/tmp -U your_source_username -d your_database -F c -b -v -f your_database.dump # For other systems, modify connection parameters accordingly
1
2
3
4your_source_username
: Username in the source PostgreSQL database.your_database
: The database to migrate.your_database.dump
: Backup file name.
Transfer the backup file to the destination ServBay environment: Use
scp
or other file transfer tools to copyyour_database.dump
into ServBay.Create the database in ServBay:
bash# Use the ServBay terminal # Connect to the default postgres database to create a new one psql -h /Applications/ServBay/tmp -U your_target_username -d postgres -c "CREATE DATABASE your_database;"
1
2
3your_target_username
: Username in the ServBay target environment.your_database
: Name for the new database.
Import into the target ServBay database:
bash# Run in the 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
: Actual backup file location in ServBay.
Migrating Redis
Redis migration generally means copying the dump.rdb
file.
Export the
dump.rdb
file in the source environment:bash# Run in the source terminal # Make sure Redis is stopped or wait for BGSAVE to finish cp /path/to/source/redis/dump.rdb ./dump.rdb
1
2
3Transfer
dump.rdb
to the Redis data directory of the target ServBay environment:bash# On the source or intermediary server scp ./dump.rdb your_target_server:/Applications/ServBay/db/redis/dump.rdb
1
2your_target_server
: Address or hostname of the ServBay target server.- Important: Stop Redis in ServBay before copying to
/Applications/ServBay/db/redis/
.
Start Redis service in ServBay: On startup, Redis will automatically load the new
dump.rdb
file.
Important Notes
- Stop Services: Before directly copying or moving database files (especially data directories of MySQL/MariaDB/PostgreSQL), always stop the respective database service via ServBay’s GUI or command-line tool. Copying open database files can result in inconsistency or corruption. Redis must also be stopped before recovering using
dump.rdb
. - Permissions: Ensure the user performing copy, move, or import operations has sufficient privileges to access and modify the necessary folders and files.
- File Paths: Double-check ServBay’s installation path (default
/Applications/ServBay
) and the specific paths for database files, especially subfolders for different database versions. - Users & Permissions: After migration, review and update database users, permissions, and configuration files as needed for the new environment.
- Built-in Backup: ServBay also offers convenient backup and restore features via its GUI, letting you back up settings, site files, databases, and SSL certificates. This can supplement or replace manual file management methods.
Conclusion
With its standardized file structure, ServBay gives developers a clear foundation for managing database files. This guide explains the file locations for MySQL, MariaDB, PostgreSQL, and Redis within ServBay, and provides practical backup, restore, and migration instructions using standard command-line tools. Mastering these techniques helps you manage your local databases securely and efficiently migrate projects between environments. Combined with ServBay’s additional features—like built-in backup—these skills will significantly boost your development productivity and data management capabilities.