View source | Discuss this page | Page history | Printable version   
Main Page
Upload file
What links here
Recent changes

PDF Books
Add page
Show collection (0 pages)
Collections help


POS - Backup MySQL Database

Code snippet

Name: POS - Backup MySQL Database
Version: POS/2.20 & 2.30 Beta
Author: ronny_g

This code was created using MySQL in Windows.

These scripts will allow you to backup a MySQL database from a button within Openbravo POS.

It will also compress the data to a zip file. You will need to install an Open Source program called 7-Zip.

It will also analyze, optimise & repair the database after backup using mysqlcheck.

1) Create a Button

Add the following button to the Ticket.Buttons resource:

<button key="button.backup" name="button.backup" image="img.backup" code="Script.Backup"/>

2) Set Button Name

Add the following to the bottom of the file in locales folder:


3) Create the img.backup Resource

Create a image resource called img.backup and add a 16x16 transparent PNG file to it like this example.

4) Give Permission to the Backup Button

In Maintenance > Roles, give permission to the Print Order button. Add the following line to what ever roles you want to have access the backup button:

<class name="button.backup"/>

5) Create the Script.Backup Resource

Create a text resource called Script.Backup. In this example the batch file is located on the Administrator accounts desktop. Add the following script to it:

int n = javax.swing.JOptionPane.showConfirmDialog(
    "Please connect your Flash Drive then press OK.",
    "Openbravo POS Backup",

if (n == 0) {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("cmd /C start C:/Docume~1/Admini~1/desktop/backup.bat");

6) Create Batch File

Create a batch file called backup.bat and save it to the desktop of the Administrator account of Windows. Add the following script to it:

@echo off
echo Backing up OpenBravoPOS...
SET mySQLfile=E:\openbravopos.%MYDATE%.sql
"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump" -uusername -ppassword --result-file="%mySQLfile%" openbravopos
echo ---
SET myZIPfile=E:\
"C:\Program Files\7-Zip\7z.exe" a -tzip %myZIPfile% %mySQLfile%
echo ---
echo Deleting %mySQLfile%
DEL %mySQLfile%
echo ---
echo Analyzing, optimising and repairing databases
echo ---
"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqlcheck" --databases openbravopos --medium-check --auto-repair --force --optimize --analyze --check-only-changed --user=root --password=admin
echo ---
echo Backup Complete ;-)
echo ---
@ping -n 5 -w 1000 > nul

That should be it. You can obviously change anything you wish to suite your setup. Lets me know if something is not working or something can be bone better.

Good Luck, Ronny G

Retrieved from ""

This page has been accessed 26,193 times. This page was last modified on 19 April 2010, at 22:24. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.