I'm creating a bash script to automate the task of making a backup of the virtual hosts I have in my web development virtual machine. I know there's far better approaches for this like using a backup manager, but I just want a quick & dirty method of having a physical backup of my development files in case I end screwing up the virtual machine.
Currently, this is what I currently wrote (I'm not a bash guru, so be benevolent haha):
cd sites
for d in `find -maxdepth 1 -mindepth 1 -type d`; do
mysqldump --user=XXXXXXXX --password=XXXXXXXX `echo $d | sed -r 's/^.{2}//'` > `echo $d | sed -r 's/^.{2}//'`-`date +"%d%m%Y"`.sql
if [$d -eq "./r4.dev"]; then
zip -r -9 `echo $d | sed -r 's/^.{2}//'`-`date +"%d%m%Y"`.zip {$d,`echo $d | sed -r 's/^.{2}//'`-`date +"%d%m%Y"`.sql} -x *documentation*
else
zip -r -9 `echo $d | sed -r 's/^.{2}//'`-`date +"%d%m%Y"`.zip {$d,`echo $d | sed -r 's/^.{2}//'`-`date +"%d%m%Y"`.sql} -x *framework*
fi
rm `echo $d | sed -r 's/^.{2}//'`-`date +"%d%m%Y"`.sql
done
cd ..
The logic behind the scheme is the following: all domains get a symlink to the PHP framework I'm developing, which is located in another domain (r4.dev). What I want is for the domain where the development files are to zip everything except the documentation folder. In any of the other domains, I want to zip everything except the symlink to the framework, because if it's present, it ends backing up the whole framework folder, and I want to get a minimum-sized backup.
The backup commands work per se, but what is failing is the directory comparison. I've been trying different combinations like $d -eq "./r4.dev"
, "$d" = ./r4.dev
, "$(basename "${d}")" -eq "./r4.dev"
and some others, but none seem to work.
I'm sure the solution is rather simple, but I can't seem to see it right now. Could you give me a hint on how to correct the comparison so it works like I expect?
Thanks in advance, Julio