Project

General

Profile

Downloading and restoring a database backup

The server where etbmanager.org is hosted performs daily backup of the eTB Manager database. This backup file is available through FTP using the following credentials:

FTP server: ftp.etbmanager.org
User: msh
Password: etbm123
Folder: database/etbmanager

Inside this folder you’ll find the latest database backup (file etbmanager.zip) followed by the backup files of the past 7 days.

The backup files were generated using the mysqldump command line program, so once downloaded the backup, it’s better to restore it using the mysql command line program, available in the MySQL folder.

Automating the downloading and restoring process

In order to make things easier, the batch file bellow does all the job of downloading and restoring the database. Just create a file called etbmanager-download-restore.bat with the content bellow:

set databasename=etbmanager
set username=msh
set password=etbm123

set backupdir=c:\etbmanager\databases\DOWNLOADED

set mysqldump="c:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" 
set mysqluser="c:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" --user=root --password=admin
set zip=c:\Program Files\7-Zip\7z.exe

set ftpdir=/database/%databasename%

echo %username%> tmp.txt
echo %password%>> tmp.txt
echo bin>> tmp.txt
echo cd %ftpdir%>> tmp.txt
echo lcd "%backupdir%">> tmp.txt
echo hash on>> tmp.txt
echo get %databasename%.zip>> tmp.txt
echo bye>> tmp.txt

echo ** DOWNLOADING FROM %ftpdir%

ftp -s:tmp.txt ftp.etbmanager.org
del tmp.txt

set backupfile=%backupdir%\%databasename%.zip

"%zip%" e "-o%backupdir%" -y "%backupfile%" 

del "%backupfile%" 

set dbfile="%backupdir%\%databasename%.bkp.sql" 

if not exist %dbfile% goto :erro_bkpnotfound

echo BACK-UP FILE: %dbfile%

echo droping database %databasename%

echo drop database %databasename%; > tmp.sql
%mysqluser% mysql < tmp.sql

echo restoring database backup
%mysqluser% mysql < %dbfile%

del tmp.sql

echo %databasename% was successfully restored
goto :fim

:erro_bkpnotfound

echo back-up file not found: %dbfile%
goto :fim

:fim

Update the paths in the batch file to the corresponding paths in your computer.

This batch file requires 7-zip and MySQL Server installed in your computer.

ftp_download_restore.PNG (18.2 KB) Ricardo Memoria, 06/29/2012 11:49 AM