Sunday, September 18, 2016

Odoo 9: backup using wget

Additional requirement:

  • zip & unzip
  • rsync
  • openssh
URL to backup Odoo is https://[your_ip]//web/database/backup or http://[your_ip]:8069//web/database/backup.
We can use wget to backup Odoo from localhost or from remote without interrupting Odoo service.

for local server

# wget --post-data 'master_pwd=yourpassword&name=yourdatabase&backup_format=zip' -O backup.zip http://localhost:8069/web/database/backup

for remote server (Not Recomended: your password will send through internet in plain text)

# wget --post-data 'master_pwd=yourpassword&name=yourdatabase&backup_format=zip' -O backup.zip http://[your_ip]:8069/web/database/backup

for remote server via https reverse proxy

# wget --post-data 'master_pwd=yourpassword&name=yourdatabase&backup_format=zip' --no-check-certificate -O backup.zip https://[your_ip]/web/database/backup

Backup Option:

  • Use backup_format=zip to backup database and filestore
  • Use backup_format=dump to backup database only

Now we can create bash file to make it easier to backup

# vi myodoobackup.sh
#!/bin/bash
## created by dedetok Sept 2016
## last update 2016-09-21
## GNU GPL v3
# create file name
now=$(date +"%Y-%m-%d")
mfname="backup_$now.zip"
#echo "$mfname"
# perform Odoo backup to output file $mfname
wget --post-data "master_pwd=yourpassword&name=yourdatabase&backup_format=zip" --no-check-certificate -O "$mfname" https://[your_ip]/web/database/backup

The file name of the output will be backup_2016-09-18.zip.
If you use local server you can use http://localhost:8069//web/database/backup

Backup to remote server

You can synchronized your backup using rsync. You need to install rsync in host and remote server.
You need to create key in your host and put it in remote read here

Synchronized without delete (exist in remote but not exist in host)

$ rsync -avzh -e "ssh -p 22" /home/foo/test/ bar@SERVER_B:/home/bar/test/
sending incremental file list
./
test.txt

sent 389 bytes  received 38 bytes  854.00 bytes/sec
total size is 395  speedup is 0.93

Synchronized with delete (delete any file in remote folder if not exist in host)

$ rsync -avzh --delete -e "ssh -p 22" /home/foo/test/ bar@SERVER_B:/home/bar/test/

Modification bash script

#!/bin/bash
## created by dedetok Sept 2016
## last update 2016-09-18
## GNU GPL v3
now=$(date +"%Y-%m-%d")
dbname="dbname"
dbserver="localhost"
dbpass="dbpassword"
dbmode="zip"
mfname="full_"$dbname"_"$now".zip"
echo "backup $dbname @ $dbserver mode $dbmode into $mfname"
wget --post-data "master_pwd=$dbpass&name=$dbname&backup_format=$dbmode" --no-check-certificate -O "$mfname" "http://$dbserver:8069/web/database/backup"
# synchronized to remote
echo "syncronized backup to REMOTE_B"
rsync -avzh --delete -e "ssh -p 22" /home/foo/ bar@REMOTE_B:/home/bar/
Note: Single quotes won't interpolate anything, but double quotes will (for example variables, backticks, certain \ escapes, etc...)
"test $parm" equal to 'test '$parm

References:

No comments:

Post a Comment