Am trying to backup set folders based on yesterday's date by using a bash script and CRON task.
The folder structure of the site is like this:
/home/admin/domains/mysite.com/public_html/media/2014/March
And I would want to back-up that folder to this file:
/home/admin/domains/mysite.com/public_html/bk/mediabackup-March-2014.tar.gz
So created this script:
#!/bin/bash
NOW=$(date -d "12 hours ago" '+%m')
NOWYEAR=$(date -d "12 hours ago" '+%Y')
MONTHS=(Dummy January February March April May June July August September October November December)
NOWMONTH=${MONTHS[3]}
FILE="/home/admin/domains/mysite.com/public_html/bk/mediabackup-$NOWMONTH-$NOWYEAR.tar.gz"
PATH="/home/admin/domains/mysite.com/public_html/media/$NOWYEAR/$NOWMONTH"
tar -zcvf $FILE $PATH
When I run this script though shell, I would do this:
bash script.sh
And it could come up "command not found" - not sure why it's not working?
Any help would be great, thanks :)
PATH
as a variable. You overwrote its default value therefore all commands can't be found, even bash.PATH
as a variable. Replace it with something likeSOURCEPATH
and you'll be fine.