by dastiogarbi on December 02, 2008, 04:37:00 PMMungkin ada sebagian dari kita yang pernah membuat program dalam bentuk batch file. Salah satu contohnya yang sering kita lihat adalah autoexec.bat. Pemakai DOS/Windows pasti tahu apa itu autoexec.bat. Karena kita sering melihatnya di dalam direktori c:\. Nah nanti kita akan membuat program yang mirip dengan itu.
Program yang akan kita buat berfungsi sebagai alat otomatis membackup database MySQL, mengompresnya dengan WinRAR, dan terakhir mengirimkan file rar-nya ke dalam ftp. Program ini saya dapatkan dari forum MySQL, lalu saya kembangkan dibantu dengan teman-teman lainnya.
Command line yang digunakan dalam program batch ini adalah :
1. mysqldump (tool backup dari mySQL).
2. ftp (tool pengiriman file dari DOS maupun OS lainnya).
Ada 2 program bantu yang harus ada di komputer kita :
1. doff.exe, ambil dari Freeware Windows command-line website.
2. winrar, ambil dari RarLab website.
Ok, kalau sudah semua ada di tangan, kita mulai sekarang :
1. Ucapkan doa. Setiap pekerjaan kan harus dimulai dengan doa, bukan.
2. Buka notepad. Editor ringan dan handal untuk membuat program batch.
3. Copy baris - baris program di bawah ini
:: Author : Wade Hedgren (see comments at http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html)
:: Mathieu van Loon (mathieu-public@jijenik.com)
:: For more information see http://www.jijenik.com/projects/mysqlbackup/index.html
:: Modified : Setiaji Kurniawan (setiaji.kurniawan@gmail.com) & Nailan Ulya (nailan.ulya@gmail.com)
::
:: Creates a backup of all databases in MySQL.
:: Zip and encrypts the backup file.
::
:: License and terms of use
:: This script is provided as is and free of charge. You are free to copy, use and modify this script
:: provided this license is retained.
::
::
@echo off
::
:: Configuration options
::
:: Name of the database user
set dbuser=root
:: Password for the database user
set dbpass=root
:: directory where backup logfiles are stored
set logdir=C:\BackupMySQLDB\Log
:: directory where backup files are stored
set bkupdir=C:\BackupMySQLDB
:: Install folder of MySQL
set mysqldir=C:\Program Files\MySQL\MySQL Server 5.0
:: Data directory of MySQL (only used to enumerate databases, we use mysqldump for backup)
set datadir=C:\Program Files\MySQL\MySQL Server 5.0\data
:: Path of Winrar compression tool
set zip=C:\Program Files\WinRAR\winrar.exe
:: Path of doff date tool (specify only the folder not the exe)
set doff=C:\BackupMySQLDB\Prog
::
::
:: NO NEED TO CHANGE ANYTHING BELOW
::
::
:: get the date and then parse it into variables
pushd %doff%
for /f %%i in ('doff.exe yyyymmdd_hhmiss') do set fn=%%i
for /f %%i in ('doff.exe dd-mm-yyyy hh:mi:ss') do set nicedate=%%i
popd
set logfile="%logdir%\%fn%_Backuplog.txt"
:: Switch to the data directory to enumerate the folders
pushd "%datadir%"
:: Write to the log file
echo Beginning MySQLDump Process > %logfile%
echo Start Time = %nicedate% >> %logfile%
echo --------------------------- >> %logfile%
echo. >> %logfile%
:: Create the backup folder
if not exist "%bkupdir%\%fn%\" (
echo Making Directory %fn%
echo Making Directory %fn% >> %logfile%
mkdir "%bkupdir%\%fn%"
)
Bagian di bawah ini memanfaatkan command line mysqldump.
echo Backing up database %fn%_%.sql
echo Backing up database %fn%_%.sql >> %logfile%
"%mysqldir%\bin\mysqldump" --user=%dbuser% --password=%dbpass% --database MyDB1 --opt --quote-names --allow-keywords --complete-insert > "%bkupdir%\%fn%\%fn%_%.sql"
echo Done... >> %logfile%
:: return from data dir
popd
pushd %bkupdir%
echo Zipping databases
echo Zipping databases >> %logfile%
"%zip%" a -pPassword1 "%fn%_MySQLBackup" "%bkupdir%\%fn%"
:: Go back and get the end time for the script
set endtime=1
:: return from backup dir
popd
:: update the nicedate for the log
pushd %doff%
for /f %%i in ('doff.exe dd-mm-yyyy hh:mi:ss') do set nicedate=%%i
popd
:: Write to the log file
echo. >> %logfile%
echo --------------------------- >> %logfile%
echo MySQLDump Process Finished >> %logfile%
echo End Time = %nicedate% >> %logfile%
echo. >> %logfile%
pushd
Bagian di bawah ini memanfaatkan command line ftp.
echo Kirim pake FTP
;@echo off
;(for /f "usebackq delims=" %%A in ("%~f0") do call echo.%%A)>"%temp%\%~n0.ftp"
;ftp -i -s:"%temp%\%~n0.ftp"
;GOTO:EOF
open ftp.myserverftp.net
myusername
mypassword1
echo !:--- FTP commands below here ---
lcd %bkupdir%
cd "/usr/home/data/"
binary
mput %bkupdir%\%fn%_MySQLBackup.rar
disconnect
bye
popd
4. Simpan script di atas ke dalam file dengan nama apa saja, asal extensionnya .bat.
5. Sudah selesai. Untuk menjalankannya, klik saja 2 kali. :D
7.13.2009
Posted by karya_Simple on/at 03.29
Langganan:
Posting Komentar (Atom)

0 komentar:
Posting Komentar