On Thu, 23 Oct 2003 20:41:57 +0200, allan juul wrote:

Hi Allan

>�how to copy a database (by scripting)

I does not have to be Perl, you know :-).

I use the command line utilities that come with MySQL:

In these, %1 is the name of the db.

Backup:
-----><8-----
@echo off
@rem backup-mysql.bat.

cd \backup
echo Password:
mysqldump -uroot -p --opt %1 > mysql-backup-%1.txt
perl \bin1\fix-mysql-backup.pl mysql-backup-%1.txt
zip -qr mysql-backup-%1.zip mysql-backup-%1.txt
del /q mysql-backup-%1.txt
echo Backed up MySQL db %1
-----><8-----

You choose --opt etc to include or exclude things like:
o Export Drop table statement
o Export Create table statement
o Export Data (ie or just Create table statement)
depending.

The Perl is only there to clean up the output file, since mysqldump outputs the prompt:
Enter Password:
(due to the -p) in the output steam, so I chop it off before compressing the file.

Restore:
-----><8-----
@echo off
@rem restore-mysql.bat.

cd \backup
unzip -q mysql-backup-%1.zip
mysql -uroot -p %1 < mysql-backup-%1.txt
del /q mysql-backup-%1.txt
echo Restored MySQL db %1
-----><8-----

--
Cheers
Ron Savage, [EMAIL PROTECTED] on 24/10/2003
http://savage.net.au/index.html

Reply via email to