Skip to content

Commit

Permalink
[FIX] odoo/14.0: rclone error on failure to purge (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
JevinD authored Jul 19, 2021
1 parent b1af7df commit 34b71c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
11 changes: 7 additions & 4 deletions backup/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function config_rclone() {
"aws")
;;
"azure")
export FILESTORE_BUCKET=$RUNNING_ENV-$PGDATABASE
;;
"do")
export FILESTORE_SPACE=`echo $FILESTORE_AWS_HOST | sed -e "s/.$FILESTORE_AWS_REGION.*$//"`
Expand All @@ -82,6 +83,7 @@ function config_rclone() {
"aws")
;;
"azure")
export BACKUP_BUCKET=$RUNNING_ENV-$PGDATABASE
;;
"do")
export BACKUP_SPACE=`echo $BACKUP_AWS_HOST | sed -e "s/.$BACKUP_AWS_REGION.*$//"`
Expand All @@ -97,6 +99,7 @@ function config_rclone() {
"aws")
;;
"azure")
export REMOTE_BUCKET=$RUNNING_ENV-$PGDATABASE
;;
"do")
export REMOTE_SPACE=`echo $REMOTE_AWS_HOST | sed -e "s/.$REMOTE_AWS_REGION.*$//"`
Expand Down Expand Up @@ -133,14 +136,14 @@ function backup() {
echo "Sync the filestore to backup"
rclone sync filestore:/$FILESTORE_SPACE/$FILESTORE_BUCKET/ backup:/$BACKUP_SPACE/$BACKUP_BUCKET/$RUNNING_ENV-$PGDATABASE-$TODAY/
echo "Cleanup last month copy on backup"
rclone purge backup:/$BACKUP_SPACE/$BACKUP_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH/
rclone purge backup:/$BACKUP_SPACE/$BACKUP_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH.sql.gz
! rclone purge backup:/$BACKUP_SPACE/$BACKUP_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH/
! rclone purge backup:/$BACKUP_SPACE/$BACKUP_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH.sql.gz
if [ $REMOTE_ENABLED == 'true' ]; then
echo "Push, sync and cleanup to/on remote"
rclone copy /tmp/$RUNNING_ENV-$PGDATABASE-$TODAY.sql.gz remote:/$REMOTE_SPACE/$REMOTE_BUCKET/
rclone sync filestore:/$FILESTORE_SPACE/$FILESTORE_BUCKET/ remote:/$REMOTE_SPACE/$REMOTE_BUCKET/$RUNNING_ENV-$PGDATABASE-$TODAY/
rclone purge remote:/$REMOTE_SPACE/$REMOTE_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH/
rclone purge remote:/$REMOTE_SPACE/$REMOTE_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH.sql.gz
! rclone purge remote:/$REMOTE_SPACE/$REMOTE_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH/
! rclone purge remote:/$REMOTE_SPACE/$REMOTE_BUCKET/$RUNNING_ENV-$PGDATABASE-$LASTMONTH.sql.gz
fi
;;
*)
Expand Down
14 changes: 7 additions & 7 deletions odoo/14.0/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ function duplicate() {
case "$PLATFORM" in
"aws")
BUCKET=`echo $BUCKET_NAME | sed -e "s/{db}/$1/g"`
rclone sync remote:/$RUNNING_ENV-backup/ remote:/$BUCKET/
rclone sync filestore:/$RUNNING_ENV-backup/ filestore:/$BUCKET/
psql -d $DB_NAME -c "
UPDATE ir_attachment AS t SET store_fname = s.store_fname FROM (
SELECT id,REPLACE(store_fname, '/*production-master*/', '$BUCKET')
AS store_fname FROM ir_attachment WHERE db_datas is NULL)
AS s(id,store_fname) where t.id = s.id;"
;;
"azure")
rclone sync remote:/$RUNNING_ENV-backup/ remote:/$RUNNING_ENV-$1/
rclone sync filestore:/$RUNNING_ENV-backup/ filestore:/$RUNNING_ENV-$1/
;;
"do")
rclone sync remote:/$SPACE/$RUNNING_ENV-backup/ remote:/$SPACE/$RUNNING_ENV-$1/
rclone sync filestore:/$SPACE/$RUNNING_ENV-backup/ filestore:/$SPACE/$RUNNING_ENV-$1/
psql -d $1 -c "
UPDATE ir_attachment AS t SET store_fname = s.store_fname FROM (
SELECT id,REPLACE(store_fname, '/production-master/', '$RUNNING_ENV-$1')
Expand Down Expand Up @@ -139,7 +139,7 @@ function create() {
case "$PLATFORM" in
"aws")
BUCKET=`echo $BUCKET_NAME | sed -e "s/{db}/$1/g"`
rclone mkdir remote:/$BUCKET/
rclone mkdir filestore:/$BUCKET/
;;
*)
;;
Expand All @@ -153,14 +153,14 @@ function drop() {
case "$PLATFORM" in
"aws")
BUCKET=`echo $AWS_BUCKETNAME | sed -e "s/{db}/$1/g"`
rclone purge remote:/$BUCKET/
! rclone purge filestore:/$BUCKET/
;;
"azure")
rclone purge remote:/$RUNNING_ENV-$1/ || echo 0
! rclone purge filestore:/$RUNNING_ENV-$1/
;;
"do")
BUCKET=`echo $AWS_BUCKETNAME | sed -e "s/{db}/$1/g"`
rclone purge remote:/$SPACE/$BUCKET/
! rclone purge filestore:/$SPACE/$BUCKET/
;;
*)
rm -Rf $ODOO_DATA_DIR/filestore/$1
Expand Down
6 changes: 3 additions & 3 deletions odoo/14.0/templates/rclone.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ if contains "aws" .Env.PLATFORM }}
[remote]
[filestore]
type = s3
provider = AWS
env_auth = false
Expand All @@ -10,12 +10,12 @@ location_constraint = {{ default "" .Env.AWS_REGION }}
acl = private
{{ end }}
{{ if contains "azure" .Env.PLATFORM }}
[remote]
[filestore]
type = azureblob
sas_url = {{ default "" .Env.AZURE_STORAGE_ACCOUNT_URL }}
{{ end }}
{{ if contains "do" .Env.PLATFORM }}
[remote]
[filestore]
type = s3
provider = DigitalOcean
env_auth = true
Expand Down

0 comments on commit 34b71c0

Please sign in to comment.