Community mailing list archives

community@mail.odoo.com

Re: SUMMARY: SEEKING: Method to script backups of Odoo v9 - also include filestore (anything else??)

by
Camptocamp France SAS, Alexandre Fayolle - Camptocamp
- 01/03/2016 05:41:08
> Backuping databases under postgres or a superuser role of postgresql
> is not a good practice imho.

Hello Dominique. I'm curious about this one. Can you elaborate?

Alexandre

2015-12-31 10:53 GMT+01:00 Dominique Chabord <dominique.chabord@sisalp.org>:
-Hi Ray,

under some circumstances, your script will work.
You may improve it a bit by
- cd to adirectory so you don't have to before launching it and it
will work on crontab
- test result of pg_dump and tar, remove failed backups and exit with
an error code
- use full paths of commands to run under different environments.
- log the details

Backuping databases under postgres or a superuser role of postgresql
is not a good practice imho.
I don't expect you can -U postgres if you don't have root priviledge,
again not a good practice.
If you have root priviledge, you cannot sudo.
 I wouldn't make an rm $file behind a find without any
control, as root, this may damage the server if the find output is not
what you expect.
 I wouldn't suppress old backups on a test on dates
(-mtimes), you will erase valuable data one day or the other

Last recommandation would be to manage restoration in the same script
for maintenance reasons.

BTW, if your database gets important, stress on disk and space on disk
become important too. Compressing filestore is not so efficient, most
files are already compressed.

hope this helps


2015-12-31 9:42 GMT+01:00 Levent Karakas <levent@mektup.at>:
> From our experience, pgdump sometimes fails if database in use so we stop
> the instance and then dump the database. before zipping filestore we start
> it back to minimize the downtime.
>
> - stop instance
> - pgdump database
> - start instance
> - zip sql dump and filestore (zip is better if you might use database
> manager gui to restore)
> - send the backup file (sftp/s3 etc.)
>
>
>
> How do you manage to disable interfacing such as pop/e-mail, connectors etc
> on copy databases? Do you disable them manually with running some SQL?
>
>
>
> 2015-12-31 3:35 GMT+02:00 Ray Carnes <ray.carnes@bistasolutions.com>:
>>
>> Thanks to Stefan Rijnhart and Dominique Chabord (their replies, and my
>> original question are at the end of this email)
>>
>>
>>
>> I will be using the script below - rotating backups (keeps last 11) of all
>> databases on a specific server, with their filestore – (since the servers I
>> am moving from and to are all identically configured [highly recommended], I
>> won't need to worry about file permissions or different postgres users,
>> etc.).  It also bounces the postgres and odoo service.  I schedule it daily
>> via a cron for the postgres user.
>>
>>
>>
>> #!/bin/sh
>>
>> hostname=`hostname`
>>
>>
>>
>> ##########################################
>>
>> ##Odoo v9 Backup
>>
>> ##########################################
>>
>>
>>
>>
>> #############################################################################
>>
>> ##Add the following lines to the sudoers file, so postgres can restart the
>> services
>>
>> ##
>>
>> ##postgres        ALL=NOPASSWD: /usr/sbin/service odoo-server restart
>>
>> ##postgres        ALL=NOPASSWD: /usr/bin/service postgresql restart
>>
>>
>> #############################################################################
>>
>>
>>
>> # ReStart PostgreSQL
>>
>> sudo /usr/sbin/service postgresql restart
>>
>>
>>
>> # Dump DBs
>>
>> databases=`psql -U postgres -q -c "\l" | awk '{ print $1}' | grep -vE
>> '^\||^-|^List|^Name|postgres|^Name|template[0|1]|^\('`
>>
>> for db in ${databases}
>>
>> do
>>
>>   date=`date +"%m-%d-%Y"`
>>
>>   filename="/opt/backups/${hostname}_${db}_${date}.sql"
>>
>>   pg_dump -f $filename $db
>>
>>   gzip $filename
>>
>>   filename2="/opt/backups/${hostname}_${db}_${date}.filestore.gz"
>>
>>   tar -zcvf $filename2 /home/odoo/.local/share/Odoo/filestore/$db
>>
>> done
>>
>>
>>
>> # ReStart Odoo Server
>>
>> sudo /usr/sbin/service odoo-server restart
>>
>>
>>
>> for file in `find /opt/backups/*.gz -mtime +10 -type f`
>>
>> do
>>
>>  rm $file
>>
>> done
>>
>>
>>
>>
>>
>> exit 0
>>
>>
>>
>>
>>
>> MY ORIGINAL QUESTION:
>>
>>
>>
>> Hi everyone.
>>
>>
>>
>> Is scripting a backup of Odoo v9 as simple as pg_dump and copying the
>> relevant filestore folder?
>>
>>
>>
>> 1.  pg_dump -E UTF-8 -F p -b -f $filename $database
>>
>> 2.  tar -zcvf filestore_$filename.gz $database
>>
>> 3.  move both to the new server, restore dump and folder and update
>> database ?
>>
>>
>>
>> Does anyone know (have experience or a verified method for doing this) ?
>>
>>
>>
>> I want to start testing how I can quickly move a database from one server
>> to another.
>>
>>
>>
>>
>>
>>
>>
>> STEFAN’S REPLY:
>>
>>
>>
>> Yes, that is all there is to it. I do it all the time, not between servers
>> per sé but in order to copy production environments to test instances
>> running under a different user account on the same server. If you download
>> apps from the apps store, include these from your .local/share/Odoo/addons/
>> directory.
>>
>>
>>
>>
>>
>> DOMINIQUE’S REPLY:
>>
>>
>>
>> > 1.  pg_dump -E UTF-8 -F p -b -f $filename $database
>>
>>
>>
>> in my scripts I use -O and -U options
>>
>>
>>
>> -E UTF-8 -F p -b  options should be useless
>>
>>
>>
>>
>>
>> > 2.  tar -zcvf filestore_$filename.gz $database
>>
>> >
>>
>>
>>
>> > 3.  move both to the new server, restore dump and folder and update
>> > database
>>
>> > ?
>>
>>
>>
>> if target database already exists, dropdb after closing all connections
>>
>> restoration with psql  and tar -xzf for the filestore
>>
>> change owner:group on filestore according to the new server
>>
>>
>>
>> depending on your context, you may have to synchronize/adapt some
>>
>> options in the server config file and also the modules that users can
>>
>> upload from the apps.
>>
>>
>>
>> A key point is to determine whether the copied database is a copy or a
>>
>> replacement of the main database. If a copy, the new database should
>>
>> not interface external applications (pop/imap, smtp, shop-connector
>>
>> etc...), if a replacement it should
>>
>>
>>
>> _______________________________________________
>> Mailing-List: https://www.odoo.com/groups/community-59
>> Post to: mailto:community@mail.odoo.com >> Unsubscribe: https://www.odoo.com/groups?unsubscribe > > > _______________________________________________ > Mailing-List: https://www.odoo.com/groups/community-59 > Post to: mailto:community@mail.odoo.com > Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
Alexandre Fayolle
Chef de Projet
Tel : + 33 (0)4 58 48 20 30

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac Cedex
http://www.camptocamp.com