Syncing a TYPO3 Database and Uploads with DDEV
When I work on an existing TYPO3 website, I want my local copy to be as close as possible to what editors are working with on the live site. That’s especially helpful for TYPO3 upgrades and visual regression tests with Playwright, when I need the current content from the database as well as the files that go with it.
Over the years I’ve tried several ways of doing this, and for the most part they worked well for me. There were still a few things I wanted to improve, so I came back to the problem to see whether I could make the process fit better into my day-to-day workflow.
How I used to pull databases and files
In some projects, I still use a cron job to make a database dump overnight and serve it from a backup URL protected with a password via .htaccess. Whenever I need a fresh copy of the database, I download the dump and import it locally.
The fetchdatabase.sh script that Wolfgang Wagner uses in his training courses makes this a little easier. It uses the stored credentials to create a database dump on the server when it’s needed, then takes care of downloading and importing it locally.
What always bothered me a little was having to store the database credentials separately in the script, especially as I’ve started working more with AI agents that can access files in my projects.
I considered moving the credentials to a separate my.cnf on the server. That would take them out of the script, but I’d still have to maintain a second copy alongside the TYPO3 configuration. TYPO3 already has all the information I need for the export, so it made sense to use that directly.
For files, I’ve used the filefill extension in some projects. I still like the idea of fetching missing files from the server only when they’re needed. Development on the extension seems to have slowed, though, and I’ve run into different issues with it depending on the project.
In practice, I usually ended up putting together my own rsync command whenever I needed to bring the files back in sync.
From a custom script to a DDEV provider
I now run all my TYPO3 projects locally with DDEV, so it made sense to use it to sync the database and files as well. DDEV already has a command for this with ddev pull.
Providers define where the data comes from and how to retrieve it. You can also write your own provider as a YAML file under .ddev/providers/.
The idea came from Christoph Schwob, who wrote about importing a staging database through a custom DDEV provider. Thanks again for sharing that, Christoph!
Christoph Schwob’s post on importing a staging database with DDEV (in German)
I first tried writing my own provider in December 2024. I hit problems in a few projects and eventually ran out of time to resolve them. As often happens in day-to-day development, I put it aside for a while.
I picked it up again now that AI gives me more options when I’m developing. This time I wanted something I could use across projects with as little extra configuration as possible.
What I like about making it a DDEV provider is that I can use features DDEV already has. The existing ddev pull options let me choose whether I need the database, the files, or both.
Packaging the provider as a DDEV add-on also means I can develop it in one place and update it across my projects as needed.
The result is TYPO3 Deployer Pull. Once a project is set up, I can pull everything with this command.
What happens during a pull
That one command handles several steps I used to do partly by hand.
- Export the database on the server, skipping tables I don’t need locally, such as cache and session tables
- Validate the SQL dump and import it into the local DDEV environment
- Bring the database schema into line with the local code (
database:updateschema safe) - Flush the local TYPO3 caches
- Sync the upload directories with rsync
For the export, I use Helmut Hummel’s TYPO3 Console. Its database:export command reads the database configuration straight from TYPO3 on the server. That saves me from maintaining another copy of the database credentials or setting up a protected backup URL.
TYPO3 Console also handles the local schema update. Some tables are deliberately excluded from the export and have to be recreated after the import. I need those tables for the local installation, even though I can do without their contents.
My local code may also differ from what’s deployed on the server. If I’ve installed a new extension or defined an extra database column locally, the schema update adds what’s needed right after the import.
In many cases, I can get straight back to where I left off after running the pull.
Requirements and conventions
To keep setup to a minimum, I followed the principle of convention over configuration. A few conventions shared across projects let the add-on find the information it needs without asking you to specify it again.
Here’s what the add-on expects.
- The project uses Composer and DDEV 1.25.0 or later with the
typo3project type. - The project is deployed with Deployer. A local installation is optional. In my projects, Deployer runs entirely in CI.
- The Deployer host definitions are in a
.hosts.ymlfile in the project root. - The DDEV project name matches the SSH alias in the local
~/.ssh/config. - For database pulls, TYPO3 Console version 8 or 9 is available both locally and on the server.
- Bash, SSH and rsync are available on the local machine. The server also needs rsync and, for database pulls, a compatible MySQL or MariaDB dump utility.
My own website, eric-harrer.de, is a good example of how this fits together. It runs on Mittwald’s classic hosting platform. I’ve anonymized the configuration examples below.
Sharing the host configuration between Deployer and DDEV
I keep the host definitions for my Deployer projects in a separate .hosts.yml in the project root. Here’s what that file looks like for my site, with the identifying details replaced.
hosts:
production:
hostname: p123456.webspaceconfig.de
remote_user: p123456
port: 22
deploy_path: /home/www/p123456/html/eric-harrer.de/production
bin/php: '/usr/local/bin/php -d memory_limit=512M'
In deploy.php, I load that file with a single import.
Deployer and the add-on can then use the same host information, even if Deployer is only installed in CI.
If bin/php specifies a PHP binary and CLI arguments, the add-on uses those as well. In this example, I use that setting to give PHP a memory limit of 512 MB.
Keeping the hosts in a separate .hosts.yml is a convention I chose for the add-on. That lets me reuse the same host configuration for both jobs, while Deployer can still define hosts in other ways.
DDEV project name and SSH alias
As I’ve been using Git worktrees more often, I’ve stopped setting name explicitly in .ddev/config.yaml across my DDEV projects.
If you’re new to worktrees, they let you keep several working directories for the same Git repository. You can, for example, work on different branches side by side without constantly switching between them.
When you omit name, DDEV uses the project directory’s name as the project name. That lets me run several worktrees side by side as separate DDEV instances, as described in this post.
DDEV Project Names and Directories
I’ve named my SSH aliases after my project directories for quite a while. That gives the add-on another convention for free. In my case, the directory name, the DDEV project name and the SSH alias are all eric-harrer.de.
Here’s what the corresponding entry in my local ~/.ssh/config looks like.
Host eric-harrer.de
HostName p123456.webspaceconfig.de
User p123456
Port 22
IdentityFile ~/.ssh/eric-harrer-de
IdentitiesOnly yes
When I connect to my server with ssh eric-harrer.de, I’m using the same SSH setup as the provider.
A DDEV provider can run its commands inside a container or directly on the machine running DDEV.
Jochen Roth describes another approach on the b13 blog in How to fetch a customer’s TYPO3 data with a DDEV custom provider. That recipe runs SSH and rsync inside the DDEV web container. It makes the local SSH keys available to the container with ddev auth ssh and runs mysqldump directly using credentials from the server’s .env file.
I chose to run the SSH and rsync commands on my own machine. That lets the provider use my existing SSH configuration, including keys and any other connection settings, and saves me from running ddev auth ssh.
If I want to run the pull directly from a worktree with a different directory name, I just need an SSH alias to match it.
Which upload directories are synced
DDEV already has a setting for the directories I want to pull from the server. It’s called upload_dirs and lives in .ddev/config.yaml. For TYPO3, the default looks like this.
These paths are relative to the document root configured in DDEV. Mine is public, so the provider syncs public/fileadmin.
If you haven’t used this setting before, DDEV also uses it for ddev import-files and with Mutagen.
Mutagen speeds up file access within Docker, especially on macOS and Windows. It does that by keeping a synchronized copy of the project files inside the Docker environment.
When Mutagen is enabled, the directories listed in upload_dirs are left out of that local synchronization. The container reads the files on my machine directly through a bind mount. For a large fileadmin directory, that saves both the work of synchronizing it locally and the disk space needed for another copy inside Docker.
That makes upload_dirs a good fit for deciding what to sync with the server as well.
If an older TYPO3 project still needs the uploads directory, I can simply add it under upload_dirs. I can do the same for any project-specific upload directories.
The server sync skips directories such as _processed_ and _temp_. It also skips node_modules, since some projects list it under DDEV’s upload_dirs for performance and I want to use the dependencies installed locally.
If a project already follows these conventions, I can use the add-on with the configuration it already has.
Installation and usage
I install the add-on as usual from the root of the DDEV project.
It’s ready to use after installation. I can skip the ddev restart that DDEV suggests.
Important. A pull replaces the local database and the contents of the configured upload directories with the versions from the server. It may also delete files that exist only locally. Back up your local data first if you still need it. The import carries over any personal data in its original form.
If I want both the database and the files, I use the same command without any extra options. It pulls from the Deployer host production by default.
If I’m about to upgrade TYPO3, for example, and only need a recent copy of the database, I can skip file synchronization.
Sometimes I just want to bring the files up to date and keep the local database I’m working with.
Many of my projects have a staging environment as well as the live site. If staging is reachable through the same SSH connection, I can specify the Deployer host when I run the pull.
Example of a full pull
The easiest way to see how the steps fit together is to look at the console output from a full pull of my site. I’ve anonymized the connection details here as well.
$ ddev pull typo3-deployer
You're about to delete the current database and files and replace with the results of a fresh pull.
Would you like to continue? [Y/n] (yes):
Authenticating...
TYPO3 Deployer Pull
Project / SSH alias: eric-harrer.de
Environment: production
SSH target: p123456@p123456.webspaceconfig.de (port 22)
Remote release: /home/www/p123456/html/eric-harrer.de/production/current
[OK] Local preflight checks passed
Obtaining databases...
Database export
[..] Exporting remote database (production) ...
[OK] Remote database exported and SQL dump validated (2 s)
SQL dump size: 2 MiB (rounded down)
Importing databases [/Users/example/docker/eric-harrer.de/.ddev/.downloads/db.sql]
Importing database via custom db_import_command
Database import
[..] Checking local TYPO3 CLI for schema updates ...
[OK] Required local TYPO3 CLI command available
[..] Replacing the local database ...
Not creating CMS settings files because disable_settings_management=true or project type doesn't require settings
Successfully imported database 'db' for eric-harrer.de
[OK] Local database imported (4 s)
[..] Updating the local database schema (add/change operations) ...
The following database schema updates were performed:
+------------+---------+
| Type | Updates |
+------------+---------+
| Add tables | 21 |
+------------+---------+
[OK] Database schema updated (3 s)
[..] Flushing local TYPO3 caches ...
[OK] TYPO3 caches flushed (5 s)
Obtaining files...
Importing files...
Importing files via custom files_import_command...
File synchronization
[..] Checking remote upload directories ...
[OK] Remote upload directories verified (1 s)
[..] Synchronizing public/fileadmin ...
[OK] Synchronized public/fileadmin (1 s)
Pull succeeded.
In this example, the schema update recreated 21 tables after the import. Looking at the schema for my site, that matches the tables deliberately excluded from the export. These are 16 cache tables (including their associated tag tables), two session tables and the sys_log, sys_http_report and sys_file_processedfile tables.
The last table holds information about files generated by TYPO3, such as images prepared for display on the site. Since I leave the files in the _processed_ directories on the server, I don’t need to pull their database entries either. TYPO3 can regenerate both locally when it needs them.
Of the 72 tables in my installation, I only need to pull 51 from the server. The subsequent schema update recreates the other 21 as empty tables.
The file sync was fairly quick in this example too. One advantage of rsync is that on subsequent runs, it can skip files that are already present and unchanged. Once I’ve pulled all the files for the first time, later runs mostly come down to checking what has changed and transferring those changes.
What I’ve tested so far and what’s next
I’ve now used the add-on successfully on macOS in six different TYPO3 client projects. They already follow the conventions described here, so I could use the provider straight after installation in each of them.
I’ve yet to test it myself on Windows and Linux. On Windows, rsync may take an extra step to set up, depending on whether it’s already available in your environment (Git Bash or WSL).
For me, the add-on is one of those small tools that saves a few steps over and over. Whenever I need a fresh copy of a website, I can now get it with the same command across projects.
Some of these conventions may fit the way other TYPO3 developers already set up their projects. If you’d like to try the add-on, the source code, more detailed setup instructions and troubleshooting notes are on GitHub.
I’d be glad to hear any suggestions or how it worked for you, especially if you use Windows or Linux.
