I am running a website on an Amazon ec2 instance running the default Debian linux. I set up a cronjob to copy the site files, take a database imprint, and zip them up. I want to keep the file archives in the same directory as the bash script itself, which is located somewhat deep within /var/www/[a new directory]/[a new directory]/[etc]/. I created a mysql user that can only read and dump the database, but cannot write to it.
The script is as follows
#/bin/bash
CURRPATH=$(pwd)
SITEPATH="/var/www/html"
MYSQLUSER="user"
MYSQLPASS="password"
MYSQLDB="database"
CURRDATE=$(date +"%Y-%m-%d__%T_%p")
DATETAG="Backup_$CURRDATE"
TEMPDIR="$CURRPATH/$DATETAG"
ARCHIVENAME="$DATETAG.zip"
# I first copy the files so I can stick a database imprint in the same directory
cp -r "$SITEPATH/" "$CURRPATH/"
mv "$CURRPATH/html" "$TEMPDIR"
mysqldump -u "$MYSQLUSER" -p"$MYSQLPASS" "$MYSQLDB" > "$TEMPDIR/BackupDB_$CURRDATE.sql"
cd $CURRPATH
zip -r "$ARCHIVENAME" "$DATETAG"
rm -rf "$TEMPDIR"
I set this with crontab, and it works perfectly, except for one problem - the archive ends up in the ~/root folder (I set up the crontab with the root user).
Is there a way to get this archive to spit out in the same directory as the script, the $CURRPATH variable?