I am running Aegir on:
D6.14, provision 0.4-alpha1, hosting0.4-a1, drush2.0, hostmaster0.4a1
OSX10.5 and MAMP
Adding platforms and sites works well, however untill now I was not able to backup (and migrate)sites, because: "An error occurred at function : drush_provision_mysql_pre_provision_backup"
Using the Terminal the backup did work however. After a long, long time I found out that mysqldump should be called by stating the whole path when using cron: usr/local/bin/mysqldump. (found this here: http://www.nntp.perl.org/group/perl.macosx/2002/09/msg3205.html)
So I changed line 6 of backup.provision.inc to $cmd = sprintf("/usr/local/bin/mysqldump --defaults-file=/dev/fd/3 -rsites/%s/database.sql %s" (...)
And it works!
I don't know if it's a bug, or something I should setup on my own system or something else; or perhaps there is a better solution?
Anyway, it could be usefull for anyone running into the same problem.
Comments
Comment #1
Anonymous (not verified) commentedYour solution works because your binary mysqldump happens to be in /usr/local/bin, a custom area which seems specific to MAMP (I've no idea about MAMP).
In most standard Linux distributions that have MySQL installed, the mysqldump binary is in /usr/local/bin, and hence it works, as it's in the PATH environment, and after a quick googling it looks like apparently the geniuses at Apple don't put this on the PATH.
Perhaps what we want to do here is automatically detect the location of the binary by using `which` in the backup task. I'll see what can be done.
Thanks!
Comment #2
adrian commentedYou should edit the $PATH in your ~/.bash_profile
Moya:hosting adrian$ cat ~/.bash_profile
export PATH=/Applications/MAMP/bin/php5/bin:/Applications/MAMP/bin/apache2/bin:/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
Comment #3
anarcat commentedIndeed, we assume that the binaries are in the PATH, otherwise fix the PATH on your machine.
Comment #4
Rainy Day commentedIIRC, /usr/local/bin does not exist on Mac OS X by default (hence it is not part of $PATH), but the MySQL installer (et al) will create the directory if absent.
A generalized (OS agnostic) solution to this problem would simply be to let the backup script check $PATH for /usr/local/bin, and if absent, add it:
if `echo $PATH | grep -vqE "(^|:)/usr/local/bin(:|$)"`; then export PATH="/usr/local/bin:${PATH}"; fiComment #5
dman commentedsudo ln -s /usr/local/bin/mysqldump /usr/bin/:-)
but yeah, adding /usr/local/bin to $PATH is nicer. Note, as webserver should run as a daemon (not you) it should be done system-wide,
/etc/bashrcnot just~/.bash_profileNot sure if that affects MAMP, but it's better anyway.
Comment #6
anarcat commentedThat's just silly: if proper tools are not available to aegir, it will *not* work. The environment needs to be properly configured. We can't have exceptions for every platform out there, that's what $PATH is for: it points to where your stuff is. If it's not configured properly, it's not up to aegir to fix that, it's up to the operating system and its maintainer.
Adding /usr/local/bin to the PATH is not "platform agnostic": it assumes /usr/local exists and has some meaning. In Debian, it's useless and can even be harmful, for example.
Comment #7
Rainy Day commented@anarcat: On the contrary, there is a good argument to be made that scripts should never rely on $PATH being set to anything useful. My previously suggested check is a concession to those who would like to rely on $PATH anyhow; it will make the Aegir script more robust, and prevent this question from arising again. Your concern about the existence of the directory is valid, so here is an updated version which doesn’t touch $PATH unless the directory actually exists:
if [ -d /usr/local/bin/ ] && `echo $PATH | grep -vqE "(^|:)/usr/local/bin(:|$)"`; then export PATH="/usr/local/bin:${PATH}"; fiComment #8
anarcat commentedWhat *is* that argument that scripts should not rely on $PATH?
Arguably, we sometimes do use explicit paths but only because the actual apachectl binary varies in *name* (apachectl vs apache2ctl), not in path. Furthermore, the problem is solved differently: the path is autodetected on install and editable by the adminsitrator.
Hacking around the $PATH is not the right way. If we want to give power to the user, we should let complete control over the complete binary path.
Comment #9
Rainy Day commented$PATH is too volatile and unreliable. Seasoned UNIX scripters eschew it; trusting it can really wreck havoc (scripts failing under various conditions, or unpredictably in the future). Relying on $PATH does not make for robust code.
But this may be a situation where you have to choose one devil or another, and really don’t have a good alternative. Guess POSIX still has a ways to go.
Comment #10
anarcat commentedSo far this is the only argument i've seen against $PATH: it's too brittle (ie. not robust). On the contrary, in my opinion, hardcoding the path to the binary makes code unnecessary complicated and is *also* brittle, as the path may change between platforms. It *forces* porters to actually patch the code to make it work, instead of just setting up a proper environment.
The only reason I would see why we would want to change that path is because the actual binary name changes, like apache requires it, because it's sometimes apachectl, apache2ctl or whatever. We *need* to let the user choose the binary because it *might* be ambiguous. We don't do that because we can't find apachectl, we can figure that out ourselves if necessary.
I do not think that mysqldump would change name. I have never seen such an instance.
I do respect your position however and if you feel we absolutely need to bypass the PATH, it should be done in the server verification step, and this issue should be reopened (otherwise it's being ignored right now).
Comment #11
Rainy Day commentedWell i really don’t like hacking away at $PATH any more than you do. But relying on $PATH makes for fragile code. I concur that the mysqldump name is likely to be pretty static. So it would seem the best approach would be to determine mysqldump’s location in the server verification step, as you suggest. My recommendation would be to reopen the issue. YMMV.