Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file for Backup

Status
Not open for further replies.

Delphard

Programmer
Jul 22, 2004
144
RS
Can I make complete Backup of a database (same as from MySQL Administrator) using batch file?
 
Yes you can. But since you said batch file, I have to assume you're using Windows. Sorry, I can't help with that.

I use mysqlhotcopy in a shell script. I hear most people use mysqldump. You should be able to run the program within a batch file. You may need to fully qualify the executable or cd to the directory.

Mark
 
I backup my DB on linux using a bash script. Was a pain in the rear as I wanted to back up each table into a separate file, so i've got 30 different statements running. Maybe there was a better way, but i'm not that clever.


here's the script. If you are using windows then you'd need to change the file creating bit, i guess

#!bin/sh

#This is the directory to save the log files to:
#create subfolder for todays backups

today_folder=`date +%Y-%m-%d-%a`
backup_dir="/dbbackup/"$today_folder


#If the directory exists for the date Y-m-d-a then...
if [ -d $backup_dir ]
then echo directory $backup_dir exists
else echo directory $backup_dir does not exist
mkdir $backup_dir

fi


#dump tables
/usr/local/mysql/bin/mysqldump --net_buffer_length=64k -u myusername -pmypassword dbname tablename> $backup_dir/filename.sql
/usr/local/mysql/bin/mysqldump --net_buffer_length=64k -u myusername -pmypassword dbname tablename> $backup_dir/filename.sql
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top