Version 10 (modified by Fran Boon, 12 years ago) ( diff )




This is normally done using Fab:

fab <systemname> deploy



Put site into Maintenance:

vim /etc/crontab
#0-59/1 * * * * www-data cd /path/to/web2py/ && python -C -D 1 >> /tmp/cron.output 2>&1

vim /etc/apache/sites-available/maintenance
  RewriteEngine On
  RewriteRule ^/(.*) /maintenance.html

ln -sf /etc/apache/sites-available/maintenance /etc/apache/sites-enabled/mysite
/etc/init.d/apache2 force-reload

Upgrade code:

cd /path/to/web2py/applications/eden
bzr pull

Trial run:

cd /path/to/web2py
python -S eden -M

Fix any Database Issues:

  1. The .table files in the databases directory contains what web2py knows about your database
  2. You need to set deployment_settings.base.migrate=True in models/ before you update the code and switch back to deployment_settings.base.migrate=False later on.
  3. In case of database mismatches - check the databases directory for the appropriate .table file and change accordingly.

If using MySQL, then can use phpMyAdmin, if using SQLite then can use sqlite3 command-line tool:

Restore site into production:

vim /etc/crontab
0-59/1 * * * * www-data cd /path/to/web2py/ && python -C -D 1 >> /tmp/cron.output 2>&1

ln -sf /etc/apache/sites-available/mysite /etc/apache/sites-enabled/mysite
/etc/init.d/apache2 force-reload

Data Migration

We now have a nifty script to help a lot with this process on MySQL. The script includes lots of detailed documentation steps:

  • static/scripts/tools/

Importing existing copy of the database into a fresh installation

This is needed for some incompatible Schema modifications, such as changing the length of the UUID field (MySQL-only for this - SQLite is fine).

Warning use the following only if

  • You have a SQL dump of the data.
  • You are aware of the schema changes for the updated code.

1: Export Data

  1. Turn off the Webserver and Cron to make sure no other instance of web2py is hooking into the database.
    /etc/init.d/apache2 stop
    /etc/init.d/cron stop

  1. Take a data-only dump of the SQL database.
    • For MySQL, disable "foreign key checks" - Note: Do not include the structure of the database
      The following screen shot shows the settings for exporting data via phpMyAdmin (for MySQL users):

No image "phpmyadmin-dump-sql.png" attached to UserGuidelines/Admin/Upgrade

  • For SQLite users, dump the database using CSV:
    python -S eden -M -N

2: Drop the Database


mysql -u root -p
drop DATABASE sahana;
create DATABASE sahana;
rm -rf databases/*


rm -rf databases/*

3: Upgrade the Codebase

cd applications/eden
bzr pull
cd ../..

4: Import Data

  1. Set the following in models/
    deployment_settings.base.prepopulate = False
  1. Create the db structure via shell:
    cd /path/to/web2py
    python -S eden -M -N
  1. Fix permissions:
    chown www-data:www-data applications/eden/databases/*
  1. Import the existing data into the database
    • If using MySQL:
      mysql -u root -p
      \u sahana
      \. sahana.sql
    • If using sqlite then use the CSV export:
      python -S eden -M -N
  1. Turn back on the Webserver and Cron.
    /etc/init.d/apache2 start
    /etc/init.d/cron start

Foreign Key problems when doing live migrations on MySQL

Can't do a live migration on MySQL & get an error like this?

OperationalError: (1025, "Error on rename of './prod/#sql-372_f2' to './prod/drrpp_project' (errno: 150)") 

It's likely a problem with a foreign key...can see more information on the error through:


Look for the section 'LATEST FOREIGN KEY ERROR' should see something like:

100615  0:27:09 Error in foreign key constraint of table prod/drrpp_project:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match to the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
  CONSTRAINT drrpp_project_ibfk_2 FOREIGN KEY (drrpp_contact_id) REFERENCES drrpp_contact (id) 

So to resolve this, need to:

ALTER TABLE drrpp_project DROP FOREIGN KEY drrpp_project_ibfk_2;

You'll need to remove the failed attempt to ALTER_TABLE from the bottom of databases/sql.log & maybe also delete the Index.

phpMyAdmin can show all FK relationships & allow you to clear them: under table structures there is a link to 'relation view', as well as a list of the Indexes.

Can completely disable checks using:

SET foreign_key_checks = 0;

Other examples

Here are some examples of Data migration used on the Haiti instance, some of which are more-generally applicable:



Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.