Feature Request: Download latest acquia backup instead of dumping it ourselves
Provide ability to use existing Acquia backups
When doing a ddev pull acquia an on-demand data dump is initiated, which can take a very long time. In most instances, using the backup databases that may have been created by Acquia would be sufficient. In my case, this saves an hour and a quarter.
Existing backup downloaded by default with option for on-demand dump Here is the output from a Lando pull:
lando pull ─╯
? Pull code from? none
? Pull database from? Stage, test (vcs: sprint4.18-certificate-functionality)
? Pull files from? none
--
Saved credentials to /var/www/.acquia/cloud_api.conf
✔ Destroying all current tables in local database if needed...
! [NOTE] This is a multisite application. Drupal will load the default site unless you've configured sites.php for this
! environment: https://docs.acquia.com/cloud-platform/develop/drupal/multisite/
[INFO] Using a database backup that is 11 hours old. Backup #189250915 was created at Sun Oct 24 6:48:35 UTC 2021.
You can view your backups here:
https://cloud.acquia.com/a/environments/12594-15786fc5-f286-4275-abf8-af232cce1823/databases
To generate a new backup, re-run this command with the --on-demand option.
✔ Importing Drupal database download
}
✔ Checking db pull for expected tables...
✔ Pull completed successfully!
This is a good idea (and Pantheon integration used to do it)
Since pull support is just a little shell script you could easily do this - After the download of the database, move it to a different storage place, and when pulling, check for the downloaded database before pulling.
And of course... you can just do a ddev snapshot after downloading, or ddev export-db and use that for future downloads if you don't need a fresh database.
Once again, I probably didn't explain it clearly enough - that backup database that Lando is using is one that was stored on Acquia which was produced by a daily cron run. By default lando pull does not do a drush sql-dump unless you add the --on-demand option to it.
Having never used Lando on this project until the other day, doing a lando pull took 15 minutes to download that existing gzipped tarball from Acquia and import it. When doing a ddev pull for the first time, it takes 1hr and 37minutes.
I see that I can grab that zipped database dump and then do a ddev import-db. That will work.
I suppose my boss will simply remain smug that he chose Lando, as they can do that pull with a single command from the command line.
I didn't spot anything in acli that pulls the database backup down from Acquia, so I'll see if I can figure out how Lando does it.
Ah, you're talking about using a pre-existing backup on the Acquia side. It's a good idea, and probably easier than what is currently done. But I imagine acli has a technique for it, poke around... It's just a matter of experimenting with the technique and then implanting it into the script.
If the backup is on the filesystem on the Acquia side, then it shouldn't be hard to get it, and it would be a good technique. See if you can figure out where it gets stored. I also don't see an option in acli to pull a backup.
It's hidden away but in there!
acli api:environments:database-backup-list eeamoreno.dev eeamoreno
acli api:environments:database-backup-download eeamoreno.dev eeamoreno 164897342
Then you have to download the provided url, which is a gzipped db dump
The acquia integration in soon-to-be-released release v1.18.1 downloads a gzipped database, which may fix the concerns you have, I'd appreciate it if you could try it out. It may solve the slowness issue. It still requires a dump on the server side, but the contents are brought down as a gzipped file.
@siliconmeadow could you please take a look at the acquia.yaml.example in ddev v1.18.1 and give it a try and see if it resolves your download issue?
Still hope you'll give that a try @siliconmeadow
Hi @rfay - am I right in thinking that the magic is:
drush @${project_id} sql-dump -n --alias-path=~/.drush --extra-dump=--no-tablespaces --gzip >db.sql.gz
If so, I've been successful with that in the past. I needed to change the --extra-dump to simply --extra when using Drush 8, but that's a different matter and I was considering how to handle different versions of Drush more gracefully.
Rather than doing this, what will perform better is if we download the latest db backup, as you'd saw was possible with acli, instead of creating an "on demand" one. I picked apart the Lando Acquia plugin to see what they were doing with their use of acli. Instead of the drush sql-dump command above, I've swapped it with:
acli -n pull:db @${project_id}
Which gets closer, but it seems like acli makes assumptions about the local environment and I can't see where to change that. In short, I don't see where they've specified --host localhost --user drupal drupal. Here is the verbose transcript when running acli -n pull:db my_acquia_project.dev directly in the web container:
ddev exec acli -n -vvv pull:db rcnimain.dev ─╯
Box Requirements Checker
========================
> Using PHP 7.4.26
> PHP is using the following php.ini file:
/etc/php/7.4/cli/php.ini
> Checking Box requirements:
✔ The application requires the version "^7.3 | ^8.0" or greater.
✔ The application requires the extension "json".
✔ The package "brick/math" requires the extension "json".
✔ The package "guzzlehttp/guzzle" requires the extension "json".
✔ The package "ramsey/uuid" requires the extension "json".
✔ The package "zumba/amplitude-php" requires the extension "curl".
[OK] Your system is ready to run the application.
Acquia CLI version: 1.19.0
Connecting to database drupal
[notice] Command: 'which' 'mysql' [Exit: 0]
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
[notice] Command: 'mysql' '--host' 'localhost' '--user' 'drupal' 'drupal' [Exit: 1]
In PullCommandBase.php line 371:
[Acquia\Cli\Exception\AcquiaCliException]
Unable to connect to local database using credentials mysql:://drupal:drupal@localhost/drupal. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
Exception trace:
at phar:///usr/local/bin/acli/src/Command/Pull/PullCommandBase.php:371
Acquia\Cli\Command\Pull\PullCommandBase->connectToLocalDatabase() at phar:///usr/local/bin/acli/src/Command/Pull/PullCommandBase.php:129
Acquia\Cli\Command\Pull\PullCommandBase->pullDatabase() at phar:///usr/local/bin/acli/src/Command/Pull/PullDatabaseCommand.php:52
Acquia\Cli\Command\Pull\PullDatabaseCommand->execute() at phar:///usr/local/bin/acli/vendor/symfony/console/Command/Command.php:298
Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/acli/src/Command/CommandBase.php:428
Acquia\Cli\Command\CommandBase->run() at phar:///usr/local/bin/acli/vendor/symfony/console/Application.php:1023
Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/acli/vendor/symfony/console/Application.php:299
Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/acli/vendor/symfony/console/Application.php:171
Symfony\Component\Console\Application->run() at phar:///usr/local/bin/acli/bin/acli:69
require() at /usr/local/bin/acli:14
pull:database [--no-scripts] [--on-demand] [--no-import] [--multiple-dbs] [--] [<environmentId> [<site>]]
[help] You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/
You can submit a support ticket at https://insight.acquia.com/support/tickets/new?product=p:cli
Failed to execute command acli -n -vvv pull:db rcnimain.dev: exit status 1
On an aside, the web container has version 1.14.x of acli. I'll look at your image build scripts to see how to get a newer version can be installed.
I was asking you to take a look at the Acquia example as it is and try it out for speed. Could you give it a shot? https://github.com/drud/ddev/blob/master/pkg/ddevapp/dotddev_assets/providers/acquia.yaml.example
I see you tested with acli v1.19, which had major behavior change with aliases download, which is why it's pinned at v1.14.
But I'd love to have you test it as is and compare the speed to what you were after. It's currently set up to pull a gzipped dump.
I'm wide open to improvements, and I saw that acli in a recent version had its own pull that might have some potential.
I tested exactly that feature for speed already.
If so, I've been successful with that in the past. I needed to change the --extra-dump to simply --extra when using Drush 8, but that's a different matter and I was considering how to handle different versions of Drush more gracefully.
The purpose of this request was to circumvent running drush sql-dump on the Acquia server, as that's where the bottleneck is regardless. On our installation, this line https://github.com/drud/ddev/blame/master/pkg/ddevapp/dotddev_assets/providers/acquia.yaml.example#L45 takes about an hour to run.
And I've been using that since a day or two after @greggmarshall's commit was merged in
Right, but I don't think you did since the recent revamp of the acquia.yaml.example, where it started to transfer gzipped versions of everything. Your feature request predated that change. The question is whether your feature request is still relevant given the changes.
Right, but I don't think you did since the recent revamp of the acquia.yaml.example, where it started to transfer gzipped versions of everything. Your feature request predated that change. The question is whether your feature request is still relevant given the changes.
I did after the revamp of the file. Before 1.18.x was added. Within the same week of @greggmarshall's mod was added, I tried it out. I'm sorry I didn't mention it.
The way I see it is that the pull of the DB is actually not the most descriptive of names as it does pull the DB but also imports it.
The importing of the DB is fast. Doing a drush sql-dump is not near as fast as simply downloaded an already created gzipped file done from last night's backup. Which is what exec acli pull:db -n my_acquia_proj.dev does. It's far more energy efficient.
Looking forward to an improvement. With ddev v1.18.2, it's no longer required to let ddev import the database, acli can do it or whatever. See https://ddev.readthedocs.io/en/latest/users/providers/provider-introduction/
Another benefit of using the Acquia backups would be to reduce the load on the production server, assuming that's the DB being pulled. If you have a half dozen developers, each doing the appropriate thing of starting each feature with a fresh copy of the DB, you could be doing a half dozen pulls a day. My last project was concerned about it enough that we used a spare environment (they had a bunch) and had a weekly cron job update it from production then the developers pulled from there.
I'm not quite sure how to extract the name or id of the latest backup. I saw the ACLI commands above but not sure how you go from the output of the first to the second in a script.
I'm checking to see how I can specify a different host, username, pw and database with acli pull:db as it's defaulting to
[notice] Command: 'mysql' '--host' 'localhost' '--user' 'drupal' 'drupal' [Exit: 1]
I felt like I was making progress and thought my increased activity on this issue above was going in the right direction! Not so certain now.
Another benefit of using the Acquia backups would be to reduce the load on the production server, assuming that's the DB being pulled. If you have a half dozen developers, each doing the appropriate thing of starting each feature with a fresh copy of the DB, you could be doing a half dozen pulls a day. My last project was concerned about it enough that we used a spare environment (they had a bunch) and had a weekly cron job update it from production then the developers pulled from there.
Precisely! This is the whole reason I raised this damned ticket in the first place!
I'm not quite sure how to extract the name or id of the latest backup. I saw the ACLI commands above but not sure how you go from the output of the first to the second in a script.
I've swapped out line 45 in my acquia.yaml file with this:
acli pull:db -n -vvv @${project_id}
And get the following output:
ddev pull acquia --skip-files ─╯
You're about to delete the current database and replace with the results of a fresh pull.
Would you like to continue? [Y/n] (yes):
Authenticating...
Saved credentials to /home/sheppardr/.acquia/cloud_api.conf
Obtaining database...
Box Requirements Checker
========================
> Using PHP 7.4.26
> PHP is using the following php.ini file:
/etc/php/7.4/cli/php.ini
> Checking Box requirements:
✔ The application requires the version "^7.3 | ^8.0" or greater.
✔ The application requires the extension "json".
✔ The package "brick/math" requires the extension "json".
✔ The package "guzzlehttp/guzzle" requires the extension "json".
✔ The package "ramsey/uuid" requires the extension "json".
✔ The package "zumba/amplitude-php" requires the extension "curl".
[OK] Your system is ready to run the application.
Acquia CLI version: 1.14.0
Connecting to database drupal
[notice] Command: 'which' 'mysql' [Exit: 0]
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
[notice] Command: 'mysql' '--host' 'localhost' '--user' 'drupal' 'drupal' [Exit: 1]
In PullCommandBase.php line 407:
[Acquia\Cli\Exception\AcquiaCliException]
Unable to connect to local database. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
Exception trace:
at phar:///usr/local/bin/acli/src/Command/Pull/PullCommandBase.php:407
Acquia\Cli\Command\Pull\PullCommandBase->connectToLocalDatabase() at phar:///usr/local/bin/acli/src/Command/Pull/PullCommandBase.php:133
Acquia\Cli\Command\Pull\PullCommandBase->pullDatabase() at phar:///usr/local/bin/acli/src/Command/Pull/PullDatabaseCommand.php:50
Acquia\Cli\Command\Pull\PullDatabaseCommand->execute() at phar:///usr/local/bin/acli/vendor/symfony/console/Command/Command.php:299
Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/acli/src/Command/CommandBase.php:414
Acquia\Cli\Command\CommandBase->run() at phar:///usr/local/bin/acli/vendor/symfony/console/Application.php:996
Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/acli/vendor/symfony/console/Application.php:295
Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/acli/vendor/symfony/console/Application.php:167
Symfony\Component\Console\Application->run() at phar:///usr/local/bin/acli/bin/acli:89
require() at /usr/local/bin/acli:14
pull:database [--no-scripts] [--on-demand] [--no-import] [--] [<environmentId> [<site>]]
[help] You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/
You can submit a support ticket at https://insight.acquia.com/support/tickets/new?product=p:cli
Pull failed: Failed to exec # set -x # You can enable bash debugging output by uncommenting
set -eu -o pipefail
ls /var/www/html/.ddev >/dev/null # This just refreshes stale NFS if possible
pushd /var/www/html/.ddev/.downloads >/dev/null
acli pull:db -n -vvv @${project_id}
on web: exit status 1
In short, if I can figure out how to specify that the host is the db container and not local host, the username, pwd and db are db then I'm onto a winner.
acli doesn't seem to respect Drupal's settings.php for db connection? That would be weird. Definitely a bug report if it's happening. But as you know, every experiment you can try can be tried out first manually, line by line, inside the web container.