13

I need to backup the current db while logged into odoo. I should be able to do it using a button, so that suppose I click on the button, it works the same way as odoo default backup in manage databases, but I should be able to do it from within while logged in.

Is there any way to achieve this? I do know that this is possible from outside odoo using bash but thats not what I want.

Yaseen Shareef
  • 757
  • 8
  • 21

10 Answers10

8

By using this module you can backup your database periodically

https://www.odoo.com/apps/modules/7.0/crontab_config/ (v7)

you can also test this module

https://www.odoo.com/apps/modules/6.1/db_backup_ept/ (v6 it can be miggrated to v7)

in your case you can add button to execute the function that will be executed by the schedular.

4

You can use the CURL to download the full backup (assets + DB), this method is comparatively faster than pg_dump.

curl -X POST \
-F "master_pwd=${ADMIN_PASSWORD}" \
-F "name=${ODOO_DATABASE}" \
-F "backup_format=zip" \
-o ${BACKUP_DIR}/${ODOO_DATABASE}.$(date +%F-%T).zip \
${HOST}/web/database/backup

You can wrap inside a custom (your own) Odoo add-on if you wish to. Hope this helps.

Vipin Kohli
  • 487
  • 3
  • 9
3

You can take database backup from "Database Management" in odoo..

type following link in browser,

http://localhost:8069/web/database/manager

just replace your ip and port in aboves link, you will get screen for database management, you can perform following operations related to database

  • Create
  • Duplicate
  • Drop
  • Backup
  • Password
  • Restore
Meet Vaishnani
  • 253
  • 1
  • 10
2

Add a button somewhere and call a controller like this one.

@http.route('/backup/download', auth="user", type='http')
        def backup(self, **kw):
            ts = datetime.datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%S")
            filename = "%s_%s.zip" % (request.env.cr.dbname, ts)
            headers = [
                ('Content-Type', 'application/octet-stream; charset=binary'),
                ('Content-Disposition', content_disposition(filename)),
            ]
            dump_stream = db.dump_db(request.env.cr.dbname, None)
            response = werkzeug.wrappers.Response(dump_stream, headers=headers, direct_passthrough=True)
            return response
1

You can use a private browser session to access the Database menu, from the login screen, and perform the the backup form there (you need to know the master password to access that, defined in the server configuration file).

Daniel Reis
  • 12,944
  • 6
  • 43
  • 71
1

Go to your_odoo_instance/web/database/manager where you can see all your installed databases:

Odoo's Database Manager - Backup

You will need your defined master password for this task. If you can't remember it, have a look at your odoo.conf file in your server and check the 'admin_passwd' entry.

0

There are a lot of ways to dump the database of ODOO. You can download apps from the ODOO store for doing this automatically also. Here I can suggest an addon that will do this DATABASE AUTO Backup according to your settings Month, Day, Hour basis. This is a highly reliable and efficient way where this module can handle large databases without effecting odoo processes. ODOO DATABASE AUTOMATIC BACKUP

Hilar AK
  • 1,655
  • 13
  • 25
0

Use This Module For Automatic Backup

Active developer mode. Go Settings > General Settings > Database Backup Set your database name and path where you want to save your database.

https://apps.odoo.com/apps/modules/11.0/db_backup/

https://apps.odoo.com/apps/modules/14.0/yodoo_easy_backup/

0

Considerations before starting

The Backup button visible on the http://your_odoo_example.com/web/database/manager URL, packages both the Filestore and the Database on a compressed *.zip file, that the Odoo Database Manager through the same URL can decompress and restore.

It's also important to know that to generate a full backup of Odoo three essential parts are needed:

  1. Filesystem (Usually a GIT Repo)
  2. Database (Can be done through the Odoo Database Manager as stated before)
  3. FileStore (Can be done through the Odoo Database Manager as stated before)

Without a backup and restore of the Filestore, there's a chance of getting errors and having Odoo not work well, or at least make the log unreadable if it's flooded with attachment errors.

It's recommended that you stop the Odoo Services on both current and target Database locations, PostgreSQL will complain about the Database still being accessed.

Requirements:

  • Access to the psql command
  • The user and password to your Odoo database

The information on both user and password is most likely on the odoo.conf file, assuming it is on the most used path /etc/odoo/odoo.conf it's easy to retrieve with:

grep 'db_password\|db_user\|db_name' /etc/odoo/odoo.conf

Test access to the psql console with the resulting values of db_user, db_name and db_password executing:

psql -U db_user -d db_name

it should either log in directly or ask for a password, the result should be something like this:

❯ psql db_user -d db_name
Password for user db_user:
psql (11.13)
Type "help" for help.

db_name=#

Getting an error message most likely means PostgreSQL will need additional configuration on the pg_hba.conf and/or postgres.conf files, it'll be a topic on its own to also cover it here.

The bash commands

With all that information and if everything went good accessing psql, we are ready for a solution to do it through bash,

  1. Execute via psql commands, one to generate a Database dump, preferably one that will also compress the file for easier transport if you need to download, this is a simple version of one of the options:

    pg_dump -U db_user -d db_name | bzip2 >
    backup_name-DDMMYYY.sql.bz2
    
  2. To restore the Database dump execute a similar command that will restore it from the *.sql.bz2 file, however, it needs to first be created as an empty target Database, with:

    createdb -U db_user db_name
    

    Have in mind that if you have restored the Database before, and you want to use the same name, you'll need to drop the Database you are not going to use anymore, for that you can use:

    dropdb -U db_user target_db_name
    

    MAKE SURE! you're not dropping the original Database you intend to backup.

  3. Once you have the empty target Database to restore the backup you'll need to run a command that will decompress the dump and then write it on the empty target Database:

    bzcat backup_name-DDMMYYY.sql.bz2 | psql -U db_user -d target_db_name
    

    That should be good enough to get your Database back up and running

  4. Finally set the owner of the Database to the user of the target Database location:

    psql -U db_user -d target_db_name -c "ALTER DATABASE \"target_db_name\" OWNER TO target_db_user"
    

The bash script

To really streamline the process create via vim or nano at the .bashrc PATH an executable command to use regardless of the current directory being worked on, an example that will work for a Standard Debian/Ubuntu Linux distribution is:

sudo nano /usr/local/bin/your_command_name

Assuming the Service names for both Odoo and PostgreSQL are respectively, odoo and PostgreSQL this is an option for a bash script to achieve the task:

#!/bin/bash


## Variables
# Name of Local Database to Drop and Recreate
target_db_name="replace_with_your_db_name"

# Local Credentials
db_user="replace_with_your_db_user"
db_password="replace_with_your_db_password"
target_db_user="replace_with_your_targer_db_user"


## Database Backup Files selection
# Set all the files in an array named $files
files=( /replace_with_your/path_to/database_backups/*.sql.bz2 )
shopt -s extglob

# Build the string to use for the case options
string="@(${files[0]}"
# Add file names to the string
for((i=1;i<${#files[@]};i++))
do
    string+="|${files[$i]}"
done
# Add the rest of the syntax to $string resulting in something like @(file1|file2|file3|...|fileN)
string+=")"

# Case for Database Backup *.sql.bz2 File
select file in "${files[@]}" "quit"
do
    case $file in
    ## If the choice is one of the files (if it matches $string)
    $string)
    ## PostgreSQL commands
    # Stops Odoo Server Service
    systemctl stop odoo

    # Starts PostgreSQL Service
    systemctl restart PostgreSQL

    # Drop target_db_name
    PGPASSWORD=$db_password psql -U $db_user -c "DROP DATABASE \"$target_db_name\""

    # Creates Empty target_db_name
    PGPASSWORD=$db_password psql -U $db_user -c "CREATE DATABASE \"$target_db_name\""

    # Generates Target Database from dump file
    bzcat $file | PGPASSWORD=$db_password psql -U $db_user $target_db_name

    # New Database gets psql User by Default as Owner, must change to Local Database instance owner
    PGPASSWORD=$db_password psql -U $db_user -d $target_db_name -c "ALTER DATABASE \"$target_db_name\" OWNER TO $taregt_db_owner"

    # Starts PostgreSQL Service
    systemctl restart PostgreSQL

    # Starts Odoo Server Service
    systemctl start odoo
    ;;
    "quit")
        ## Exit
        echo
        echo
        exit
        ;;
    *)
        file=""
        echo "Please choose a number from 1 to $((${#files[@]}+1))"
        ;;
    esac
done

The bash script will require sudo execution since it involves stopping and starting daemon services:

sudo your_command_name

About the db_name and db_password on the bash script

There are better ways to do this, f example, it's not necessary to set the db_password on the bash script, it can be passed by setting it as an environment variable or through a encrypted secrets file along with the db_user, I'm sure there are other topics that will cover them but this should get things started.

I hope this helps someone.

-2

For backup, you can go to this link http://localhost:8069/web/database/manager.

  • You can create a backup from there.
  • You can restore your pre existing backup also.

Important- Before that just set your master password for your Database to avoid consequences in future.

enter image description here If you want to change particular models or fields while logged in. You can do it by export/import action provided by Odoo. After exporting data from local you can import it on your server for that you have to validate it. enter image description here

Dheeraj Balodia
  • 252
  • 7
  • 36