Backup and restore database
If the field type in odoo can be converted, you just need to click the update button in the module. If you are not allowed to modify the field type, then you need to use the following methods to backup and restore the database.
speech_balloon: For example, it is allowed for integer to convert to char type, but when you convert from char to integer type, there will be problems in data storage, which is not allowed and dangerous.
zap: Note: Files in the / usr / lib / Python 2.7 / dist-packages / openerp / addons directory in Odoo should be the same as those in the directory before backup.
1. Backup database:
root@runner:/home/sg-os# pg_dump -U postgres linxerp >/home/sg-os/linxerp.bak
2. Create a new database:
root@runner:/home/sg-os# su - postgres
postgres@runner:~$ createdb newlinxerp
3. Change the owner of the database:
postgres@runner:~$ psql
postgres=# alter database newlinxerp owner to odoo;
4. Restore the database:
postgres=# \q
postgres@runner:~$ exit
root@runner:/home/sg-os# psql -U postgres -d newlinxerp </home/sg-os/linxerp.bak
II. Data Restoration
1. Create a folder:
root@runner:/home/sg-os# cd /var/lib/postgresql
root@runner:/var/lib/postgresql# mkdir csv_file
2. Change the group of documents:
root@runner:/var/lib/postgresql# chown postgres.postgres csv_file
3. Export the files in the database to the csv file and execute the following python script:
speech_balloon: A table corresponds to a CSV file named after the table name and stored in the / var/lib/postgresql/csv_file directory
#!/usr/bin/env python
import psycopg2
conn = psycopg2.connect("dbname=linxerp user=postgres")
cur = conn.cursor()
cur.execute("select tablename from pg_tables where tablename not like 'pg%' and tablename not like 'sql_%';")
tables=cur.fetchall()
for table in tables:
table_csv="copy " + table[0] + " to '/var/lib/postgresql/csv_file/"+ table[0] + ".csv' with csv header;"
cur.execute(table_csv)
conn.commit()
cur.close()
conn.close()
4. Uninstall the module you want to change, click the uninstall in the module. (Take the product_receive_prove module as an example for the following operations)
5. Place the latest version of the module file in the / usr / lib / Python 2.7 / dist-packages / openerp / addons / directory and restart the odoo service
root@runner:/home/sg-os# /etc/init.d/odoo restart
6. Installation module
7. If a new field is added, then you need to modify the corresponding csv file of this table, and change the header of the original csv file to be consistent with the header of the present database. If no new fields are added, skip this step and do the following.
8. To load data, all class classes in the module need to load data (a class class class corresponds to a table in the database). The following statement is only one of them:
speech_balloon: Grammar: copy table name from'absolute path'with csv header;
newlinxerp=# copy product_receive_prove from '/var/lib/postgresql/csv_file/product_receive_prove.csv' with csv header;
9. Update the id of the table. The id of all tables in the unloaded module needs to be updated. The following statement is just one of the tables.
speech_balloon: Syntax: select setval('table name_id_seq', max(id)) from table name;
newlinxerp=# select setval('product_receive_prove_id_seq',max(id)) from product_receive_prove;
10. Update the workflow table and skip this step if the unloaded module does not have a workflow
newlinxerp=# copy wkf_instance from '/var/lib/postgresql/csv_file/wkf_instance.csv' with csv header;
newlinxerp=# copy wkf_workitem from '/var/lib/postgresql/csv_file/wkf_workitem.csv' with csv header;
11. Update the translation. If the translation of the reinstallation module is not translated, you need to update it manually. If the translation is successful, skip this step.
newlinxerp=# update ir_translation set value='translate' where id=Recorded id Number;
12, the end