I've got a phpbb discussion board running OK and it seems wise to automate backups. I found a recommended shell script that keeps seven recent backups in rotation. Not being a programmer, I tried to delicately edit the variables I could identify to replace them with my own and surprisingly, it kinda-sorta works What happens is I get a command not found error every time, but it does sucessfully make the backup. I've let it run eight days now, and I've got eight backups, so the pruning part also isn't working. Here's what I've done so far. If you can spot where I've gone wrong, pointers to the path of righteousness appreciated.
count_files=`ls -l /home/user/domain/forum/backups/db_name* | wc -l`
count_files=expr $count_files - 1
if [ $count_files -gt 7 ]; then
file_list=`ls -S -t -p -r /home/user/domain/forum/backups | grep gz`
mysqldump -h forum.domain -u user --password=password db_name > $output_file 2>&1
mv $output_file.gz $filename
chmod g+wr /home/user/domain/forum/backups/*
This is in my home dir as db_rotate and is executable. If I go sh db_rotate I get an 'Error: Command not found' plus a successful backup in the directory where I expect it. The glass is half full!
(I've also tried using sh db_rotate >/dev/null in the crontab to avoid getting error-reporting mail every day, but I still get the email. Also, even if it worked, it would just be treating the symptom
I tried pasting some of the standalone-type command lines at my shell prompt to see if I could discover the offending line that way, but the simpler ones all seemed to work. Some I don't really know how to test.
I guess I'm happy that I'm at least getting some backups and don't mind doing some of the pruning chores by hand, but I feel bad running such a sloppy process. I'd like to learn how to tidy this up. Thanks for any thoughts.