Blog Backup Script Fixed (Updated) 6
You can read the full story of how I shot this trouble here. I kept it all in one place in case some poor jerk like me comes along looking for an answer to the same problem.
I’ve written a script to back up the database and set it up to run at five tomorrow morning. I’ve already run the script from the command line and it works perfectly. All I’m doing now is testing the cron job.
Addendum, 10/24/2008:
The script ran this morning, right on schedule.
End Addendum
If you’re interested in the script, it’s below the fold.
The first line declares that this is a bash script.
The remaining lines prefaced with an octothorp (#) are “remarked out.” They are notes and reminders about the script, not commands to be executed.
“echo” means “display the following line of text on the screen to give the user something to look at while I do the work.”
[BEGIN SCRIPT]
#!/bin/bash
#Set the variable NOW
NOW=1
#Define now as today's day-month-year-hour-minute.
NOW=$(date +%m-%d-%Y-%H-%M)
#Make the directory to hold the backup file.
mkdir /root/backups/sql/$NOW
echo "Making the directory for the backup."
cd /opt/lampp/bin
echo "Entering the Lampp directory."
mysqldump -S /opt/lampp/var/mysql/mysql.sock -u [username] -p[password] [databasename] > /root/backups/sql/$NOW/[filename].sql
(Note: The above command is one line. The blog forces it to wrap.--ed)
echo "Backing up database."
cd
echo "Returning to root directory and exiting."
[END SCRIPT]
October 22, 2008 at 4:53 pm
Does this script do the same thing that my external hard drive & the backup capability of Norton 360 do?
October 22, 2008 at 11:02 pm
Well, probably similar.
Except for the underlying reality that Norton sucks.
October 23, 2008 at 7:20 pm
I’ve used it for 7 or 8 years & it has given me very little trouble. And I’ve never had a bug.
July 28, 2010 at 8:59 pm
[…] to GoDaddy. I haven't tried scripting on GoDaddy. You can read the details and see the script on my blog. I've never tried to enter variables in cron, so I'm not competent to comment on […]
April 21, 2011 at 11:48 am
[…] I was just greeted with the dreaded “Unable to connect to database” error message. (That’s the same error that cost me three months of posts three years ago and led me to my first venture in BASH scripting). […]
August 21, 2011 at 8:45 pm
[…] I wrote up a script that worked for me several years ago. You are welcome to look at it, in case it helps. http://www.pineviewfarm.net/weblog/?p=3113 […]