PostgreSQL Permission Denied After Docker Migration Between VPS Using rclone

[Help]

Problem

I'm getting permission denied errors while trying to set modification times on PostgreSQL files after migrating a Docker setup between VPS instances. Even with full permissions (777) and sudo, the errors persist.

Current Approach

  • Trying to migrate the entire Docker directory structure (not using pg_dump)
  • Stopped PostgreSQL containers on both VPS 1 and VPS 2 before migration
  • Note: I'm aware pg_dump works fine, but specifically need to migrate the entire folder structure

Environment

  • Docker container app running PostgreSQL
  • Migration from VPS 1 to VPS 2
  • Path: /opt/docker/my-docker-app/database/

Rclone Commands

  • My function:
 sync_operation() {
    local source="$1"
    local destination="$2"
    sudo rclone sync "$source" "$destination" \
        --sftp-host "$SSH_HOST" \
        --sftp-port "$SSH_PORT" \
        --sftp-user "$SSH_USER" \ # not root
        --sftp-key-file "$SSH_KEY" \
        --create-empty-src-dirs \
        --progress
    }
  • Example of usage:
SOURCE_DIR="/opt/docker/my-docker-app/database" # in VPS 1
DEST_DIR="/opt/docker/my-docker-app/database"  # in VPS 2
sync_operation "$SOURCE_DIR" ":sftp:$DEST_DIR"

Error Messages

ERROR : /my-docker-app/database/data/base/16384/13404: Failed to set modification time: SetModTime failed: permission denied
ERROR : /my-docker-app/database/data/base/16384/13406: Failed to set modification time: SetModTime failed: permission denied
ERROR : /my-docker-app/database/data/PG_VERSION: Failed to set modification time: SetModTime failed: permission denied

What I've Tried

  1. Set full permissions: sudo chmod -R 777 /opt/docker/my-docker-app/database/
  2. Used sudo for rclone sync operations
  3. Checked file ownership (all failed files owned by systemd-coredump)

Questions

  1. What's the proper way to handle file permissions during VPS migrations?
  2. Are there specific considerations for PostgreSQL db file permissions in Docker environments?
  3. Why I'm encounter this error?

Any help or guidance would be greatly appreciated!

What about to tar + compression all your folder -> then rclone to the destination -> un-tar + decompress. This way your should preserve all extended attributes and permissions without fighting with sftp limitations.

If you do not have free space and have ssh access you can forget rclone all together and pipe tar over network. Something like (pull):

ssh user@remoteIP 'tar zcf - /some/dir' | tar zxf 

I appreciate your reply, but it's not the ideal solution for me.

hi,
need to figure out if this is a rclone issue or not?
try rsync or another copy tool.


are you using root or not?
did you try as root?

i used a sudo user not root