How do I use import and export php classes with aegir?
To execute a PHP script in the context of a selected site, use drush php-script or drush scr.

In your question you specified the site using -s example.org, and I suspect you may be looking for -l (--uri) rather than -s (--simulate) to determine which site to load. See the first section of drush help output for these flags.

If -l doesn't do it, you can also use aliases which Aegir automatically creates for each site - you should find that drush @example.org vget site_name works and returns the name of the expected site, because there will be alias files in eg /var/aegir/.drush/EXAMPLE.ORG.alias.drushrc.php for each site.

So, you probably want something like: drush -l example.org scr /path/to/export.php


If drush vget site_name returns the name of the expected site, you've confirmed Drush can connect to Drupal.
If drush cvapi Contact.get returns contacts from your site, you've confirmed that CiviCRM works when called via Drush.
If drush scr import.php or drush scr export.php still don't work, that sounds like those scripts don't bootstrap "normally" for CiviCRM and there may be work to do to get them to behave.


I don't actually know how import.php/export.php are expected to behave - so I might have led you astray. Looking at them, I'd expect export.php probably works via Drush, but I see import.php is looking for $_GET['file'] which Id' expect to require special treatment for Drush use (but I see this SE answer says it works using --file=blah.csv, and that you should call them via php import.php not drush).