Making an snapshot of your Openbravo instance
I have created a small ant script that automates the process of making a ‘snapshot’ of your instance. By snapshot I mean a database dump and the whole Openbravo folder. This archive file (zip format) does not exclude any file, so .class files, Mercurial metadata, etc is also included in the file, so is a ‘real snapshot’
When is this script useful?
This tool is useful when:
- You are a newbie developing with Openbravo framework, you have an instance up and running, and you want to start testing something. Making an snapshot of your current state, gives you a easy way to step back if something goes wrong.
- You just want to archive the current state of your instance.
- You want to make a copy of your current instance. You can make a snapshot and restore in another folder. A couple of tweaks in the Openbravo.properties and voila! you have a copy of your instance.
- You want to move your running instance to a another environment (e.g for testing).
- Etc.
How to use it?
Note: The following commands are for GNU/Linux users. If you use other operating system, the script still works but the unzip process is different, e.g. I have tested on Windows using the built in extracting tool for zip files.
You can grab a copy of the snapshot.xml and place it inside your Openbravo sources folder, eg.
~/src/openbravo/pi $ wget http://bitbucket.org/iperdomo/labs/raw/8db9dcb650d3/openbravo/snapshot.xml
Making a snapshot
Once you have the snapshot.xml in the sources folder just run it (the default target is snapshot).
~/src/openbravo/pi $ ant -f snapshot.xml
Depending on your machine’s resources the script takes about 7 minutes. Is slower on Windows machines (and more slow if you have an antivirus checking every file that you touch). Here you have an example of the output.
snapshot:
[echo] Creating instance snapshot...
[echo] Making temp folder...
[echo] basedir /home/iperdomo/src/openbravo/pi
[echo] Creating a database backup...
[exec] pg_dump: reading schemas
[exec] pg_dump: reading user-defined functions
[exec] pg_dump: reading user-defined types
[exec] pg_dump: reading procedural languages
[exec] pg_dump: reading user-defined aggregate functions
[exec] pg_dump: reading user-defined operators
[exec] pg_dump: reading type casts
[exec] pg_dump: finding inheritance relationships
[exec] pg_dump: reading column info for interesting tables
... some more pg_dump logging ...
[exec] pg_dump: dumping contents of table s_resourceunavailable
[exec] pg_dump: dumping contents of table s_timeexpense
[exec] pg_dump: dumping contents of table s_timeexpenseline
[exec] pg_dump: dumping contents of table s_timetype
[echo] Making a zip...
[zip] Building zip: /home/iperdomo/src/openbravo/openbravo-2010-02-19_13-18-45.zip
BUILD SUCCESSFUL
Total time: 7 minutes 33 seconds
The script will call pg_dump with all the necessary parameters read from Openbravo.properties, and creates a .backup in the temp folder inside the sources. Then it archives the whole content in a zip file in the parent folder. The name of the zip is the name of the context plus a timestamp.
Restoring a snapshot
To restore an snapshot is as simple as removing the current folder and extracting the contents of the zip file. Then run the restore target from the script.
~/src/openbravo $ rm -rf pi ~/src/openbravo $ unzip /home/iperdomo/src/openbravo/openbravo-2010-02-19_13-18-45.zip -d pi
Example output of unzip
Archive: /home/iperdomo/src/openbravo/openbravo-2010-02-19_13-18-45.zip creating: pi/.hg/ creating: pi/.hg/store/ creating: pi/.hg/store/data/ creating: pi/.hg/store/data/.settings/ creating: pi/.hg/store/data/_web_content/ creating: pi/.hg/store/data/_web_content/_m_e_t_a-_i_n_f/ creating: pi/.hg/store/data/_web_content/_w_e_b-_i_n_f/ creating: pi/.hg/store/data/config/ creating: pi/.hg/store/data/config/eclipse/ creating: pi/.hg/store/data/database/model/sequences/ ... some more log ... inflating: pi/web/skins/Default/Popup/_ParticularItems/Workflow/iconTask.png inflating: pi/web/skins/Default/Popup/_ParticularItems/Workflow/iconWorkflow.png inflating: pi/web/skins/Default/RTLFlippedImages.txt
After extracting the contents of the zip file, change the directory to the Openbravo sources and execute the restore target, e.g.
~/src/openbravo $ cd pi ~/src/openbravo/pi $ ant -f snapshot.xml restore
This will drop the database and use pg_restore to restore the .backup file stored in the temp folder. Here you have some example of the log output.
Buildfile: snapshot.xml
check.backup:
[echo] Checking if openbravo.backup file exists in /home/iperdomo/src/openbravo/pi/temp folder...
restore:
[echo] Deleting the database ...
[sql] Executing commands
[sql] 1 of 1 SQL statements executed successfully
[echo] Creating the database...
[sql] Executing commands
[sql] 1 of 1 SQL statements executed successfully
[echo] Restoring the backup file...
[exec] pg_restore: connecting to database for restore
[exec] pg_restore: creating SCHEMA public
[exec] pg_restore: creating COMMENT SCHEMA public
[exec] pg_restore: creating PROCEDURAL LANGUAGE plpgsql
[exec] pg_restore: creating FUNCTION a_amortization_process(character varying)
... some other pg_restore log ...
[exec] pg_restore: setting owner and privileges for FK CONSTRAINT s_timeexpenseline_s_timeexpens
[exec] pg_restore: setting owner and privileges for FK CONSTRAINT s_timeexpenseline_s_timetype
[exec] pg_restore: setting owner and privileges for FK CONSTRAINT s_timetype_ad_client
[exec] pg_restore: setting owner and privileges for FK CONSTRAINT s_timetype_ad_org
BUILD SUCCESSFUL
Total time: 36 seconds
That’s it, you have restored your snapshot.
How to use the script to copy an instance?
You follow the same procedure, to create the snapshot. Then you unzip the archive and another folder.
~/src/openbravo $ unzip openbravo-2010-02-19_13-18-45.zip -d pi2
After the extraction of the archive contents, you modify the Openbravo.properties and change the following properties:
# New name of the context context.name=openbravo-copy # Should point to the new path source.path=/home/iperdomo/src/openbravo/pi2 # New name of the database bbdd.sid=pi_reference
After changing the Openbravo.properties file, execute the restore process as usual.
Notes
Using the script with non default settings
The script assumes that you are working in a development environment with the ‘standard’ configuration of PostgreSQL. If your database is not in localhost or not using the default port 5432, you can override those properties when making the backup and restoring it.
~/src/openbravo/pi $ ant -f snapshot.xml -Dhost=otherHost -Dport=otherport
Why is not this part of Openbravo’s standard distribution?
As you can see the script uses pg_dump and pg_restore for dumping and restoring the database, so only PostgreSQL is supported. If you are willing you can send me a patch to include support for Oracle
That’s all, I hope this script will save you some time
Hi, i´m read xml file and i think this don´t put attach directory in backup it´s correct ?
good job
thanks
Carbonete
March 16, 2010 at 4:37 pm
Hi Carbonete,
This script archives all the content of your source path, usually the attach folder is inside the source path, but if you configure it outside this folder, it won’t get archived.
The idea is simple, backup your db, and zip the whole folder, whatever is inside the folder.
Best Regards,
Iván
katratxo
March 17, 2010 at 10:23 am
Can this procedure be used to backup and migrate data between different releases of Openbravo within the same major version? (e.g. 2.50MP8 to 2.50MP15)
If not, is there any alternate procedure for community users?
Thanks,
Daniel
Daniel
May 17, 2010 at 3:42 pm
Hi,
This script is to backup and restore, is not an upgrade tool. Community users can upgrade using the code repository. Here http://ln-s.net/6aE3 (Openbravo forums) you have a reply on how to upgrade your instance. Change 2.50MP10 to 2.50MP17 the latest release.
Cheers,
katratxo
May 17, 2010 at 4:06 pm
Excellent! Thanks! Great piece of information!
With the title talking about logos, I would have never found that post in the forum!
Once I get to test it, I’ll try to update the wiki for others to find this info more easily.
Thanks again, Daniel
Daniel
May 17, 2010 at 11:42 pm
How do I get the script to work on the (fully up and running) Community Edition VMWare image? I get this error:
#cd /opt/OpenbravoERP/src
#ant -f /root/snapshot.xml
Buildfile: /root/snapshot.xml
snapshot:
[echo] Creating instance snapshot…
[echo] Making temp folder…
[echo] basedir /root
[echo] Creating a database backup…
[exec] pg_dump: [archiver (db)] connection to database “${bbdd.sid}” failed: FATAL: database “${bbdd.sid}” does not exist
[exec] pg_dump: *** aborted because of error
BUILD FAILED
/root/snapshot.xml:51: exec returned: 1
Total time: 0 seconds
anonymous
October 28, 2010 at 1:31 am
sorry for the /root mistake earlier. here is the correct command, which still generates an error:
[root@localhost src]# pwd
/opt/OpenbravoERP/src
[root@localhost src]# ant -f snapshot.xml
Buildfile: snapshot.xml
snapshot:
[echo] Creating instance snapshot…
[echo] Making temp folder…
[echo] basedir /opt/OpenbravoERP/src
[echo] Creating a database backup…
[exec] pg_dump: [archiver (db)] connection to database “${bbdd.sid}” failed: FATAL: database “${bbdd.sid}” does not exist
[exec] pg_dump: *** aborted because of error
BUILD FAILED
/opt/OpenbravoERP/src/snapshot.xml:51: exec returned: 1
Total time: 0 seconds
anonymous
October 28, 2010 at 1:35 am
Remember that the community appliance ships an ‘openbravo’ user. Any command related to Openbravo must be executed using this user. Do not use root unless is strictly necessary.
Regards,
Iván
katratxo
October 28, 2010 at 9:18 am
[...] If you are not familiar with this script, I suggest you read my previous post on how to make a snapshot of your Openbravo instance [...]
Update: Making a snapshot of your Openbravo instance « katratxo on Openbravo
January 6, 2011 at 10:19 am
That’s cool. I am going to start using this solution.
Jarek Wozniak
October 5, 2011 at 5:52 pm
Hey Guys
i followed most if not all insructions via this post and i’am getting this error –
[echo] Creating instance snapshot…
[echo] Making temp folder…
[echo] basedir /opt/OpenbravoERP/src
[echo] Creating a database backup…
[exec] pg_dump: [archiver (db)] connection to database “${bbdd.sid}” failed: FATAL: database “${bbdd.sid}” does not exist
[exec] pg_dump: *** aborted because of error
BUILD FAILED
/opt/OpenbravoERP/src/snapshot.xml:51: exec returned: 1
Total time: 0 seconds
I have logged in as openbravo, which is the default user and not root, promted the command -
ant -f snapshot.xml
but i keep getting the error above any help would be appreicated
Thanks In Advance
Chanel K
Chanel K
October 27, 2011 at 9:33 am
Hi,
As the instructions explain, you should place the snapshot.xml file in the root folder of your sources, not under src. The folder from which you execute ant tasks.
katratxo
October 27, 2011 at 12:48 pm
sry but iam a linux begineer iam not sure where that folder is located. I appreciate you trying to help me with this as well. exactly where is the folder that houses ant tasks?
Chanel K
October 30, 2011 at 10:21 am
Hi,
Then you should try to get familiar with the sources folder structure before doing things “blindly”, more info at: http://wiki.openbravo.com/wiki/Development_Project_Structure
If you need further help, please use the forums: http://forge.openbravo.com/projects/openbravoerp/forum/help-f549511.html
katratxo
October 30, 2011 at 5:15 pm
Thank you so much for that directory breakdown for open bravo, i have a much better understanding of this component now. You mentioned to put the snapshots.xml in the sources folder, would that be the /src folder?
Thanks In Advance
Chanel K
October 30, 2011 at 11:09 pm
No,
The root folder that contains src, src-wad, etc.
As I mentioned in the previous message. If you need further help, please use the Help forum: http://forge.openbravo.com/projects/openbravoerp/forum/
katratxo
October 31, 2011 at 7:51 am
Hi
This snapshot, is just for development project?, because i installed openbravo erp from the ubuntu repository, how can i do a snapshot for that?. Thank you very much for your helpg
galvaroelvaroe
February 8, 2012 at 3:58 pm
Hi,
Is not just for development. First you need to understand how to run ant tasks, and where Openbravo is located in your machine.
More info at: http://wiki.openbravo.com/wiki/Installation/Ubuntu:_advanced_topics
Another thing is that the Ubuntu package starts a PostgreSQL service on different port, not the default one.
Try it out, and if you need further help, please use the forums:
http://forge.openbravo.com/projects/openbravoerp/forum/help-f549511.html
Cheers,
katratxo
February 8, 2012 at 5:20 pm